C# winform 开发 由于需要,我需要一个能够批量添加本地图片,批量预览缩略图,还要求可以对单张图片实施编辑(如编号,添加注释,旋转等),最后可以上传的东东。我是小菜,winform方面技术几乎为零,还请教各位大哥大姐帮帮忙。就以上上面这些功能会涉及到哪些零散的技术。我只能边学边写了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 PictureBox肯定要吧OpenFileDialog也要吧Image也要吧一些用来显示信息的也要吧 http://topic.csdn.net/u/20090420/00/4042e404-e802-45f7-8b25-c7fbc5a81c76.html 批量添加本地图片 OpenFileDialog openSource = new OpenFileDialog(); openSource.Filter = "所有影像文件 (*.ASF,*.MPEG-1,*.MPEG-2,*.WAV,*.AVI,*.MIDI,*.VOD,*.AU,*.MP3,*.MPG,*.wmv,*.rmvb,*.JPGE)|*.ASF;*.MPEG-1;*.MPEG-2;*.WAV;*.AVI;*.MIDI;*.VOD;*.AU;*.MP3;*.MPG;*.wmv;*.rmvb;*.jpg"; if (openSource.ShowDialog() == DialogResult.OK) { DirectoryInfo directory = new DirectoryInfo(openSource.FileName.Substring(0, openSource.FileName.LastIndexOf("\\"))); if (!Directory.Exists(存储图片路径+ "\\" + dgvBaoTao.CurrentRow.Cells["PackageName"].Value.ToString())) { Directory.CreateDirectory(存储图片路径 + "\\" + 图片名.jpg); } FileInfo[] diInfo = directory.GetFiles(); 批量预览缩略图:我做的办法是做了一个自定义控件因为图片有名称,类型等属性。 如果没有就用for 添加PictureBox! /// <summary> /// 以逆时针为方向对图像进行旋转 /// </summary> /// <param name="b">位图流</param> /// <param name="angle">旋转角度[0,360](前台给的)</param> /// <returns></returns> public Bitmap Rotate(Bitmap b, int angle) { angle = angle % 360; //弧度转换 double radian = angle * Math.PI / 180.0; double cos = Math.Cos(radian); double sin = Math.Sin(radian); //原图的宽和高 int w = b.Width; int h = b.Height; int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin))); int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos))); //目标位图 Bitmap dsImage = new Bitmap(W, H); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //计算偏移量 Point Offset = new Point((W - w) / 2, (H - h) / 2); //构造图像显示区域:让图像的中心与窗口的中心点一致 Rectangle rect = new Rectangle(Offset.X, Offset.Y, w, h); Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); g.TranslateTransform(center.X, center.Y); g.RotateTransform(360 - angle); //恢复图像在水平和垂直方向的平移 g.TranslateTransform(-center.X, -center.Y); g.DrawImage(b, rect); //重至绘图的所有变换 g.ResetTransform(); g.Save(); g.Dispose(); //dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); return dsImage; } private const string IMAGEFILE = "FocusPoint.JPG"; MyAngle = 90; //MyAngle += 90; //if (MyAngle > 360) MyAngle = 90; pictureBox1.Image = Rotate(GetSourceImg(IMAGEFILE), MyAngle); 太感谢lin45143777了,虽然我只能看懂一部分。谢谢你啊!我好好学习学习代码。 图片旋转可以用image的RotateFlip方法来控制旋转! 图像处理类~~~using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Imaging;using System.IO;using System.Drawing.Drawing2D;namespace Silent.Web.Controllers.Common{ /**//// <summary> /// ASPJpegBase /// Author : Jolly /// </summary> public class ASPJpegBase : IDisposable { /**//// <summary> /// 会产生graphics异常的PixelFormat /// </summary> private static PixelFormat[] indexedPixelFormats = { PixelFormat.Undefined, PixelFormat.DontCare, PixelFormat.Format16bppArgb1555, PixelFormat.Format1bppIndexed, PixelFormat.Format4bppIndexed, PixelFormat.Format8bppIndexed }; /**//// <summary> /// 图片宽度--生成缩略图时使用 /// </summary> public int Width { get; set; } /**//// <summary> /// 图片高度--生成缩略图时使用 /// </summary> public int Height { get; set; } /**//// <summary> /// Bitmap对象 /// </summary> public Bitmap CurrentBitmap { get { if (oCurrentImage == null) throw new NullReferenceException("CurrentBitmap is null!"); return oCurrentImage; } } private Bitmap oCurrentImage; private ASPJpegEffect etASPJpegEffect; /**//// <summary> /// 图片特效处理 /// </summary> public ASPJpegEffect Effect { get { etASPJpegEffect = new ASPJpegEffect(); etASPJpegEffect.CurrentBitmap = this.CurrentBitmap; return etASPJpegEffect; } } /**//// <summary> /// 默认构造函数 /// </summary> public ASPJpegBase() { } /**//// <summary> /// 构造函数 /// </summary> /// <param name="sImagePath">图片路径</param> public ASPJpegBase(string sImagePath) { oCurrentImage = new Bitmap(sImagePath); //如果原图片是索引像素格式之列的,则需要转换 if (IsPixelFormatIndexed(oCurrentImage.PixelFormat)) { using(Bitmap bmp = new Bitmap(oCurrentImage.Width, oCurrentImage.Height, PixelFormat.Format32bppArgb)) { using (Graphics g = Graphics.FromImage(bmp)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.DrawImage(oCurrentImage, 0, 0); } oCurrentImage = (Bitmap)bmp.Clone(); } } } /**//// <summary> /// 构造函数 /// </summary> /// <param name="oImage">Image对象</param> public ASPJpegBase(Image oImage) { oCurrentImage = new Bitmap(oImage); } /**//// <summary> /// 实例化Bitmap对象 /// </summary> /// <param name="sImagePath">图片路径</param> public void Open(string sImagePath) { oCurrentImage = new Bitmap(sImagePath); } /**//// <summary> /// 判断图片的PixelFormat 是否在 引发异常的 PixelFormat 之中 /// 无法从带有索引像素格式的图像创建graphics对象 /// </summary> /// <param name="imgPixelFormat">原图片的PixelFormat</param> /// <returns></returns> private static bool IsPixelFormatIndexed(PixelFormat imgPixelFormat) { foreach (PixelFormat pf in indexedPixelFormats) { if (pf.Equals(imgPixelFormat)) return true; } return false; } /**//// <summary> /// 添加文字水印 /// </summary> /// <param name="text"></param> /// <param name="p"></param> /// <param name="fontcolor"></param> /// <param name="font"></param> public void DrawText(string sText, Font font, Color fontcolor, Point p, float rotate) { using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap)) { if (rotate != 0) graphics.RotateTransform(rotate); graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.DrawString(sText, font, new SolidBrush(fontcolor), (float)p.X, (float)p.Y); } } /**//// <summary> /// 添加文字水印-文字带背景 /// </summary> /// <param name="text"></param> /// <param name="p"></param> /// <param name="fontcolor"></param> /// <param name="font"></param> public void DrawText(string sText, Font font, Color fontcolor, Point p, float rotate, string sImagePath) { TextureBrush tb = new TextureBrush(Image.FromFile(sImagePath)); using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap)) { if (rotate != 0) graphics.RotateTransform(rotate); graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.DrawString(sText, font, tb, (float)p.X, (float)p.Y); } } /**//// <summary> /// 绘制边框 /// </summary> /// <param name="frameColor">边框颜色</param> /// <param name="frameWidth">边框宽度</param> public void DrawFrame(Color frameColor, int frameWidth) { double iNewframeWidth = (Convert.ToDouble(frameWidth) / Convert.ToDouble(2)); using (Bitmap newBitmap = new Bitmap(this.CurrentBitmap.Width + (2 * frameWidth), this.CurrentBitmap.Height + (2 * frameWidth))) { using (Graphics graphics = Graphics.FromImage(newBitmap)) { graphics.Clear(Color.White); Pen pen = new Pen(frameColor, frameWidth); graphics.DrawRectangle(pen, (float)iNewframeWidth, (float)iNewframeWidth, newBitmap.Width - frameWidth, newBitmap.Height - frameWidth); graphics.DrawImage(this.CurrentBitmap, new Rectangle(frameWidth, frameWidth,this.CurrentBitmap.Width,this.CurrentBitmap.Height)); this.oCurrentImage = ((Bitmap)newBitmap.Clone()); } } } /**//// <summary> /// 绘制3D边框 /// </summary> /// <param name="frameColor">边框颜色</param> /// <param name="frameWidth">边框宽度</param> public void Draw3DFrame(Color frameColor, int frameWidth) { double iNewframeWidth = (Convert.ToDouble(frameWidth) / Convert.ToDouble(2)); using (Bitmap newBitmap = new Bitmap(this.CurrentBitmap.Width + (2 * frameWidth), this.CurrentBitmap.Height + (2 * frameWidth))) { using (Graphics graphics = Graphics.FromImage(newBitmap)) { graphics.Clear(Color.White); Pen pen = new Pen(frameColor, (float)iNewframeWidth); Pen pen1 = new Pen(Color.FromArgb(frameColor.ToArgb() - 10), (float)iNewframeWidth); graphics.DrawRectangle(pen, (float)iNewframeWidth / 2, (float)iNewframeWidth / 2, newBitmap.Width - (float)iNewframeWidth, newBitmap.Height - (float)iNewframeWidth); graphics.DrawRectangle(pen1, 3 * (float)iNewframeWidth / 2, 3 * (float)iNewframeWidth / 2, newBitmap.Width - 3 * (float)iNewframeWidth, newBitmap.Height - 3 * (float)iNewframeWidth); graphics.DrawImage(this.CurrentBitmap, 2 * (float)iNewframeWidth, 2 * (float)iNewframeWidth, (float)this.CurrentBitmap.Width, (float)this.CurrentBitmap.Height); this.oCurrentImage = (Bitmap)newBitmap.Clone(); } } } /**//// <summary> /// 图片切割功能 /// </summary> /// <param name="left">left</param> /// <param name="top">top</param> /// <param name="right">right</param> /// <param name="bottom">bottom</param> public void Crop(int left, int top, int right, int bottom) { int num; int num2; if ((this.CurrentBitmap.Width - left) < right) { num = this.CurrentBitmap.Width - right; } else { num = right; } if ((this.CurrentBitmap.Height - top) < bottom) { num2 = this.CurrentBitmap.Height - top; } else { num2 = bottom; } using (Bitmap image = new Bitmap(num, num2)) { image.SetResolution(this.CurrentBitmap.HorizontalResolution, this.CurrentBitmap.VerticalResolution); using (Graphics graphics = Graphics.FromImage(image)) { graphics.Clear(Color.White); graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.DrawImage(this.CurrentBitmap, new Rectangle(0, 0, num, num2), new Rectangle(left, top, num, num2), GraphicsUnit.Pixel); oCurrentImage = (Bitmap)image.Clone(); } } } /**//// <summary> /// 图片移动 /// </summary> /// <param name="lefttopx"></param> /// <param name="lefttopy"></param> /// <param name="rightbottomx"></param> /// <param name="rightbottomy"></param> /// <param name="tox"></param> /// <param name="toy"></param> public void Move(int lefttopx, int lefttopy, int rightbottomx, int rightbottomy, int tox, int toy) { using (Bitmap image = this.Copy(lefttopx, lefttopy, rightbottomx, rightbottomy)) { Rectangle rect = GetRectangle(lefttopx, lefttopy, rightbottomx, rightbottomy); using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap)) { graphics.Clear(Color.White); graphics.FillRectangle(new SolidBrush(Color.White), rect); graphics.DrawImage(image, tox, toy); oCurrentImage = (Bitmap)image.Clone(); } } } /**//// <summary> /// 调整图片大小 /// </summary> /// <param name="width"></param> /// <param name="height"></param> public void ResizeTo(int width, int height) { this.oCurrentImage = new Bitmap(this.CurrentBitmap, width, height); } /**//// <summary> /// 生成缩略图 /// </summary> public void CreateThumbnail(int iWidth, int iHeight) { //用指定的大小和格式初始化 Bitmap 类的新实例 using (Bitmap bitmap = (Bitmap)oCurrentImage.Clone()) { ResizeTo(iWidth, iHeight); //在指定位置并且按指定大小绘制 原图片 对象 Graphics.FromImage(oCurrentImage).DrawImage(bitmap, new Rectangle(0, 0, iWidth, iHeight)); } } /**//// <summary> /// 生成缩略图 /// </summary> /// <param name="sThumbnailPath">缩略图保存路径</param> public void CreateThumbnail(string sThumbnailPath) { if (Width > 0 && Height > 0 && (Width < oCurrentImage.Width || Height < oCurrentImage.Height)) { int width = Width; int height = Height; double factor = 1; if (oCurrentImage.Width > oCurrentImage.Height) { factor = Convert.ToDouble(width) / Convert.ToDouble(oCurrentImage.Width); height = Convert.ToInt32(oCurrentImage.Height * factor); } else { factor = Convert.ToDouble(height) / Convert.ToDouble(oCurrentImage.Height); width = Convert.ToInt32(oCurrentImage.Width * factor); } //用指定的大小和格式初始化 Bitmap 类的新实例 Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); //从指定的 Image 对象创建新 Graphics 对象 Graphics graphics = Graphics.FromImage(bitmap); //清除整个绘图面并以透明背景色填充 graphics.Clear(Color.Transparent); //在指定位置并且按指定大小绘制 原图片 对象 graphics.DrawImage(oCurrentImage, new Rectangle(0, 0, width, height)); try { bitmap.Save(sThumbnailPath); } catch (System.Exception e) { throw e; } finally { bitmap.Dispose(); graphics.Dispose(); } } } /**//// <summary> /// 图片垂直翻转 /// </summary> public void FlipV() { this.CurrentBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX); } /**//// <summary> /// 图片水平翻转 /// </summary> public void FlipH() { this.CurrentBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); } /**//// <summary> /// 图片旋转 /// </summary> /// <param name="angle">旋转度数</param> public void Rotate(int angle) { angle = angle % 360; if (angle < 0) { angle += 360; } if (angle >= 270) { this.CurrentBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone); angle -= 270; } else if (angle >= 180) { this.CurrentBitmap.RotateFlip(RotateFlipType.Rotate180FlipNone); angle -= 180; } else if (angle >= 90) { this.CurrentBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone); angle -= 90; } if (angle > 0) { double a = (angle * 3.1415926535897931) / 180.0; int width = Convert.ToInt32((double)((this.CurrentBitmap.Height * Math.Sin(a)) + (this.CurrentBitmap.Width * Math.Cos(a)))); int height = Convert.ToInt32((double)((this.CurrentBitmap.Width * Math.Sin(a)) + (this.CurrentBitmap.Height * Math.Cos(a)))); Bitmap image = new Bitmap(width, height * 2); image.SetResolution(this.CurrentBitmap.HorizontalResolution, this.CurrentBitmap.VerticalResolution); Graphics graphics = Graphics.FromImage(image); graphics.Clear(Color.White); Matrix matrix = new Matrix(1f, 0f, 0f, -1f, 0f, 0f); matrix.Translate(0f, (float)this.CurrentBitmap.Height, MatrixOrder.Append); graphics.Transform = matrix; Matrix matrix2 = new Matrix(); matrix2.RotateAt((float)-angle, (PointF)new Point(0, 0), MatrixOrder.Append); matrix2.Translate(0f, 0f, MatrixOrder.Append); GraphicsPath path = new GraphicsPath(); Point[] points = new Point[] { new Point(0, this.CurrentBitmap.Height), new Point(this.CurrentBitmap.Width, this.CurrentBitmap.Height), new Point(0, 0) }; path.AddPolygon(points); path.Transform(matrix2); PointF[] pathPoints = path.PathPoints; graphics.DrawImage(this.CurrentBitmap, pathPoints); graphics.ResetTransform(); int num4 = this.CurrentBitmap.Height; this.oCurrentImage = new Bitmap(width, height); this.CurrentBitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (Graphics newGraphics = Graphics.FromImage(this.CurrentBitmap)) { newGraphics.Clear(Color.White); newGraphics.DrawImage(image, new Rectangle(0, 0, width, height), new Rectangle(0, Convert.ToInt32((double)(num4 * (1.0 - Math.Cos(a)))), width, height), GraphicsUnit.Pixel); image.Dispose(); graphics.Dispose(); path.Dispose(); } } } /**//// <summary> /// 画弧形 /// </summary> /// <param name="r"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> /// <param name="startangle"></param> /// <param name="sweepAngle"></param> public void DrawArc(Rectangle r, int linewidth, Color linecolor, float startangle, float sweepAngle) { using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap)) { Pen pen = new Pen(linecolor, (float)linewidth); graphics.DrawArc(pen, r, startangle, sweepAngle); } } /**//// <summary> /// 画椭圆 /// </summary> /// <param name="r"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> /// <param name="fillcolor"></param> public void DrawEllipse(Rectangle r, int linewidth, Color linecolor, Color fillcolor) { using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap)) { Pen pen = new Pen(linecolor, (float)linewidth); graphics.DrawEllipse(pen, r); if (fillcolor != Color.Empty) { graphics.FillEllipse(new SolidBrush(fillcolor), r); } } } /**//// <summary> /// 画椭圆 /// </summary> /// <param name="lefttop"></param> /// <param name="rightbottom"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> /// <param name="fillcolor"></param> public void DrawEllipse(Point lefttop, Point rightbottom, int linewidth, Color linecolor, Color fillcolor) { this.DrawEllipse(new Rectangle(lefttop.X, lefttop.Y, rightbottom.X - lefttop.X, rightbottom.Y - lefttop.Y), linewidth, linecolor, fillcolor); } /**//// <summary> /// 画椭圆 /// </summary> /// <param name="lefttopx"></param> /// <param name="lefttopy"></param> /// <param name="rightbottomx"></param> /// <param name="rightbottomy"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> /// <param name="fillcolor"></param> public void DrawEllipse(int lefttopx, int lefttopy, int rightbottomx, int rightbottomy, int linewidth, Color linecolor, Color fillcolor) { this.DrawEllipse(new Rectangle(lefttopx, lefttopy, rightbottomx - lefttopx, rightbottomy - lefttopy), linewidth, linecolor, fillcolor); } /**//// <summary> /// 画图上图 /// </summary> /// <param name="img"></param> /// <param name="r"></param> public void DrawImage(System.Drawing.Image img, Rectangle r) { Graphics.FromImage(this.CurrentBitmap).DrawImage(img, r); } /**//// <summary> /// 画线 /// </summary> /// <param name="pFrom"></param> /// <param name="pTo"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> public void DrawLine(Point pFrom, Point pTo, int linewidth, Color linecolor) { using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap)) { Pen pen = new Pen(linecolor, (float)linewidth); graphics.DrawLine(pen, pFrom, pTo); } } /**//// <summary> /// 画线 /// </summary> /// <param name="fromx"></param> /// <param name="fromy"></param> /// <param name="tox"></param> /// <param name="toy"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> public void DrawLine(int fromx, int fromy, int tox, int toy, int linewidth, Color linecolor) { this.DrawLine(new Point(fromx, fromy), new Point(tox, toy), linewidth, linecolor); } /**//// <summary> /// 画多条线 /// </summary> /// <param name="points"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> public void DrawLines(Point[] points, int linewidth, Color linecolor) { using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap)) { Pen pen = new Pen(linecolor, (float)linewidth); graphics.DrawLines(pen, points); } } /**//// <summary> /// 画长方形 /// </summary> /// <param name="r"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> /// <param name="fillcolor"></param> public void DrawRectangle(Rectangle r, int linewidth, Color linecolor, Color fillcolor) { using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap)) { Pen pen = new Pen(linecolor, (float)linewidth); graphics.DrawRectangle(pen, r); if (fillcolor != Color.Empty) { graphics.FillRectangle(new SolidBrush(fillcolor), r); } } } /**//// <summary> /// 画长方形 /// </summary> /// <param name="lefttop"></param> /// <param name="rightbottom"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> /// <param name="fillcolor"></param> public void DrawRectangle(Point lefttop, Point rightbottom, int linewidth, Color linecolor, Color fillcolor) { this.DrawRectangle(new Rectangle(lefttop.X, lefttop.Y, rightbottom.X - lefttop.X, rightbottom.Y - lefttop.Y), linewidth, linecolor, fillcolor); } /**//// <summary> /// 画长方形 /// </summary> /// <param name="lefttopx"></param> /// <param name="lefttopy"></param> /// <param name="rightbottomx"></param> /// <param name="rightbottomy"></param> /// <param name="linewidth"></param> /// <param name="linecolor"></param> /// <param name="fillcolor"></param> public void DrawRectangle(int lefttopx, int lefttopy, int rightbottomx, int rightbottomy, int linewidth, Color linecolor, Color fillcolor) { this.DrawRectangle(GetRectangle(lefttopx, lefttopy, rightbottomx, rightbottomy), linewidth, linecolor, fillcolor); } /**//// <summary> /// 保存图片到内存中 /// </summary> /// <param name="mms"></param> /// <param name="RawFormat"></param> public void Save(MemoryStream mms, ImageFormat RawFormat) { this.CurrentBitmap.Save(mms, RawFormat); } /**//// <summary> /// 保存图片到文件流中 /// </summary> /// <param name="mms"></param> /// <param name="RawFormat"></param> public void Save(Stream mms, ImageFormat RawFormat) { this.CurrentBitmap.Save(mms, RawFormat); } /**//// <summary> /// 保存为Gif图片 /// </summary> /// <param name="sSavePath"></param> public void SaveGif(string sSavePath) { this.CurrentBitmap.Save(sSavePath, ImageFormat.Gif); } /**//// <summary> /// 保存为jpg图片 /// </summary> /// <param name="sSavePath"></param> /// <param name="iQuantity">图片质量</param> public void SaveJpeg(string sSavePath, int iQuantity) { ImageCodecInfo encoderInfo = GetEncoderInfo("image/jpeg"); EncoderParameters encoderParams = new EncoderParameters(1); encoderParams = new EncoderParameters(); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)iQuantity); this.CurrentBitmap.Save(sSavePath, encoderInfo, encoderParams); encoderParams.Dispose(); } winform界面的有点难做,是网页的那就好办. webform一点不了解。做软件和做网站不一样的。 winform程序怎么连接webservice服务器并调用其方法 请修改一下代码,统计最大值 winfrom 怎么出图表!!! 没有为请求类型“GET”找到 HTTP 处理程序。 求一个焦点式的广告图片代码 如何在后台代码实现gridview分页功能 序列化DataSet中时间格式问题 怎么动态的往DataTable里添加数据??? 55555没人教教我DropDownList绑定后的问题 吗?55555555 怎么将Console.ReadLine()得到的string中的\n转为换行? Winform程序中datagridview控件绑定数据后怎么内建添加行?? GDI+绘图打印标签问题
OpenFileDialog也要吧
Image也要吧
一些用来显示信息的也要吧
openSource.Filter = "所有影像文件 (*.ASF,*.MPEG-1,*.MPEG-2,*.WAV,*.AVI,*.MIDI,*.VOD,*.AU,*.MP3,*.MPG,*.wmv,*.rmvb,*.JPGE)|*.ASF;*.MPEG-1;*.MPEG-2;*.WAV;*.AVI;*.MIDI;*.VOD;*.AU;*.MP3;*.MPG;*.wmv;*.rmvb;*.jpg";
if (openSource.ShowDialog() == DialogResult.OK)
{
DirectoryInfo directory = new DirectoryInfo(openSource.FileName.Substring(0, openSource.FileName.LastIndexOf("\\")));
if (!Directory.Exists(存储图片路径+ "\\" + dgvBaoTao.CurrentRow.Cells["PackageName"].Value.ToString()))
{
Directory.CreateDirectory(存储图片路径 + "\\" + 图片名.jpg);
}
FileInfo[] diInfo = directory.GetFiles();
/// 以逆时针为方向对图像进行旋转
/// </summary>
/// <param name="b">位图流</param>
/// <param name="angle">旋转角度[0,360](前台给的)</param>
/// <returns></returns>
public Bitmap Rotate(Bitmap b, int angle)
{
angle = angle % 360; //弧度转换
double radian = angle * Math.PI / 180.0;
double cos = Math.Cos(radian);
double sin = Math.Sin(radian);
//原图的宽和高
int w = b.Width;
int h = b.Height;
int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
//目标位图
Bitmap dsImage = new Bitmap(W, H);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//计算偏移量
Point Offset = new Point((W - w) / 2, (H - h) / 2);
//构造图像显示区域:让图像的中心与窗口的中心点一致
Rectangle rect = new Rectangle(Offset.X, Offset.Y, w, h);
Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
g.TranslateTransform(center.X, center.Y);
g.RotateTransform(360 - angle);
//恢复图像在水平和垂直方向的平移
g.TranslateTransform(-center.X, -center.Y);
g.DrawImage(b, rect);
//重至绘图的所有变换
g.ResetTransform();
g.Save();
g.Dispose();
//dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
return dsImage;
}
MyAngle = 90; //MyAngle += 90; //if (MyAngle > 360) MyAngle = 90; pictureBox1.Image = Rotate(GetSourceImg(IMAGEFILE), MyAngle);
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Drawing.Drawing2D;namespace Silent.Web.Controllers.Common
{
/**//// <summary>
/// ASPJpegBase
/// Author : Jolly
/// </summary>
public class ASPJpegBase : IDisposable
{
/**//// <summary>
/// 会产生graphics异常的PixelFormat
/// </summary>
private static PixelFormat[] indexedPixelFormats = { PixelFormat.Undefined, PixelFormat.DontCare, PixelFormat.Format16bppArgb1555, PixelFormat.Format1bppIndexed, PixelFormat.Format4bppIndexed, PixelFormat.Format8bppIndexed }; /**//// <summary>
/// 图片宽度--生成缩略图时使用
/// </summary>
public int Width { get; set; }
/**//// <summary>
/// 图片高度--生成缩略图时使用
/// </summary>
public int Height { get; set; } /**//// <summary>
/// Bitmap对象
/// </summary>
public Bitmap CurrentBitmap
{
get { if (oCurrentImage == null) throw new NullReferenceException("CurrentBitmap is null!"); return oCurrentImage; }
} private Bitmap oCurrentImage; private ASPJpegEffect etASPJpegEffect; /**//// <summary>
/// 图片特效处理
/// </summary>
public ASPJpegEffect Effect
{
get
{
etASPJpegEffect = new ASPJpegEffect();
etASPJpegEffect.CurrentBitmap = this.CurrentBitmap;
return etASPJpegEffect;
}
} /**//// <summary>
/// 默认构造函数
/// </summary>
public ASPJpegBase()
{ } /**//// <summary>
/// 构造函数
/// </summary>
/// <param name="sImagePath">图片路径</param>
public ASPJpegBase(string sImagePath)
{
oCurrentImage = new Bitmap(sImagePath);
//如果原图片是索引像素格式之列的,则需要转换
if (IsPixelFormatIndexed(oCurrentImage.PixelFormat))
{
using(Bitmap bmp = new Bitmap(oCurrentImage.Width, oCurrentImage.Height, PixelFormat.Format32bppArgb))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.DrawImage(oCurrentImage, 0, 0);
}
oCurrentImage = (Bitmap)bmp.Clone();
}
}
} /**//// <summary>
/// 构造函数
/// </summary>
/// <param name="oImage">Image对象</param>
public ASPJpegBase(Image oImage)
{
oCurrentImage = new Bitmap(oImage);
} /**//// <summary>
/// 实例化Bitmap对象
/// </summary>
/// <param name="sImagePath">图片路径</param>
public void Open(string sImagePath)
{
oCurrentImage = new Bitmap(sImagePath);
} /**//// <summary>
/// 判断图片的PixelFormat 是否在 引发异常的 PixelFormat 之中
/// 无法从带有索引像素格式的图像创建graphics对象
/// </summary>
/// <param name="imgPixelFormat">原图片的PixelFormat</param>
/// <returns></returns>
private static bool IsPixelFormatIndexed(PixelFormat imgPixelFormat)
{
foreach (PixelFormat pf in indexedPixelFormats)
{
if (pf.Equals(imgPixelFormat)) return true;
} return false;
} /**//// <summary>
/// 添加文字水印
/// </summary>
/// <param name="text"></param>
/// <param name="p"></param>
/// <param name="fontcolor"></param>
/// <param name="font"></param>
public void DrawText(string sText, Font font, Color fontcolor, Point p, float rotate)
{
using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap))
{
if (rotate != 0)
graphics.RotateTransform(rotate);
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawString(sText, font, new SolidBrush(fontcolor), (float)p.X, (float)p.Y);
}
} /**//// <summary>
/// 添加文字水印-文字带背景
/// </summary>
/// <param name="text"></param>
/// <param name="p"></param>
/// <param name="fontcolor"></param>
/// <param name="font"></param>
public void DrawText(string sText, Font font, Color fontcolor, Point p, float rotate, string sImagePath)
{
TextureBrush tb = new TextureBrush(Image.FromFile(sImagePath));
using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap))
{
if (rotate != 0)
graphics.RotateTransform(rotate);
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawString(sText, font, tb, (float)p.X, (float)p.Y);
}
} /**//// <summary>
/// 绘制边框
/// </summary>
/// <param name="frameColor">边框颜色</param>
/// <param name="frameWidth">边框宽度</param>
public void DrawFrame(Color frameColor, int frameWidth)
{
double iNewframeWidth = (Convert.ToDouble(frameWidth) / Convert.ToDouble(2));
using (Bitmap newBitmap = new Bitmap(this.CurrentBitmap.Width + (2 * frameWidth), this.CurrentBitmap.Height + (2 * frameWidth)))
{
using (Graphics graphics = Graphics.FromImage(newBitmap))
{
graphics.Clear(Color.White);
Pen pen = new Pen(frameColor, frameWidth);
graphics.DrawRectangle(pen, (float)iNewframeWidth, (float)iNewframeWidth, newBitmap.Width - frameWidth, newBitmap.Height - frameWidth);
graphics.DrawImage(this.CurrentBitmap, new Rectangle(frameWidth, frameWidth,this.CurrentBitmap.Width,this.CurrentBitmap.Height)); this.oCurrentImage = ((Bitmap)newBitmap.Clone());
}
}
} /**//// <summary>
/// 绘制3D边框
/// </summary>
/// <param name="frameColor">边框颜色</param>
/// <param name="frameWidth">边框宽度</param>
public void Draw3DFrame(Color frameColor, int frameWidth)
{
double iNewframeWidth = (Convert.ToDouble(frameWidth) / Convert.ToDouble(2));
using (Bitmap newBitmap = new Bitmap(this.CurrentBitmap.Width + (2 * frameWidth), this.CurrentBitmap.Height + (2 * frameWidth)))
{
using (Graphics graphics = Graphics.FromImage(newBitmap))
{
graphics.Clear(Color.White);
Pen pen = new Pen(frameColor, (float)iNewframeWidth);
Pen pen1 = new Pen(Color.FromArgb(frameColor.ToArgb() - 10), (float)iNewframeWidth);
graphics.DrawRectangle(pen, (float)iNewframeWidth / 2, (float)iNewframeWidth / 2, newBitmap.Width - (float)iNewframeWidth, newBitmap.Height - (float)iNewframeWidth);
graphics.DrawRectangle(pen1, 3 * (float)iNewframeWidth / 2, 3 * (float)iNewframeWidth / 2, newBitmap.Width - 3 * (float)iNewframeWidth, newBitmap.Height - 3 * (float)iNewframeWidth); graphics.DrawImage(this.CurrentBitmap, 2 * (float)iNewframeWidth, 2 * (float)iNewframeWidth, (float)this.CurrentBitmap.Width, (float)this.CurrentBitmap.Height); this.oCurrentImage = (Bitmap)newBitmap.Clone();
}
}
} /**//// <summary>
/// 图片切割功能
/// </summary>
/// <param name="left">left</param>
/// <param name="top">top</param>
/// <param name="right">right</param>
/// <param name="bottom">bottom</param>
public void Crop(int left, int top, int right, int bottom)
{
int num;
int num2;
if ((this.CurrentBitmap.Width - left) < right)
{
num = this.CurrentBitmap.Width - right;
}
else
{
num = right;
}
if ((this.CurrentBitmap.Height - top) < bottom)
{
num2 = this.CurrentBitmap.Height - top;
}
else
{
num2 = bottom;
}
using (Bitmap image = new Bitmap(num, num2))
{
image.SetResolution(this.CurrentBitmap.HorizontalResolution, this.CurrentBitmap.VerticalResolution);
using (Graphics graphics = Graphics.FromImage(image))
{
graphics.Clear(Color.White);
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(this.CurrentBitmap, new Rectangle(0, 0, num, num2), new Rectangle(left, top, num, num2), GraphicsUnit.Pixel);
oCurrentImage = (Bitmap)image.Clone();
}
}
}
/**//// <summary>
/// 图片移动
/// </summary>
/// <param name="lefttopx"></param>
/// <param name="lefttopy"></param>
/// <param name="rightbottomx"></param>
/// <param name="rightbottomy"></param>
/// <param name="tox"></param>
/// <param name="toy"></param>
public void Move(int lefttopx, int lefttopy, int rightbottomx, int rightbottomy, int tox, int toy)
{
using (Bitmap image = this.Copy(lefttopx, lefttopy, rightbottomx, rightbottomy))
{
Rectangle rect = GetRectangle(lefttopx, lefttopy, rightbottomx, rightbottomy);
using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap))
{
graphics.Clear(Color.White);
graphics.FillRectangle(new SolidBrush(Color.White), rect);
graphics.DrawImage(image, tox, toy);
oCurrentImage = (Bitmap)image.Clone();
}
}
} /**//// <summary>
/// 调整图片大小
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
public void ResizeTo(int width, int height)
{
this.oCurrentImage = new Bitmap(this.CurrentBitmap, width, height);
} /**//// <summary>
/// 生成缩略图
/// </summary>
public void CreateThumbnail(int iWidth, int iHeight)
{
//用指定的大小和格式初始化 Bitmap 类的新实例
using (Bitmap bitmap = (Bitmap)oCurrentImage.Clone())
{
ResizeTo(iWidth, iHeight);
//在指定位置并且按指定大小绘制 原图片 对象
Graphics.FromImage(oCurrentImage).DrawImage(bitmap, new Rectangle(0, 0, iWidth, iHeight));
}
} /**//// <summary>
/// 生成缩略图
/// </summary>
/// <param name="sThumbnailPath">缩略图保存路径</param>
public void CreateThumbnail(string sThumbnailPath)
{
if (Width > 0 && Height > 0 && (Width < oCurrentImage.Width || Height < oCurrentImage.Height))
{
int width = Width;
int height = Height;
double factor = 1; if (oCurrentImage.Width > oCurrentImage.Height)
{
factor = Convert.ToDouble(width) / Convert.ToDouble(oCurrentImage.Width);
height = Convert.ToInt32(oCurrentImage.Height * factor);
}
else
{
factor = Convert.ToDouble(height) / Convert.ToDouble(oCurrentImage.Height);
width = Convert.ToInt32(oCurrentImage.Width * factor);
}
//用指定的大小和格式初始化 Bitmap 类的新实例
Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
//从指定的 Image 对象创建新 Graphics 对象
Graphics graphics = Graphics.FromImage(bitmap);
//清除整个绘图面并以透明背景色填充
graphics.Clear(Color.Transparent);
//在指定位置并且按指定大小绘制 原图片 对象
graphics.DrawImage(oCurrentImage, new Rectangle(0, 0, width, height));
try
{
bitmap.Save(sThumbnailPath);
}
catch (System.Exception e)
{
throw e;
}
finally
{
bitmap.Dispose();
graphics.Dispose();
}
}
} /**//// <summary>
/// 图片垂直翻转
/// </summary>
public void FlipV()
{
this.CurrentBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
} /**//// <summary>
/// 图片水平翻转
/// </summary>
public void FlipH()
{
this.CurrentBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
} /**//// <summary>
/// 图片旋转
/// </summary>
/// <param name="angle">旋转度数</param>
public void Rotate(int angle)
{
angle = angle % 360;
if (angle < 0)
{
angle += 360;
}
if (angle >= 270)
{
this.CurrentBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
angle -= 270;
}
else if (angle >= 180)
{
this.CurrentBitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
angle -= 180;
}
else if (angle >= 90)
{
this.CurrentBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
angle -= 90;
}
if (angle > 0)
{
double a = (angle * 3.1415926535897931) / 180.0;
int width = Convert.ToInt32((double)((this.CurrentBitmap.Height * Math.Sin(a)) + (this.CurrentBitmap.Width * Math.Cos(a))));
int height = Convert.ToInt32((double)((this.CurrentBitmap.Width * Math.Sin(a)) + (this.CurrentBitmap.Height * Math.Cos(a))));
Bitmap image = new Bitmap(width, height * 2);
image.SetResolution(this.CurrentBitmap.HorizontalResolution, this.CurrentBitmap.VerticalResolution);
Graphics graphics = Graphics.FromImage(image);
graphics.Clear(Color.White);
Matrix matrix = new Matrix(1f, 0f, 0f, -1f, 0f, 0f);
matrix.Translate(0f, (float)this.CurrentBitmap.Height, MatrixOrder.Append);
graphics.Transform = matrix;
Matrix matrix2 = new Matrix();
matrix2.RotateAt((float)-angle, (PointF)new Point(0, 0), MatrixOrder.Append);
matrix2.Translate(0f, 0f, MatrixOrder.Append);
GraphicsPath path = new GraphicsPath();
Point[] points = new Point[] { new Point(0, this.CurrentBitmap.Height), new Point(this.CurrentBitmap.Width, this.CurrentBitmap.Height), new Point(0, 0) };
path.AddPolygon(points);
path.Transform(matrix2);
PointF[] pathPoints = path.PathPoints;
graphics.DrawImage(this.CurrentBitmap, pathPoints);
graphics.ResetTransform();
int num4 = this.CurrentBitmap.Height;
this.oCurrentImage = new Bitmap(width, height);
this.CurrentBitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (Graphics newGraphics = Graphics.FromImage(this.CurrentBitmap))
{
newGraphics.Clear(Color.White);
newGraphics.DrawImage(image, new Rectangle(0, 0, width, height), new Rectangle(0, Convert.ToInt32((double)(num4 * (1.0 - Math.Cos(a)))), width, height), GraphicsUnit.Pixel);
image.Dispose();
graphics.Dispose();
path.Dispose();
}
}
} /**//// <summary>
/// 画弧形
/// </summary>
/// <param name="r"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
/// <param name="startangle"></param>
/// <param name="sweepAngle"></param>
public void DrawArc(Rectangle r, int linewidth, Color linecolor, float startangle, float sweepAngle)
{
using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap))
{
Pen pen = new Pen(linecolor, (float)linewidth);
graphics.DrawArc(pen, r, startangle, sweepAngle);
}
} /**//// <summary>
/// 画椭圆
/// </summary>
/// <param name="r"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
/// <param name="fillcolor"></param>
public void DrawEllipse(Rectangle r, int linewidth, Color linecolor, Color fillcolor)
{
using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap))
{
Pen pen = new Pen(linecolor, (float)linewidth);
graphics.DrawEllipse(pen, r);
if (fillcolor != Color.Empty)
{
graphics.FillEllipse(new SolidBrush(fillcolor), r);
}
}
} /**//// <summary>
/// 画椭圆
/// </summary>
/// <param name="lefttop"></param>
/// <param name="rightbottom"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
/// <param name="fillcolor"></param>
public void DrawEllipse(Point lefttop, Point rightbottom, int linewidth, Color linecolor, Color fillcolor)
{
this.DrawEllipse(new Rectangle(lefttop.X, lefttop.Y, rightbottom.X - lefttop.X, rightbottom.Y - lefttop.Y), linewidth, linecolor, fillcolor);
}
/**//// <summary>
/// 画椭圆
/// </summary>
/// <param name="lefttopx"></param>
/// <param name="lefttopy"></param>
/// <param name="rightbottomx"></param>
/// <param name="rightbottomy"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
/// <param name="fillcolor"></param>
public void DrawEllipse(int lefttopx, int lefttopy, int rightbottomx, int rightbottomy, int linewidth, Color linecolor, Color fillcolor)
{
this.DrawEllipse(new Rectangle(lefttopx, lefttopy, rightbottomx - lefttopx, rightbottomy - lefttopy), linewidth, linecolor, fillcolor);
} /**//// <summary>
/// 画图上图
/// </summary>
/// <param name="img"></param>
/// <param name="r"></param>
public void DrawImage(System.Drawing.Image img, Rectangle r)
{
Graphics.FromImage(this.CurrentBitmap).DrawImage(img, r);
} /**//// <summary>
/// 画线
/// </summary>
/// <param name="pFrom"></param>
/// <param name="pTo"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
public void DrawLine(Point pFrom, Point pTo, int linewidth, Color linecolor)
{
using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap))
{
Pen pen = new Pen(linecolor, (float)linewidth);
graphics.DrawLine(pen, pFrom, pTo);
}
} /**//// <summary>
/// 画线
/// </summary>
/// <param name="fromx"></param>
/// <param name="fromy"></param>
/// <param name="tox"></param>
/// <param name="toy"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
public void DrawLine(int fromx, int fromy, int tox, int toy, int linewidth, Color linecolor)
{
this.DrawLine(new Point(fromx, fromy), new Point(tox, toy), linewidth, linecolor);
} /**//// <summary>
/// 画多条线
/// </summary>
/// <param name="points"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
public void DrawLines(Point[] points, int linewidth, Color linecolor)
{
using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap))
{
Pen pen = new Pen(linecolor, (float)linewidth);
graphics.DrawLines(pen, points);
}
} /**//// <summary>
/// 画长方形
/// </summary>
/// <param name="r"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
/// <param name="fillcolor"></param>
public void DrawRectangle(Rectangle r, int linewidth, Color linecolor, Color fillcolor)
{
using (Graphics graphics = Graphics.FromImage(this.CurrentBitmap))
{
Pen pen = new Pen(linecolor, (float)linewidth);
graphics.DrawRectangle(pen, r);
if (fillcolor != Color.Empty)
{
graphics.FillRectangle(new SolidBrush(fillcolor), r);
}
}
} /**//// <summary>
/// 画长方形
/// </summary>
/// <param name="lefttop"></param>
/// <param name="rightbottom"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
/// <param name="fillcolor"></param>
public void DrawRectangle(Point lefttop, Point rightbottom, int linewidth, Color linecolor, Color fillcolor)
{
this.DrawRectangle(new Rectangle(lefttop.X, lefttop.Y, rightbottom.X - lefttop.X, rightbottom.Y - lefttop.Y), linewidth, linecolor, fillcolor);
} /**//// <summary>
/// 画长方形
/// </summary>
/// <param name="lefttopx"></param>
/// <param name="lefttopy"></param>
/// <param name="rightbottomx"></param>
/// <param name="rightbottomy"></param>
/// <param name="linewidth"></param>
/// <param name="linecolor"></param>
/// <param name="fillcolor"></param>
public void DrawRectangle(int lefttopx, int lefttopy, int rightbottomx, int rightbottomy, int linewidth, Color linecolor, Color fillcolor)
{
this.DrawRectangle(GetRectangle(lefttopx, lefttopy, rightbottomx, rightbottomy), linewidth, linecolor, fillcolor);
} /**//// <summary>
/// 保存图片到内存中
/// </summary>
/// <param name="mms"></param>
/// <param name="RawFormat"></param>
public void Save(MemoryStream mms, ImageFormat RawFormat)
{
this.CurrentBitmap.Save(mms, RawFormat);
} /**//// <summary>
/// 保存图片到文件流中
/// </summary>
/// <param name="mms"></param>
/// <param name="RawFormat"></param>
public void Save(Stream mms, ImageFormat RawFormat)
{
this.CurrentBitmap.Save(mms, RawFormat);
} /**//// <summary>
/// 保存为Gif图片
/// </summary>
/// <param name="sSavePath"></param>
public void SaveGif(string sSavePath)
{
this.CurrentBitmap.Save(sSavePath, ImageFormat.Gif);
} /**//// <summary>
/// 保存为jpg图片
/// </summary>
/// <param name="sSavePath"></param>
/// <param name="iQuantity">图片质量</param>
public void SaveJpeg(string sSavePath, int iQuantity)
{
ImageCodecInfo encoderInfo = GetEncoderInfo("image/jpeg");
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams = new EncoderParameters();
encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)iQuantity); this.CurrentBitmap.Save(sSavePath, encoderInfo, encoderParams);
encoderParams.Dispose();
}