我正在使用 WIA 2.0 从 HP 扫描仪扫描图像。问题是保存的 TIFF 大约 9MB 大(300dpi 的 A4 页面,灰度)。我将包含 TIFF 格式扫描的 WIA 的 ImageFile 转换为 BitmapSource,如下所示:
public static BitmapSource ConvertScannedImage(ImageFile imageFile)
{
if (imageFile == null)
return null;
// save the image out to a temp file
string fileName = Path.GetTempFileName();
// this is pretty hokey, but since SaveFile won't overwrite, we
// need to do something to both guarantee a unique name and
// also allow SaveFile to write the file
File.Delete(fileName);
// now save using the same filename
imageFile.SaveFile(fileName);
BitmapFrame img;
// load the file back in to a WPF type, this is just
// to get around size issues with large scans
using (FileStream stream = File.OpenRead(fileName))
{
img = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
stream.Close();
}
// clean up
File.Delete(fileName);
return img;
}
任何人都知道如何减小图像大小,如果可能的话在内存中(因为我有很多可以预览和旋转的扫描)?谢谢。