-
BitBlt to a PictureBox in VB.net
I'm having real trouble with blting an array of bytes into a
picturebox control (thanks with earlier help but I'm still not there).
As you will see from my code below I set up a MemDC compatible with
the PictureBox, then create a DIB from that and my bytes then I try
and stretch the bits from the MemDC to the pictureBox DC. Everything
appears OK, except that nothing appears in the PictureBox, and if I
repeat (it's all based on a button click) I get an exception in
disassembler:-
An unhandled exception of type 'System.InvalidOperationException'
occurred in system.drawing.dll
Here's the code fragment. Can anyone tell me what I'm doing wrong,
I'm new to .net and I'm not sure if I'm using GDI+ correctly. I do
need to get the BMP from raw bytes as well, so if anyone has a better
GDI+ way that would be good.
CODE ------
Dim hDIB as Integer 'Or as IntPtr, both time the same problem occurs
With bm_info.bmiHeader
.biSize = Len(bm_info.bmiHeader)
.biWidth = FP_WIDTH ' Width in pixels.
.biHeight = FP_HEIGHT ' Height in pixels.
.biPlanes = 1 ' 1 color plane.
.biBitCount = 8 ' 8 bits per pixel.
.biCompression = BI_RGB ' No compression.
.biSizeImage = 0 ' Unneeded with no compression.
.biXPelsPerMeter = 0 ' Unneeded.
.biYPelsPerMeter = 0 ' Unneeded.
.biClrUsed = 256 ' # colors in color table that are used by the image. 0
means all.
.biClrImportant = 256 ' # important colors. 0 means all.
End With
'_picFP_0 is a PictureBox Control
Dim gr As Graphics = _picFP_0.CreateGraphics()
Dim hdc As IntPtr = gr.GetHdc()
MemDC = CreateCompatibleDC(hdc)
gr.ReleaseHdc(hdc)
gr.Dispose()
hDib = CreateDIBitmap(MemDC, bm_info.bmiHeader, 0, Nothing, Nothing, DIB_RGB_COLORS)
SetDIBits(MemDC, hDib, 0, FP_HEIGHT, biData, bm_info, DIB_RGB_COLORS)
Dim grPic As Graphics
Dim hdcPic As IntPtr
grPic = _picFP_0.CreateGraphics()
hdcPic = grPic.GetHdc()
StretchBlt(hdcPic, 0, 0, FP_WIDTH / 2, FP_HEIGHT / 2, MemDC, 0, 0, FP_WIDTH,
FP_HEIGHT, SRCCOPY)
grPic.ReleaseHdc(hdcPic)
grPic.Dispose()
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks