- 第三方类库:
Magick.NET-Q8-AnyCPU.dll、Magick.NET.Core.dll
DLL下载
using ImageMagick;
{//指定路径图片缩略图显示
MagickImage img = new MagickImage(filePath);
img.Scale(this.imageList1.ImageSize.Width, imageList1.ImageSize.Height);//按宽高取图
Stream st = new MemoryStream();
img.Write(st);//输出到内存
Image img2 = new Bitmap(st);
imageList1.Images.Add(img2);
}
{//pictureBox1图片读到内存 → 通过MagickImage输出到本地
MemoryStream mstr = new MemoryStream(); //创建新的MemoryStream
pictureBox1.Image.Save(mstr, ImageFormat.Jpeg);// 保存对象到内存
MagickImage image = new MagickImage(mstr.ToArray(), MagickFormat.Jpeg);
var arr = txtImgSize.Text.Trim().Replace(",", " ").Replace(",", " ").Split(' ');
image.Scale(int.Parse(arr[0]), int.Parse(arr[1]));//缩放
MemoryStream mstr2 = new MemoryStream(); //创建新的MemoryStream
image.Write(mstr2);
image.Dispose();
}
{//无损压缩
MagickImage image = new MagickImage(filePath);
image.Quality = 100;//无损压缩
Percentage percentage = new Percentage(50);
image.Resize(percentage);//调大小 按px值
//image.Scale(width, height);//缩放 字不清楚较严重
image.Write(FilePath);//输出到磁盘
image.Dispose();
}