Background
At times, you may run into an image which has a "non-square" resolution - an
image where the resolution of the X (width) axis of the image differs from the
resolution of the Y (height) axis
The most common cause for such an image is that many older fax systems used
to use a resolution of 204 DPI for the width but 196 DPI for the height.
Such images appear normal when viewed in the original orientation, but if
rotated or opened in one of our viewers, these types of images often cause
unwanted effects - distortion of an image when rotated or annotations that
completely fail to line up / appear as intended.
NOTE: if you would like a means of detecting and fixing all
such images in a multipage TIFF File please see
HOWTO: Use TiffFile to Resample FAX images with Unequal Resolutions in a Multi-Page TIFF
Example Code
// Given the incoming AtalaImage, this method will determine if the resolution is non-square
//
// if it is not, the original image object is returned by reference
//
// if it is, then the original image is resampled into a new image, disposed of and a
// totally new image representing the corrected square-resolution version of the original
// is returned.
private static AtalaImage FixNonSquareResolution(AtalaImage img)
{
AtalaImage returnImg = null;
if ((int)Math.Floor(img.Resolution.X) != (int)Math.Floor(img.Resolution.Y))
{
// Do nothing:
return img;
}
else
{
Size newSize = Size.Empty;
ResampleCommand resamp = new ResampleCommand();
Dpi newRes;
// non square
if (img.Resolution.X > img.Resolution.Y)
{
// most common: width stays the same, height gets recalculated
newSize = new Size(img.Width, (int)((img.Height / img.Resolution.Y) * img.Resolution.X));
newRes = new Dpi(img.Resolution.X, img.Resolution.X, img.Resolution.Units);
}
else
{
// should almost never see this
newSize = new Size((int)((img.Width / img.Resolution.X) * img.Resolution.Y), img.Height);
newRes = new Dpi(img.Resolution.Y, img.Resolution.Y, img.Resolution.Units);
}
resamp.DestSize = newSize;
returnImg = resamp.Apply(img).Image;
returnImg.Resolution = newRes;
// clean up - returnImg is a full new image - NOT a reference to img - so dispose img now that we're done
img.Dispose();
return returnImg;
}
}
Original Article
Q10425 - HOWTO: Fix Non-square Resolution of a Single AtalaImage
Last Update
2026-11-06 - TD - (Fixed outdated link)