Today I tried to reuse the image splitting feature in my program ShrinkerImages. Only with a single image, namely a photo from my Lumia 435. However, it was the first time I actually came across an image with a lower DPI than the usual 96. If an image has a DPI other than 96 (I have tested this only with a lower one), then BitmapImage, for example, returns the size of the image like this: actual width in px * 96 / the image’s DpiX. The same goes for the height. I had code that cropped the image, and now I know it is a good idea to check the DPI and set a different size if needed. It will not affect, for example, the size in px of the resulting image.
C#
//-bitmapImage is the image to crop, point is the point the crop starts from, size is the size of the cropped area
if (bitmapImage.DpiX != 96)
{
size.Width /= 96d;
size.Width *= bitmapImage.DpiX;
point.X /= 96d;
point.X *= bitmapImage.DpiX;
}
if (bitmapImage.DpiY != 96)
{
size.Height /= 96d;
size.Height *= bitmapImage.DpiY;
point.Y /= 96d;
point.Y *= bitmapImage.DpiY;
}
//-The crop operation itself
return BitmapFrame.Create( new CroppedBitmap(bitmapImage, new Int32Rect((int)point.X, (int)point.Y, (int)size.Width, (int)size.Height)));