2
私はWIA 2.0を使用してHPスキャナから画像をスキャンしています。問題は、保存されたTIFFが約9MBもの大きさであることです(A4ページ、300dpi、グレースケール)。私はあなたがプレビューすることができますスキャンのlsitを持っているので、WPFアプリケーションでのWIAスキャン
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;
}
誰もが(メモリ内可能であれば、画像サイズを小さくする方法のアイデアを持っている:私はこのようなたBitmapSourceにTIFF形式でスキャン含まWIAの画像ファイルを変換します回転する)?ありがとう。
と.Imageの実装を書き込みます処理中にストリームは自動的に閉じられます。 – Clemens