Hello!

I'm stuck here, i see no reason why i cant properly declare a dc and/or a bitmap object for a b/g/r image data i got from getbitmapbits() api.

In my theory, this should copy the image from picturebox1 to picturebox2, by converting the picture from picbox1 to a byte array, then reproduces it in a memory bitmap, that i bitblt to the picbox2.

Code:
Private Type BITMAP
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type

Private Declare Function DeleteObject Lib "GDI32.dll" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "GDI32.dll" (ByVal hDC As Long, ByVal hObject As Long) As Long

Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" _
    (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
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

Private Sub Command1_Click()
Dim PicArray() As Byte, PicInfo As BITMAP
Dim hDC As Long, hBMP As Long, hOldBmp As Long

  GetObject Picture1.Picture, Len(PicInfo), PicInfo
  ReDim PicArray((PicInfo.bmWidth * PicInfo.bmHeight * (PicInfo.bmBitsPixel / 8)) - 1) As Byte
  GetBitmapBits Picture1.Picture, UBound(PicArray), PicArray(0)
  
  hDC = CreateCompatibleDC(Picture2.hDC)
  hBMP = CreateCompatibleBitmap(Picture2.hDC, PicInfo.bmWidth, PicInfo.bmHeight)
  
  hOldBmp = SelectObject(hDC, hBMP)
  
  Debug.Print SetBitmapBits(hBMP, UBound(PicArray), PicArray(0))
  
  Picture2.Cls
  Debug.Print BitBlt(Picture2.hDC, 0, 0, PicInfo.bmWidth, PicInfo.bmHeight, hDC, 0, 0, vbSrcCopy)
  
  SelectObject hDC, hOldBmp
  DeleteObject hBMP
  DeleteObject hDC
End Sub
What i am getting is looks horrible.

I checked the array to see, what is the array is containing, by using the setpixel. It seems to be the getbitmapbits runs fine, the problem should be around the dc and bitmap creations, but i have no idea why.

Code:
Dim PicArray() As Byte, PicInfo As BITMAP
Dim hDC As Long, hBMP As Long, hOldBmp As Long
Dim X As Long, Y As Long

  GetObject Picture1.Picture, Len(PicInfo), PicInfo
  ReDim PicArray((PicInfo.bmWidth * PicInfo.bmHeight * (PicInfo.bmBitsPixel / 8)) - 1) As Byte
  GetBitmapBits Picture1.Picture, UBound(PicArray), PicArray(0)
  Picture2.Cls
  
  For X = 0 To PicInfo.bmWidth * (PicInfo.bmBitsPixel / 8) Step (PicInfo.bmBitsPixel / 8)
    For Y = 0 To PicInfo.bmHeight - 2
      SetPixel Picture2.hDC, X / 3, Y, RGB(PicArray(Y * ((PicInfo.bmWidth * 3) + 1) + X + 2), PicArray(Y * ((PicInfo.bmWidth * 3) + 1) + X + 1), PicArray(Y * ((PicInfo.bmWidth * 3) + 1) + X + 0))
    Next
  Next