【发布时间】:2019-04-26 21:23:16
【问题描述】:
我刚刚发现 TIFF 有几种格式。使用时出于某种原因
Using bm As New Bitmap(rect.Width, rect.Width)
bm.Save("C:\testfolder\screenshot.png", Imaging.ImageFormat.Tiff)
格式变成了LZW压缩的,我不能在第三方库中使用。
经过一番搜索,我发现 .NET 确实提供了一个库来保存为具有不同压缩选项的 TIFF,我想尝试所有这些,但我不知道如何实现它。或者我应该说我没有弄清楚如何使用它:
目的是我想得到一个区域截图并保存为TIFF。
Dim stream As New FileStream("new.tif", FileMode.Create)
Dim encoder As New TiffBitmapEncoder()
encoder.Compression = TiffCompressOption.Zip
encoder.Frames.Add(BitmapFrame.Create(image)) <--what is this "image"?
encoder.Save(stream)
image 实体是什么?流?如何将截取的屏幕截图区域保存为 TIFF?
如果
Using bm As New Bitmap(rect.Width, rect.Width)
我不介意先保存它然后只重新读取 bmp 流。唯一的问题是我不知道示例中给出的“图像”代表什么。
我从这里阅读了一些信息,但我仍然没有弄清楚: https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.bitmapframe.create?view=netframework-4.8
如果你想通了,请给我一个如何使用代码的例子。
【问题讨论】:
-
bm 上面是 System.Drawing.Bitmap 而“图像”是 System.Windows.Media.Imaging.WriteableBitMap 我不知道如何实现它
-
据记录,
System.Windows命名空间下的大多数成员(System.Windows.Forms除外)是 WPF(不同的 GUI 框架)的一部分,通常不用于 WinForms。
标签: c# vb.net screenshot tiff