日期:2014-05-20 浏览次数:21153 次
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
public class Form1 : Form
{
Bitmap bitmap = new Bitmap(500, 400);
ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix();
public Form1()
{
this.DoubleBuffered = true;
this.ClientSize = bitmap.Size;
using (Graphics g = Graphics.FromImage(this.bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bitmap.Size);
}
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(
this.bitmap,
this.ClientRectangle, 0, 0, this.bitmap.Width, this.bitmap.Height,
GraphicsUnit.Pixel,
this.imageAttributes);
}
protected override void OnMouseMove(MouseEventArgs e)
{
this.matrix[4, 0] = (e.X - this.ClientRectangle.Width / 2.0f) / this.ClientRectangle.Width;
this.matrix[4, 1] = (e.Y - this.ClientRectangle.Height / 2.0f) / this.ClientRectangle.Height;
this.imageAttributes.SetColorMatrix(this.matrix);
Invalidate();
}
static void Main()
{
Application.Run(new Form1());
}
}
------解决方案--------------------
学习了
------解决方案--------------------
帮顶下
------解决方案--------------------
百叶窗效果显示图像
推拉效果显示图像
水平交错效果显示图像
垂直交错效果显示图像
图像纹理效果
图像浮雕效果
图像积木效果
马赛克效果显示图像
将彩色图片转换为灰度图片
反转图片的颜色
旋转、反射和扭曲图像
------解决方案--------------------
此贴必火啊。
先收藏,再想想代码
------解决方案--------------------
帮顶
------解决方案--------------------
好主意
先帮顶了
------解决方案--------------------
最近怎么这么多人对图形感冒了.
------解决方案--------------------
看看这个http://www.cnpopsoft.com/article.asp?id=76,功能很强大的图片处理软件,全源码共享
------解决方案--------------------
http://topic.csdn.net/u/20090420/00/4042e404-e802-45f7-8b25-c7fbc5a81c76.html
------解决方案--------------------
图像算法?啥意思?
------解决方案--------------------
学习
------解决方案--------------------
public static bool GetThumbnailJPEG(string sourceFile,ref string destFile, int destHeight, int destWidth)
{
System.Drawing.Image imgSource = System.Drawing.Image.FromFile(sourceFile);
int sW = 0, sH = 0;
// 按比例缩放
int sWidth = imgSource.Width;
int sHeight = imgSource.Height;
if (sHeight > destHeight || sWidth > destWidth)
{
if ((sWidth * destHeight) > (sHeight * destWidth))
{
sW = destWidth;
sH = (destWidth * sHeight) / sWidth;
}
else
{
sH = destHeight;
sW = (sWidth * destHeight) / sHeight;
}
}
else
{
sW = sWidth;
sH = sHeight;
}
Bitmap outBmp = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage(outBmp);
g.Clear(Color.Black);
// 设置画布的描绘质量
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
g.Dispose();
// 以下代码为保存图片时,设置压缩质量
EncoderParameters encoderParams = new EncoderParameters();
long[] quality = new long[1];
quality[0] = 100;
EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
encoderParams.Param[0] = encoderParam;
try
{
//获得包含有关内置图像编码解码器的信息的ImageCodecInfo 对象。
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo jpegICI = null;
for (int x = 0; x < arrayICI.Length; x++)
{
if (arrayICI[x].FormatDescription.Equals("JPEG"))
{
jpegICI = arrayICI[x];//设置JPEG编码
break;
}
}
string savefile =Path.GetDirectoryName( destFile) + "\\" + Path.GetFileName(destFile).Replace(Path.GetExtension(destFile), ".jpg");
destFile = savefile;
if (jpegICI != null)
{
outBmp.Save(savefile, jpegICI, encoderParams);
}
else
{
outBmp.Save(savefile, ImageFormat.Jpeg);
}
return true;
}
catch
{
return false;
}
finally
{
imgSource.Dispose();
outBmp.Dispose();
}
}