使用WPF图像类 - 在不读取整个文件的情况下获取图像尺寸 [英] Using WPF Imaging classes - Getting image dimensions without reading the entire file

查看:602
本文介绍了使用WPF图像类 - 在不读取整个文件的情况下获取图像尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接这篇文章我希望能够读取一个图像文件的高度和宽度,而不必将整个文件读入内存。

在Frank Krueger的文章中提到了一些WPF图像类的做法。任何想法如何做到这一点?

解决方案



  var bitmapFrame = BitmapFrame.Create(new Uri(@C:\ Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter .jpg),BitmapCreateOptions.DelayCreation,BitmapCacheOption.None); 
var width = bitmapFrame.PixelWidth;
var height = bitmapFrame.PixelHeight;


Link this post I want to be able to read an image files height and width without reading in the whole file into memory.

In the post Frank Krueger mentions there is a way of doing this with some WPF Imaging classes. Any idea on how to do this??

解决方案

This should do it:

var bitmapFrame = BitmapFrame.Create(new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg"), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
var width = bitmapFrame.PixelWidth;
var height = bitmapFrame.PixelHeight;

这篇关于使用WPF图像类 - 在不读取整个文件的情况下获取图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆