winforms - Drawing transparent pixels in pictureBox C# -
i have picture box, , import .png picture into. when rotate actual image, "free" space of picture box, not include image filled black pixels.
q: how make black pixels transparent?
edit:
here rotation code
public static bitmap rotateimage(image image, pointf offset, float angle) { if (image == null) { return null; } try { bitmap rotatedbmp = new bitmap(image.width, image.height); rotatedbmp.setresolution(image.horizontalresolution, image.verticalresolution); using (graphics g = graphics.fromimage(rotatedbmp)) { g.translatetransform(offset.x, offset.y); g.rotatetransform(angle); g.translatetransform(-offset.x, -offset.y); g.drawimage(image, new point(0, 0)); } return rotatedbmp; } catch (outofmemoryexception) { gc.collect(); } catch (argumentexception) { } return image bitmap; } here original , modified images:


picturebox supports transparency if set supportstransparentbackcolor property of system.windows.forms.controlstyles true, put in form_load.
this.setstyle(system.windows.forms.controlstyles.supportstransparentbackcolor, true); you can set backcolor on picturebox colour if wish, default defaultbackcolor.
Comments
Post a Comment