2009-04-24 74 views

回答

42

這應做到:

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; 
+0

乾杯我給thiis一個很好的讓你知道我怎麼去。 – vdhant 2009-04-24 11:30:26

+0

作品,謝謝。 – 2009-04-29 01:09:51

17

繼果汁先生的建議,下面是一些可供選擇的代碼,避免鎖映像文件:

using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) 
{ 
    var bitmapFrame = BitmapFrame.Create(stream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None); 
    var width = bitmapFrame.PixelWidth; 
    var height = bitmapFrame.PixelHeight; 
}