.NET GDI+ Simple Image Operations
(In C#)
System.Drawing.Graphics g;
bmpOriginal = new Bitmap("C:\\myImage.gif");
int nNewWidth = 2 * bmpOriginal .Width; //suppose resize 200%
int nNewHeight = 2 * bmpOriginal .Height;
System.Drawing.Bitmap bmpModified = new Bitmap(nNewWidth, nNewHeight);
g = Graphics.FromImage(bmpModified );
RectangleF rectDest =new RectangleF(
0,
0,
nNewWidth,
nNewHeight);
RectangleF rectSource = new RectangleF(0, 0, bmpOriginal.Width, bmpOriginal.Height);
g.DrawImage(
bmpOriginal ,
rectDest,
rectSource ,
GraphicsUnit.Pixel);
bmpModified .Save("C:\\myNewImage.gif", System.Drawing.Imaging.ImageFormat.Gif);
g.Dispose();
g = null;
System.Drawing.Graphics g;
bmpOriginal = new Bitmap("C:\\myImage.gif");
int nNewWidth = 2 * bmpOriginal .Width; //suppose resize 200%
int nNewHeight = 2 * bmpOriginal .Height;
System.Drawing.Bitmap bmpModified = new Bitmap(nNewWidth, nNewHeight);
g = Graphics.FromImage(bmpModified );
RectangleF rectDest =new RectangleF(
0,
0,
nNewWidth,
nNewHeight);
RectangleF rectSource = new RectangleF(0, 0, bmpOriginal.Width, bmpOriginal.Height);
g.DrawImage(
bmpOriginal ,
rectDest,
rectSource ,
GraphicsUnit.Pixel);
bmpModified .Save("C:\\myNewImage.gif", System.Drawing.Imaging.ImageFormat.Gif);
g.Dispose();
g = null;
Comments