Need help BitBlting to PictureBox 
Author Message
 Need help BitBlting to PictureBox

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

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.
        .biXPel{*filter*}eter = 0 ' Unneeded.
        .biYPel{*filter*}eter = 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)


hDib = CreateDIBitmap(MemDC, bm_info.bmiHeader, 0, Nothing, Nothing,

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,


Mon, 15 Nov 2004 17:16:43 GMT  
 [ 1 post ] 

 Relevant Pages 

1. BitBlting - need help!

2. PictureBox Help Needed

3. Desparately need Help! (Textbox on Picturebox)

4. Need Help Adding scroll to Picturebox

5. resize and draw text in picturebox, need help!

6. Help needed with two picturebox, 1 form, 1 function

7. need help scrolling a picturebox

8. PictureBox Help Needed !!

9. PictureBox : Need Help !!!!!!!!!!!!

10. Need Help: Picturebox partial copy and paste ?

11. Playing AVI in picturebox with mciSendString....need help !

12. need help with paintpicture and picturebox


Powered by phpBB® Forum Software