Save usercontrol as bitmap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • garethrichardadams@gmail.com

    #1

    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 BackgroundImage Layout =
    ImageLayout.Til ed.

    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.Clien tRectangle;
    Bitmap imageToSave = new Bitmap(areaToSa ve.Width, areaToSave.Heig ht);
    Graphics g = Graphics.FromIm age(imageToSave );
    g.DrawImage(can Canvas.Backgrou ndImage, areaToSave, areaToSave,
    GraphicsUnit.Pi xel);
    imageToSave.Sav e(fileName, imageFormatToSa ve);
    g.Dispose();
    imageToSave.Dis pose();

  • garethrichardadams@gmail.com

    #2
    Re: Save usercontrol as bitmap

    Nevermind, worked it out.

    Bitmap imageToSave = new Bitmap(canCanva s.ClientRectang le.Width,
    canCanvas.Clien tRectangle.Heig ht);

    Graphics g = Graphics.FromIm age(imageToSave );

    PaintEventArgs pe = new PaintEventArgs( g, new Rectangle(0, 0,
    canCanvas.Clien tRectangle.Widt h, canCanvas.Clien tRectangle.Heig ht));

    this.InvokePain tBackground(can Canvas, pe);
    this.InvokePain t(canCanvas, pe);

    imageToSave.Sav e(fileName, imageFormatToSa ve);

    g.Dispose();
    imageToSave.Dis pose();

    Comment

    Working...