How to create and draw into a white empty Image

  • Thread starter Thread starter TheLetti
  • Start date Start date
T

TheLetti

Hi,

I created some thumbnails from pictures - they all have a size of up to
80 pixels in width or height (if it is a square pic, the size is
exactly 80 x 80, otherwise 80 pixel is the size of the greater
dimension).

For displaying purposes, I want to view them all in the same size, that
is 80 x 80.
Pictures that are smaller shall have a white border to fill up the size
to 80 pixels.

How can I do that? I have the thumbnail already in a
System.Drawing.Image object, but I have no clue how to add this white
border, or even how to create the empty 80 x 80 white picture first,
where I want to draw my thumbnail into. I looked already for the
classes Bitmap, DrawImage, Graphics (all in namespace System.Drawing),
but couldn't find any appropriate method.


I appreciate any help,

TheLetti
 
TheLetti said:
How can I do that? I have the thumbnail already in a
System.Drawing.Image object, but I have no clue how to add this white
border, or even how to create the empty 80 x 80 white picture first,
where I want to draw my thumbnail into. I looked already for the
classes Bitmap, DrawImage, Graphics (all in namespace System.Drawing),
but couldn't find any appropriate method.

Try that...

// create a new bitmap
Bitmap bmp = new Bitmap(200, 200);

// get a Graphics object for drawing on the bitmap
Graphics g = Graphics.FromImage(bmp);

// draw on it
g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
g.FillEllipse(Brushes.Red, 0, 0, bmp.Width, bmp.Height);

// save it, or put it in a picturebox,...
bmp.Save(@"C:\MyImage.bmp", ImageFormat.Bmp);
 
Hello Markus,

thank you very much for your input. I figured it out right now thanks
to your help.


greez,
TheLetti
 
Back
Top