This seems weird... I have bitmaps storaged in memory and most of them display correctly, but all ones with odd width and also some others (it is quite random) display incorrectly. Attached is a file that shows what kind of results I get.
Is there a reason for this? I give the bytes correctly. Here is the code I use to storage the graphics to memory:
VB Code:
'IN A CLASS MODULE
Option Explicit
Private BMP_INFO As BITMAPINFO_256, BMP_DATA() As Byte
Private hDIB As Long, hWidth As Integer, hHeight As Integer
Public Sub Create(ByVal NewWidth As Integer, ByVal NewHeight As Integer, ByRef Pixels() As Byte, ByRef Palette() As Byte)
Dim Screen_hDC As Long, A As Integer, B As Long
'set width and height
hWidth = NewWidth
hHeight = NewHeight
B = UBound(Pixels)
'resize graphics array
ReDim BMP_DATA(B)
'copy graphics data
RtlMoveMemory ByVal VarPtr(BMP_DATA(0)), ByVal VarPtr(Pixels(0)), B + 1
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Public Declare Function CreateDIBitmap Lib "gdi32" (ByVal hDC As Long, lpInfoHeader As BITMAPINFOHEADER, ByVal dwUsage As Long, lpInitBits As Any, lpInitInfo As BITMAPINFO_256, ByVal wUsage As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Public Declare Function StretchBlt Lib "gdi32" (ByVal hDC 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Hope someone can answer the question. I can't see anything wrong with the code, since it is a modification of a code made by someone else.
Finally! Figured it! Just had to make so that each data row is dividable by four. Code to make this clearer in case somebody happens to have the same problem some day:
VB Code:
Public Sub Create(ByVal NewWidth As Integer, ByVal NewHeight As Integer, ByRef Pixels() As Byte, ByRef Palette() As Byte)
Dim Screen_hDC As Long, A As Integer, B As Long, C As Integer
'set width and height
hWidth = NewWidth
hHeight = NewHeight
B = IIf(hWidth Mod 4, (hWidth + 4 - hWidth Mod 4) * hHeight - 1, UBound(Pixels))