graphics - VB.NET using bitblt to draw bitmap renders a black square -


i'm starting out vb.net after many years of vb 6.0 , thought i'd started graphics.

just fun i'm using bitblt draw bitmap have loaded resource , draw on form. can load existing image picturebox , bitblt it, works fine. can load bitmap resources , store picturebox, when take bitmap, turn gdi graphics object , bitblt onto form, black square same size bitmap.

here code:

    dim srcbmp new bitmap(me.gettype, "colorwheel.bmp")     dim drect new rectangle(0, 0, 233, 233)     'srcgrp = picturebox1.creategraphics 'this works.     srcgrp = graphics.fromimage(srcbmp)     'this doesn't      targetgrp = me.creategraphics 'destination graphics      srchdc = srcgrp.gethdc     targethdc = targetgrp.gethdc      bitblt(targethdc, 0, 0, 233, 233, srchdc, 0, 0, srccopy)      srcgrp.releasehdc(srchdc)     targetgrp.releasehdc(targethdc)     targetgrp.dispose()     srcbmp.dispose()     srcgrp.dispose() 

the reasons want use bitblt a) i've used before, first choice. b) know possible use black , white mask mask out areas transparent, need. , b) graphics may moving around frequently.

is there better way of drawing graphics transparent background onto form or picturebox? e.g. png alpha channel?

worked out.

1) load bitmap 2) hbitmap bitmap 3) create blank dc stream 4) create compatible dc dc stream

        dim srcbmp new bitmap(me.gettype, "colorwheel.png")         dim hbm intptr = srcbmp.gethbitmap()         dim sdc intptr = getdc(intptr.zero)         dim hdc intptr = createcompatibledc(sdc) 

you can bitblt hdc. found bitblt doesn't work in .net same used in vb6. i'm going try drawimage method instead.


Comments