private void button2_Click(object sender, EventArgs e)
{
int n = (int) listView1.View;
if (n == 4)
n = -1;
listView1.View = (View)Enum.ToObject(typeof(View), ++n);
}
using System.Drawing.Imaging;
public static Bitmap MakeGrayscale(Bitmap original)
{
//create a blank bitmap the same size as original
Bitmap newBitmap =
new Bitmap(original.Width, original.Height);
//get a graphics object from the new image
Graphics g = Graphics.FromImage(newBitmap);
//create the grayscale ColorMatrix
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}});
//create some image attributes
ImageAttributes attributes = new ImageAttributes();
//set the color matrix attribute
attributes.SetColorMatrix(colorMatrix);
//draw the original image on the new image
//using the grayscale color matrix
g.DrawImage(original,
new Rectangle(0, 0, original.Width, original.Height),
0, 0, original.Width, original.Height,
GraphicsUnit.Pixel, attributes);
//dispose the Graphics object
g.Dispose();
return newBitmap;
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap b = (Bitmap) pictureBox1.Image;
pictureBox2.Image = MakeGrayscale(b);
}
using System.Drawing.Imaging;
public Image GrayScaleImage(Graphics graph, Image img, int left, int top)
{
ColorMatrix colorMix = new ColorMatrix();
colorMix.Matrix00 = 1 / 3f;
colorMix.Matrix01 = 1 / 3f;
colorMix.Matrix02 = 1 / 3f;
colorMix.Matrix10 = 1 / 3f;
colorMix.Matrix11 = 1 / 3f;
colorMix.Matrix12 = 1 / 3f;
colorMix.Matrix20 = 1 / 3f;
colorMix.Matrix21 = 1 / 3f;
colorMix.Matrix22 = 1 / 3f;
ImageAttributes imgAttrib = new ImageAttributes();
imgAttrib.SetColorMatrix(colorMix);
graph.DrawImage(img, new Rectangle(left, top, img.Width,
img.Height), 0, 0, img.Width, img.Height,
GraphicsUnit.Pixel, imgAttrib);
Bitmap bmp = new Bitmap(img);
return bmp;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
// حالت معمولی
e.Graphics.DrawEllipse(new Pen(Color.Red, 10), 30, 30, 50, 50);
// SmoothingMode.AntiAlias روانسازی به کمک
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
e.Graphics.DrawEllipse(new Pen(Color.Blue, 10), 30, 100, 50, 50);
}
using System.Runtime.InteropServices;
// The signature for the callback method.
public delegate bool CallBack(IntPtr hwnd, int lParam);
[DllImport("user32.dll")]
public static extern int EnumWindows(CallBack callback, int param);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd,
StringBuilder lpString, int nMaxCount);
static void Main(string[] args)
{
// Request that the operating system enumerate all windows,
// and trigger your callback with the handle of each one.
EnumWindows(DisplayWindowInfo, 0);
Console.ReadLine();
}
// The method that will receive the callback. The second
// parameter is not used, but is needed to match the
// callback's signature.
public static bool DisplayWindowInfo(IntPtr hWnd, int lParam)
{
int chars = 100;
StringBuilder buf = new StringBuilder(chars);
if (GetWindowText(hWnd, buf, chars) != 0)
{
Console.WriteLine(buf);
}
return true;
}