Here is the 1D version. cyborg I was unable to get SetDiBits working with what you posted
VB Code:
Private Type RGBQUAD Blue As Byte Green As Byte Red As Byte Alpha As Byte End Type Private Type BITMAPINFOHEADER '40 bytes biSize As Long biWidth As Long biHeight As Long biPlanes As Integer biBitCount As Integer biCompression As Long biSizeImage As Long biXPelsPerMeter As Long biYPelsPerMeter As Long biClrUsed As Long biClrImportant As Long End Type Private Type BITMAPINFO bmiHeader As BITMAPINFOHEADER bmiColors(0 To 255) As RGBQUAD End Type Private Type SAFEARRAY1D cDims As Integer fFeatures As Integer cbElements As Long cLocks As Long pvData As Long cElements As Long lLbound As Long End Type Private Const BI_RGB& = 0& Private Const DIB_RGB_COLORS& = 0& Dim BM_256 As BITMAPINFO Dim Bytes8() As Byte Dim PadBytes8 As Long Dim X As Long Dim Y As Long Dim Wide As Integer Dim High As Integer Dim DrawWidthBytes& Dim AddDrawWidth& Dim BufUbound& Dim TopLeft& Dim DrawLeft& Dim DrawRight& Dim Res& Private Declare Function StretchDIBits Lib "gdi32" (ByVal hDC As Long, _ ByVal X As Long, ByVal Y As Long, _ ByVal DesW As Long, ByVal DesH As Long, _ ByVal SrcXOffset As Long, ByVal SrcYOffset As Long, _ ByVal SrcW As Long, ByVal SrcH As Long, _ lpBits As Any, lpBitsInfo As BITMAPINFO, _ ByVal wUsage As Long, ByVal dwRop As Long) As Long Private Sub Form_Activate() ScaleMode = vbPixels DoEvents Wide = 250 High = 200 With BM_256.bmiHeader .biBitCount = 8 .biWidth = Wide .biHeight = High .biClrImportant = 256 .biClrUsed = 256 .biSize = Len(BM_256.bmiHeader) PadBytes8 = 4 - Wide Mod 4 If PadBytes8 = 4 Or .biBitCount = 32 Then PadBytes8 = 0 DrawWidthBytes = Wide * .biBitCount / 8 + PadBytes8 .biSizeImage = DrawWidthBytes * High .biCompression = BI_RGB .biPlanes = 1 End With For X = 0 To 255 BM_256.bmiColors(X).Blue = X BM_256.bmiColors(X).Green = X BM_256.bmiColors(X).Red = X Next BufUbound = DrawWidthBytes * High - 1 ReDim Bytes8(BufUbound) AddDrawWidth = Wide - 1 TopLeft = DrawWidthBytes * (High - 1) For Y = 0 To TopLeft Step DrawWidthBytes X = 0 DrawRight = Y + AddDrawWidth For Res = Y To DrawRight Bytes8(Res) = 255 * X / Wide X = X + 1 Next Next If StretchDIBits(Form1.hDC, 0, 0, Wide, High, 0, 0, Wide, High, _ Bytes8(0), _ BM_256, DIB_RGB_COLORS, vbSrcCopy) = 0 Then Caption = "Blit Error" End If End Sub




Reply With Quote