using System;
using System.Drawing;
using System.Windows.Forms;
class ImageScaleToRectangle: Form
{
Image image = Image.FromFile("Color.jpg");
public static void Main()
{
Application.Run(new ImageScaleToRectangle());
}
public ImageScaleToRectangle()
{
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, 0, 0, cx, cy);
}
}
ASP.NET & Csharp (C#)
ASP.NET & Csharp (C#) , Here you can find my posts about .NET c# .
Image Scale Isotropic
using System;
using System.Drawing;
using System.Windows.Forms;
class ImageScaleIsotropic: Form
{
Image image = Image.FromFile("Color.jpg");
public static void Main()
{
Application.Run(new ImageScaleIsotropic());
}
public ImageScaleIsotropic()
{
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(0, 0, cx, cy);
SizeF sizef = new SizeF(image.Width / image.HorizontalResolution,
image.Height / image.VerticalResolution);
float fScale = Math.Min(rect.Width / sizef.Width,
rect.Height / sizef.Height);
sizef.Width *= fScale;
sizef.Height *= fScale;
grfx.DrawImage(image, rect.X + (rect.Width - sizef.Width ) / 2,
rect.Y + (rect.Height - sizef.Height) / 2,
sizef.Width, sizef.Height);
}
}
Image Reflection
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);
}
}
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);
}
}