|
-
Oct 1st, 2003, 05:26 PM
#1
Thread Starter
So Unbanned
Resolved - 8 bit DIB
How would I go about using SetDiBits using a 1-d array?
I tried... but I got a illegal operation and VB crashed.
Thanks,
Last edited by DiGiTaIErRoR; Oct 8th, 2003 at 04:59 AM.
-
Oct 3rd, 2003, 03:26 PM
#2
Thread Starter
So Unbanned
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...
-
Oct 8th, 2003, 04:04 AM
#3
Addicted Member
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
-
Oct 8th, 2003, 05:12 AM
#4
Thread Starter
So Unbanned
Thanks.
This works:
VB Code:
res = SetDIBits(Form1.hdc, Form1.Image.Handle, 0, 200, Bytes8(1, 1), BM_256, 0)
-
Oct 8th, 2003, 05:35 AM
#5
Thread Starter
So Unbanned
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?
-
Oct 8th, 2003, 09:19 PM
#6
Frenzied Member
"The Y is inverted. Is there anyway to correct that?"
y=height-y
-
Oct 8th, 2003, 09:37 PM
#7
Thread Starter
So Unbanned
Originally posted by cyborg
"The Y is inverted. Is there anyway to correct that?"
y=height-y
Yea... besides that.
This needs to be as fast as possible.
-
Oct 8th, 2003, 10:25 PM
#8
Frenzied Member
change:
VB Code:
For Y = 1 To High
For X = 1 To Wide
Bytes8(X, Y) = 255 * X / Wide
Next
Next
to:
VB Code:
For Y = 1 To High
For X = 1 To Wide
Bytes8(X, High - Y) = 255 * X / Wide
Next
Next
-
Oct 9th, 2003, 01:52 AM
#9
Addicted Member
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
-
Oct 9th, 2003, 03:03 PM
#10
Thread Starter
So Unbanned
Originally posted by cyborg
change:
VB Code:
For Y = 1 To High
For X = 1 To Wide
Bytes8(X, Y) = 255 * X / Wide
Next
Next
to:
VB Code:
For Y = 1 To High
For X = 1 To Wide
Bytes8(X, High - Y) = 255 * X / Wide
Next
Next
Yes, I know. I coded something similar to that. I just want it to not have to calculate the position for optimal speed.
-
Oct 9th, 2003, 03:44 PM
#11
Frenzied Member
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
-
Oct 12th, 2003, 06:00 AM
#12
Addicted Member
"ah," cool thank you. I had tried a negative sign in front of the height parameter but that didn't work
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|