Using WPF Imaging classes - Getting image dimensions without reading the entire file

前端 未结 2 1407
暗喜
暗喜 2021-01-31 05:12

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

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 05:46

    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;
    

提交回复
热议问题