471,350 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Save usercontrol as bitmap

Hello all,

I've got a user control I've created called canvas. Doesn't do much at
the moment.

I've set the background image to a small bitmap using BackgroundImage
and I've set it to tiled using BackgroundImageLayout =
ImageLayout.Tiled.

It all works - I get a tiled image.

What I'd like to do now is save the tiled image (i.e. exactly what I
can see in the window) to disk. The closest I can get is to save the
non-tiled image by referring to BackgroundImage but this isn't much
help!!

Can anyone point me in the right direction? Thanks

gareth

Rectangle areaToSave = new Rectangle();
areaToSave = canCanvas.ClientRectangle;
Bitmap imageToSave = new Bitmap(areaToSave.Width, areaToSave.Height);
Graphics g = Graphics.FromImage(imageToSave);
g.DrawImage(canCanvas.BackgroundImage, areaToSave, areaToSave,
GraphicsUnit.Pixel);
imageToSave.Save(fileName, imageFormatToSave);
g.Dispose();
imageToSave.Dispose();

Feb 9 '06 #1
1 6557
Nevermind, worked it out.

Bitmap imageToSave = new Bitmap(canCanvas.ClientRectangle.Width,
canCanvas.ClientRectangle.Height);

Graphics g = Graphics.FromImage(imageToSave);

PaintEventArgs pe = new PaintEventArgs(g, new Rectangle(0, 0,
canCanvas.ClientRectangle.Width, canCanvas.ClientRectangle.Height));

this.InvokePaintBackground(canCanvas, pe);
this.InvokePaint(canCanvas, pe);

imageToSave.Save(fileName, imageFormatToSave);

g.Dispose();
imageToSave.Dispose();

Feb 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Mark Johnson | last post: by
2 posts views Thread by Frank Trebus | last post: by
1 post views Thread by Andy Jacobs | last post: by
8 posts views Thread by RicercatoreSbadato | last post: by
3 posts views Thread by CSH | last post: by
1 post views Thread by DSchlichte | last post: by
8 posts views Thread by Nathan Sokalski | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.