Results 1 to 4 of 4

Thread: Bitmap in memory

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    28

    Bitmap in memory

    How do I get a Bitmap in the memory and if it is in the memory, how can I edit the bitmap pixel per pixel??

    Thanks...

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You can a Bitmap into memory very simply, by using the VB LoadPicture() function.

    You could just load the image directly into a Picturebox (which is technically in memory) or if you want to create a Memory DC yourself and store it there do something like this:
    VB Code:
    1. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    2. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    3. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    4. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    5.  
    6. Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
    7.  
    8. Private Sub Command1_Click()
    9.     Dim lDC As Long
    10.     Dim lBMP As IPictureDisp
    11.    
    12.     Picture1.ScaleMode = vbPixels
    13.    
    14.     ' Create a Memory Device Context to hold the Image you want to manipulate
    15.     lDC = CreateCompatibleDC(0)
    16.     ' Load the Image
    17.     Set lBMP = LoadPicture("C:\Windows\Clouds.bmp")
    18.     ' Select it into the new DC
    19.     Call SelectObject(lDC, lBMP)
    20.     ' Manipulate the image via the Device Context (lDC)
    21.     ' Then BitBlt it to a Picturebox or other device context
    22.     Call BitBlt(Picture1.hdc, 0, 0, ScaleX(lBMP.Width, vbHimetric, vbPixels), ScaleY(lBMP.Height, vbHimetric, vbPixels), lDC, 0, 0, SRCCOPY)
    23.     ' always clean up DC's or Objects you create in order to restore GDI resources.
    24.     Call DeleteDC(lDC)
    25.     Set lBMP = Nothing
    26. End Sub
    There are several GDI API's you can use for altering the image, such as GetPixel and SetPixel

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Unlimited realities has some DMA samples; provides fast access with a pointer to a byte array
    http://www.ur.co.nz/
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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