How would I go about using SetDiBits using a 1-d array?
I tried... but I got a illegal operation and VB crashed.
Thanks,
Printable View
How would I go about using SetDiBits using a 1-d array?
I tried... but I got a illegal operation and VB crashed.
Thanks,
Ok.... this is what I'm going for....
I have a paletted image(byte data). And what I need to do is process the bytes and generate a picture as fast as possible.
I would assume that you'd set the device's palette and then somehow insert a 1-D DIB into it.
Quite a somehow... :confused:
Tried SetDiBits without success. If you need me to make a 1d version of this I will be happy to do so.
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 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 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 .biSizeImage = (Wide * .biBitCount / 8 + PadBytes8) * 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 ReDim Bytes8(1 To (Wide + PadBytes8) * BM_256.bmiHeader.biBitCount / 8, 1 To High) For Y = 1 To High For X = 1 To Wide Bytes8(X, Y) = 255 * X / Wide Next Next If StretchDIBits(Form1.hdc, 0, 0, Wide, High, 0, 0, Wide, High, _ Bytes8(1, 1), _ BM_256, DIB_RGB_COLORS, vbSrcCopy) = 0 Then Caption = "Blit Error!" End If End Sub
Thanks.
This works:
VB Code:
res = SetDIBits(Form1.hdc, Form1.Image.Handle, 0, 200, Bytes8(1, 1), BM_256, 0)
The Y is inverted. Is there anyway to correct that?
I'd like to be able to copymemory into Bytes8.
It's the only way I can think of that'll be ultra-fast.
Is it possible make Bytes8 1-d and forward?
"The Y is inverted. Is there anyway to correct that?"
y=height-y
Yea... besides that.Quote:
Originally posted by cyborg
"The Y is inverted. Is there anyway to correct that?"
y=height-y
This needs to be as fast as possible.
change:
to:VB Code:
For Y = 1 To High For X = 1 To Wide Bytes8(X, Y) = 255 * X / Wide Next Next
VB Code:
For Y = 1 To High For X = 1 To Wide Bytes8(X, High - Y) = 255 * X / Wide Next Next
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
Yes, I know. I coded something similar to that. I just want it to not have to calculate the position for optimal speed.Quote:
Originally posted by cyborg
change:
to:VB Code:
For Y = 1 To High For X = 1 To Wide Bytes8(X, Y) = 255 * X / Wide Next Next
VB Code:
For Y = 1 To High For X = 1 To Wide Bytes8(X, High - Y) = 255 * X / Wide Next Next
try using this:
StretchDIBits(Form1.hdc, 0, High, Wide, 0, 0, 0, Wide, High, Bytes8(1, 1), BM_256, DIB_RGB_COLORS, vbSrcCopy)
i've switched the height and y values...so its drawn from high to y instead of from y to high
"ah," cool thank you. I had tried a negative sign in front of the height parameter but that didn't work