Search

Atalasoft Knowledge Base

FAQ: How can I scale the size of an Image?

Administrator
DotImage

ResampleCommand (Any Pixel Format)

The ResampleCommand has a few different constructors .. including ones that take a single int (for "resample longest size to this number of pixels)

// resample image so the long side is 1000 pixels, keeping existing aspect ratio
ResampleCommand cmd = new ResampleCommand(1000);
AtalaImage resampledImg = cmd.Apply(origAtalaImageToResample).Image;
origAtalaImageToResample.Dispose();

// resample image to exact size
ResampleCommand cmd = new ResampleCommand(new Size(widthInPixels, heightInPiels));
AtalaImage resampledImg = cmd.Apply(origAtalaImageToResample).Image;
origAtalaImageToResample.Dispose();

ResampleDocumentCommand (Bitonal Images Only)

DotImage only provides a ResampleDocumentCommand that will resample to a specified width and height, but what if you only want to specify one dimension and keep the ratio the same? This is not that difficult, simply make an equation ...

w/h = newW/newH

and solve for which ever dimension you do not want to pick, for example I want to pick the width,

newH = (h/w)*newW

Now just plug in the value that you picked for the new Width, the old values for width and height and get out the scaled Height. Now you can use the ResampleDocumentCommand with a perfectly scaled size.

Original Article:
Q10126 - FAQ: How can I scale the size of an Image?

Details
Last Modified: 6 Years Ago
Last Modified By: Administrator
Type: INFO
Rated 5 stars based on 1 vote
Article has been viewed 2.2K times.
Options
Also In This Category