c# winform 应用编程代码总结 3
2010-12-13 15:57
239 查看
10、图像的特效显示
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr GetDC(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern int BitBlt(IntPtr hDestDC,int x,int y,int nWidth,int nHeight,IntPtr hSrcDC,int xSrc,int ySrc,int dwRop);
const int SRCCOPY = 0xCC0020;
private void button1_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
Bitmap bmp;
bmp=new Bitmap(this.openFileDialog1.FileName);
this.pictureBox1.Image=bmp;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
int i,j;
IntPtr hDC1;
IntPtr hDC2;
hDC1=GetDC(this.pictureBox1.Handle);
hDC2=GetDC(this.pictureBox2.Handle);
for (i=0;i<this.pictureBox1.Width/10;i++)
{
for(j=0;j<10;j++)
{
BitBlt(hDC2,j*this.pictureBox1.Width/10,0,i+2,this.pictureBox1.Height,hDC1,j*this.pictureBox1.Width/10,0,SRCCOPY);
}
System.Threading.Thread.Sleep(100);
}
}
11、显示动画光标
12、缩放时使用插值模式控制图片质量
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Image image = new Bitmap("..\\..\\test.bmp");
int width = image.Width;
int height = image.Height;
// Draw the image with no shrinking or stretching.
e.Graphics.DrawImage(
image,
new Rectangle(10, 10, width, height), // destination rectangle
0,
0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel,
null);
// Shrink the image using low-quality interpolation.
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.DrawImage(
image,
new Rectangle(10, 250, (int)(0.6 * width), (int)(0.6*height)),
// destination rectangle
0,
0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel);
// Shrink the image using medium-quality interpolation.
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
e.Graphics.DrawImage(
image,
new Rectangle(150, 250, (int)(0.6 * width), (int)(0.6 * height)),
// destination rectangle
0,
0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel);
// Shrink the image using high-quality interpolation.
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.DrawImage(
image,
new Rectangle(290, 250, (int)(0.6 * width), (int)(0.6 * height)),
// destination rectangle
0,
0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel);
}
13、轻松实现大图像浏览
this.pictureBox1.SizeMode=PictureBoxSizeMode.AutoSize;
if (this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
Bitmap b=new Bitmap(this.openFileDialog1.FileName);
this.pictureBox1.Image=b;
}
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr GetDC(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern int BitBlt(IntPtr hDestDC,int x,int y,int nWidth,int nHeight,IntPtr hSrcDC,int xSrc,int ySrc,int dwRop);
const int SRCCOPY = 0xCC0020;
private void button1_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
Bitmap bmp;
bmp=new Bitmap(this.openFileDialog1.FileName);
this.pictureBox1.Image=bmp;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
int i,j;
IntPtr hDC1;
IntPtr hDC2;
hDC1=GetDC(this.pictureBox1.Handle);
hDC2=GetDC(this.pictureBox2.Handle);
for (i=0;i<this.pictureBox1.Width/10;i++)
{
for(j=0;j<10;j++)
{
BitBlt(hDC2,j*this.pictureBox1.Width/10,0,i+2,this.pictureBox1.Height,hDC1,j*this.pictureBox1.Width/10,0,SRCCOPY);
}
System.Threading.Thread.Sleep(100);
}
}
11、显示动画光标
[DllImport("user32")] private static extern IntPtr SetCursor(IntPtr hCursor); [DllImport("user32")] private static extern IntPtr LoadCursorFromFile(string lpFileName); const int WM_SETCURSOR = 0x0020; private void Form1_Load(object sender, System.EventArgs e) { IntPtr hCursor; hCursor=LoadCursorFromFile("..\\..\\stopwtch.ani"); SetCursor(hCursor); } protected override void WndProc(ref System.Windows.Forms.Message m) { switch(m.Msg) { case WM_SETCURSOR: IntPtr hCursor; hCursor=LoadCursorFromFile("..\\..\\stopwtch.ani"); SetCursor(hCursor); break; default: base.WndProc(ref m); break; } }
12、缩放时使用插值模式控制图片质量
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Image image = new Bitmap("..\\..\\test.bmp");
int width = image.Width;
int height = image.Height;
// Draw the image with no shrinking or stretching.
e.Graphics.DrawImage(
image,
new Rectangle(10, 10, width, height), // destination rectangle
0,
0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel,
null);
// Shrink the image using low-quality interpolation.
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.DrawImage(
image,
new Rectangle(10, 250, (int)(0.6 * width), (int)(0.6*height)),
// destination rectangle
0,
0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel);
// Shrink the image using medium-quality interpolation.
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
e.Graphics.DrawImage(
image,
new Rectangle(150, 250, (int)(0.6 * width), (int)(0.6 * height)),
// destination rectangle
0,
0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel);
// Shrink the image using high-quality interpolation.
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.DrawImage(
image,
new Rectangle(290, 250, (int)(0.6 * width), (int)(0.6 * height)),
// destination rectangle
0,
0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel);
}
13、轻松实现大图像浏览
this.pictureBox1.SizeMode=PictureBoxSizeMode.AutoSize;
if (this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
Bitmap b=new Bitmap(this.openFileDialog1.FileName);
this.pictureBox1.Image=b;
}
相关文章推荐
- c# winform 应用编程代码总结 2
- c# winform 应用编程代码总结 5
- c# winform 应用编程代码总结 1
- c# winform 应用编程代码总结 10
- c# winform 应用编程代码总结 4
- c# winform 应用编程代码总结 7
- c# winform 应用编程代码总结 8
- c# winform 应用编程代码总结 12
- c# winform 应用编程代码总结 6
- c# winform 应用编程代码总结 9
- c# winform 应用编程代码总结 13
- c# winform 应用编程代码总结 15
- c# winform 应用编程代码总结 14
- c# winform 应用编程代码总结 11
- android 编程 应用代码
- Java 网络IO编程总结(BIO、NIO、AIO均含完整实例代码)
- 11 Java 网络IO编程总结(BIO、NIO、AIO均含完整实例代码)
- 以代码实例总结iOS应用开发中数据的存储方式
- 总结XHTML代码常见的应用问题
- android应用开发 网络编程与常见功能优化总结