2
我使用WIA 2.0掃描HP掃描儀的圖像。問題是保存的TIFF大約9MBs(A4紙,300dpi,灰度)。我轉換包含在TIFF格式掃描WIA的鏡像文件到的BitmapSource這樣的:WIA掃描WPF應用程序
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;
}
任何人有一個想法如何縮小圖像尺寸,如果可能的話在內存中(因爲我有掃描的lsit,你可以預覽和旋轉)?謝謝。
BTW沒有必要關閉使用塊內的流,因爲處理期間流自動關閉。 – Clemens