Pixel size of ImageSource Pixel size of ImageSource wpf wpf

Pixel size of ImageSource


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


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


You have to multiply the value with Windows's DPI resolution in order to obtain the amount of physical pixels. One way to get the DPI resolution is to get hold of a Graphics object and read its DpiX and DpiY properties.