Results 1 to 7 of 7

Thread: Picture in memory

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200
    You can use these two alternative options:

    1. Hide PictureBox then draw whatever you want on it (don't forget to set AutoRedraw property to TRUE). After drawing make it visible (in other words, show it).

    2. Use two PictureBox controls. One will be always visible, and the other will be always hidden. After drawing to hidden PictureBox (AutoRedraw = True - look up), put image into visible PictureBox like this:

    PictureBox1.Picture = PictureBox2.Image

    Hope this helps...

  2. #2
    New Member
    Join Date
    Jul 2000
    Posts
    11
    yeah.. thats what i normally do, but it is very slow, which is why i wanted to try doing it in memory, i think it would be faster

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200
    whell...that goes beyond my posibilities

    Maybe you'll find something on Microsoft's SDK pages. Go to http://msdn.microsoft.com/library/default.asp

    [Edited by Arcom on 09-01-2000 at 08:04 PM]

  4. #4
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Here a typical example to draw something in memory => much faster!
    Code:
      '...
      hDCTmp = CreateCompatibleDC(0)
      hBMTmp = CreateCompatibleBitmap(Picture1.hdc, Picture1.ScaleWidth, Picture1.ScaleHeight)
      HBMPrv = SelectObject(hDCTmp, hBMTmp)
      '...
      SetPixel (hDCTmp, x, y, RGB(c1,c2,c3))
      '...
      'Copy the picture in the memory DC to Picture1
      BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, hDCTmp, 0, 0, vbSrcCopy
      '...
      'Clean Up (Form_Unload event)
      SelectObject hDCTmp, HBMPrv
      DeleteObject hBMTmp
      DeleteDC hDCTmp

  5. #5
    New Member
    Join Date
    Jul 2000
    Posts
    11
    It works, great! Thanks

  6. #6
    Guest
    The best way to make this is to create a virtuell Metafile in the memory. Its very fast and take only a little part of your memory

    Public Declare Function CreateMetaFile Lib "gdi32" Alias "CreateMetaFileA" _
    (ByVal lpString As Any) As Long

    Public Declare Function CloseMetaFile Lib "gdi32" (ByVal hMF As Long) As Long

    Public Declare Function PlayMetaFile Lib "gdi32" (ByVal hdc As Long, ByVal hMF As Long) As Long

    Public Declare Function DeleteMetaFile Lib "gdi32" (ByVal hMF As Long) As Long

    Public Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long

    Public Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long


    mlngMMF = CreateMetaFile(ByVal 0&) ' mlngMMF is the Hdc of the Metafile
    SetBkColor mlngMMF, vbWhite 'set the backgroundcolor to white
    SetBkMode mlngMMF, 1 'make the background transparent

    now you can paint with API- calls

    if you are finished then make this
    mlngMMF = CloseMetaFile(mlngMMF) ' you will get back a new Hdc

    to paint the metafile you need this command

    PlayMetaFile Picturebox1.hdc, mlngMMF

  7. #7
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    WMF, EMF, ... are very powerful but they don't support bitmaps and so on. I mean, you can draw a line in the metafile, and after rescaling it, the line is enlarged, but remains it's fine quality. This behaviour doesn't apply to bitmaps. I think, BitBlt and StretchBlt are here the most common options.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width