我需要在控件中显示高分辨率图像的预览缩略图,以供用户选择。我目前使用ImageListView加载图像。这对于低至中分辨率的图像效果很好。但是,在显示非常高分辨率的图像的缩略图时会出现明显的延迟。可以从https://drive.google.com/open?id=1Qgu_aVXBiMlbHluJFU4fBvmFC45-下载示例图像E81C
图像大小约为5000x3000像素,大小约为12 MB。可以通过使用此图像的1000份副本来复制此问题。
问题屏幕截图在此处上传
https://giphy.com/gifs/ZEH3T3JTfN42OL3J1A
使用后台工作程序加载图像
foreach (var f in filepaths)
{
imageListView1.Items.Add(f);
}
Run Code Online (Sandbox Code Playgroud)
1.为了解决此问题,我尝试调整高分辨率图像的大小并将调整大小后的图像添加到ImageListView ...中,但是要进行重新调整大小会浪费大量时间,并且缩略图生成速度很慢。
Bitmap x = UpdatedResizeImage2(new Bitmap(f), new Size(1000, 1000));
string q = Path.GetTempPath() + Path.GetFileName(f);
x.Save(Path.GetTempPath() + Path.GetFileName(f));
x.Dispose();
imageListView1.Items.Add(Path.GetTempPath() + Path.GetFileName(f));
Run Code Online (Sandbox Code Playgroud)
2.我也尝试过Image.CreateThumbnail方法,但这也很慢。
有没有更好的方法来解决此问题?
我知道WPF允许你使用需要WIC编解码器查看的图像(为了争论,比如数码相机RAW文件); 但是我只能看到它可以让你本地显示图像,但我无法看到获取元数据(例如,曝光时间).
显然可以这样做,因为Windows资源管理器显示它,但这是通过.net API公开的,或者你认为它只是调用本机COM接口
好的,我试过这个:
TransformedBitmap tbm = new TransformedBitmap(myBitmapSource, new RotateTransform(angle));
return tbm;
Run Code Online (Sandbox Code Playgroud)
但这不适用于 90 度倍数以外的角度。
新我尝试使用 RenderTargetBitmap:
var image = new Canvas();
image.Width = myBitmapSource.PixelWidth;
image.Height = myBitmapSource.PixelHeight;
image.Background = new ImageBrush(myBitmapSource);
image.RenderTransform = new RotateTransform(angle);
RenderTargetBitmap rtb = new RenderTargetBitmap(myBitmapSource.PixelWidth, myBitmapSource.PixelHeight, myBitmapSource.DpiX, myBitmapSource.DpiY, myBitmapSource.Format);
rtb.Render(image);
return rtb;
Run Code Online (Sandbox Code Playgroud)
但这给了我:
"The calling thread must be STA, because many UI components require this."
Run Code Online (Sandbox Code Playgroud)
这在没有 GUI 的服务中运行。
有人可以给我一个关于如何以任何角度旋转 WPF(没有 GUI)中的 BitmapSource 的工作代码示例吗?
更新:
投票功能请求:http : //visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/10870098-allow-rotation-of-bitmapsource-by-any-angle