using System; using System.Drawing; using System.Windows.Forms; class ImageReflection: Form { Image image = Image.FromFile("Color.jpg"); public static void Main() { Application.Run(new ImageReflection()); } public ImageReflection() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { int cxImage = image.Width; int cyImage = image.Height; grfx.DrawImage(image, cx / 2, cy / 2, cxImage, cyImage); grfx.DrawImage(image, cx / 2, cy / 2, -cxImage, cyImage); grfx.DrawImage(image, cx / 2, cy / 2, cxImage, -cyImage); grfx.DrawImage(image, cx / 2, cy / 2, -cxImage, -cyImage); } }
2D Graphics
Image At Points (Draw part of the image)
using System; using System.Drawing; using System.Windows.Forms; class ImageAtPoints: Form { Image image = Image.FromFile("Color.jpg"); public static void Main() { Application.Run(new ImageAtPoints()); } public ImageAtPoints() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { grfx.DrawImage(image, new Point[] { new Point(cx / 2, 0), new Point(cx, cy / 2), new Point(0, cy / 2)}); } }
Draw Partial Image
using System; using System.Drawing; using System.Windows.Forms; class PartialImage: Form { Image image = Image.FromFile("Color.jpg"); public static void Main() { Application.Run(new PartialImage()); } public PartialImage() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { Rectangle rect = new Rectangle(95, 5, 50, 55); grfx.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel); } }
Partial Image Stretch
using System; using System.Drawing; using System.Windows.Forms; class PartialImageStretch: Form { Image image = Image.FromFile("Color.jpg"); public static void Main() { Application.Run(new PartialImageStretch()); } public PartialImageStretch() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { Rectangle rectSrc = new Rectangle(95, 5, 50, 55); Rectangle rectDst = new Rectangle( 0, 0, cx, cy); grfx.DrawImage(image, rectDst, rectSrc, GraphicsUnit.Pixel); } }
Partial Image Rotate
using System; using System.Drawing; using System.Windows.Forms; class PartialImageRotate: Form { Image image = Image.FromFile("Color.jpg"); public static void Main() { Application.Run(new PartialImageRotate()); } public PartialImageRotate() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { Point[] aptDst = { new Point(0, cy / 2), new Point(cx / 2, 0), new Point(cx / 2, cy) }; Rectangle rectSrc = new Rectangle(95, 5, 50, 55); grfx.DrawImage(image, aptDst, rectSrc, GraphicsUnit.Pixel); } }
Draw text on an Image
using System; using System.Drawing; using System.Windows.Forms; class DrawOnImage: Form { Image image = Image.FromFile("Color.jpg"); string str = "www.kutayzorlu.com/java2s/com"; public static void Main() { Application.Run(new DrawOnImage()); } public DrawOnImage() { ResizeRedraw = true; Graphics grfxImage = Graphics.FromImage(image); grfxImage.PageUnit = GraphicsUnit.Inch; grfxImage.PageScale = 1; SizeF sizef = grfxImage.MeasureString(str, Font); grfxImage.DrawString(str, Font, Brushes.White, grfxImage.VisibleClipBounds.Width - sizef.Width, 0); grfxImage.Dispose(); } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { grfx.PageUnit = GraphicsUnit.Pixel; grfx.DrawImage(image, 0, 0); grfx.DrawString(str, Font, new SolidBrush(clr), grfx.DpiX * image.Width / image.HorizontalResolution, 0); } }
Draw on Pixel-Size Image
using System; using System.Drawing; using System.Windows.Forms; class DrawOnPixelSizeImage: Form { Image image = Image.FromFile("Color.jpg"); string str = "www.kutayzorlu.com/java2s/com"; public static void Main() { Application.Run(new DrawOnPixelSizeImage()); } public DrawOnPixelSizeImage() { ResizeRedraw = true; Graphics grfxImage = Graphics.FromImage(image); Graphics grfxScreen = CreateGraphics(); Font font = new Font(Font.FontFamily, grfxScreen.DpiY / grfxImage.DpiY * Font.SizeInPoints); SizeF sizef = grfxImage.MeasureString(str, font); grfxImage.DrawString(str, font, Brushes.White, image.Width - sizef.Width, 0); grfxImage.Dispose(); grfxScreen.Dispose(); } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { grfx.DrawImage(image, 0, 0, image.Width, image.Height); grfx.DrawString(str, Font, new SolidBrush(clr), image.Width, 0); } }