Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pixel size of ImageSource

Tags:

c#

image

wpf

How can I determine the size of an ImageSource in pixels? The ImageSource object has a Height and a Width property, but they return the size in 1/96 inches..

like image 913
eWolf Avatar asked Jul 18 '09 09:07

eWolf


2 Answers

Super old post, but for anyone else having problems with this, you don't have to do anything crazy or complicated.

(ImageSource.Source as BitmapSource).PixelWidth
(ImageSource.Source as BitmapSource).PixelHeight
like image 112
Mutex Avatar answered Sep 22 '22 08:09

Mutex


There are 2 types of ImageSource: DrawingImage and BitmapSource.

Obviously, DrawingImage does not have DPI or pixel width, because it's essentially vector graphic.

On other side, BitmapSource has PixeWidth/PixelHeight and also DpiX/DpiY.

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.pixelheight.aspx

like image 42
Oleg Mihailik Avatar answered Sep 26 '22 08:09

Oleg Mihailik