c# - Save an Image/Bitmap from hidden panels -
i have tabcontrol 4 tabs, , every tab contains panel. want save panels 1 click, can save panel in front.
do know way ?
bitmap eins = new bitmap(p1.width, p1.height); eins.save(".string."+1+".jpg",system.drawing.imaging.imageformat.jpeg);
i don't see filling bitmap
.
this should work panels
, no matter tabpage
on:
foreach (panel px in new panel[] { p1, p2, p3, p4 } ) using (bitmap bmp = new bitmap(px.clientsize.width, px.clientsize.height)) { px.drawtobitmap(bmp, px.clientrectangle); bmp.save(somefolder + px.name + ".jpg", system.drawing.imaging.imageformat.jpeg); }
in fact work if panels
actually invisible , not in 1 of hidden tabpages
!
of course must make sure panels
have unique , filename compliant names
..
update: know have controls
inside panel
, not graphics draw , maybe backgroundimage
, can understand problems had..
unfortunately tabpages
have nasty way of hiding embedded controls.
so wrote little helper routine doesn't cause more blink of main form going inactive , back..:
void savehiddencontrol(control ctl, string filename) { control originalparent = ctl.parent; form fff = new form(); fff.opacity = 0; ctl.parent = fff; fff.show(); system.drawing.imaging.imageformat fmt = system.drawing.imaging.imageformat.jpeg; if (filename.tolower().endswith(".png")) fmt = system.drawing.imaging.imageformat.png; using (bitmap bmp = new bitmap(ctl.clientsize.width, ctl.clientsize.height)) { ctl.drawtobitmap(bmp, ctl.clientrectangle); bmp.save(filename, fmt); } ctl.parent = originalparent; fff.close(); }
here result:
note how form
transparent , yet lets panel
drawtobitmap
fine, including image, ellipse , 2 controls , independent of form.size
..!
update2 , here function dosn't blink @ all, @ least if panel indeed not visible:
void savehiddencontrol(control ctl, string filename) { control originalparent = ctl.parent; int oldleft = ctl.left; ctl.left = 22222; // way outside ctl.parent = this; system.drawing.imaging.imageformat fmt = system.drawing.imaging.imageformat.jpeg; if (filename.tolower().endswith(".png")) fmt = system.drawing.imaging.imageformat.png; using (bitmap bmp = new bitmap(ctl.clientsize.width, ctl.clientsize.height)) { ctl.drawtobitmap(bmp, ctl.clientrectangle); bmp.save(filename, fmt); } ctl.parent = originalparent; ctl.left = oldleft; }
this moves panel
onto main form
way right
, won't show. saves , moves back. of course should check if panel
indeed on hidden tabpage
or else blink; in case original routine do..
Comments
Post a Comment