How to do below using JMagick API:
Resampling Image
(ImageMagick Command) Convert -units pixelsperinch <input file> -resample 300x300
`
in API I could not find anything related to change dpi per pixels.
Flatten Image Layers:
(ImageMagick Command)Convert <inputfile withlayers> -layers merge <outputfile >
Please suggest.
-resample
and-layers
options.The only thing in JMagick's API docs that resembles any of those options is the method
sampleImage
in classMagickImage
. However, that operates only in pixels. There is indeed asetUnits
method that allows you to change the units declared in the header of the image file. But that's about it. It doesn't modify the image itself. And there seems to be no connection between thesampleImage
andsetUnits
methods.There is some code out there to resample an image using "manual" calculations. The following snippet is based on the one available here:
I'd suggest you try im4java instead. From the website:
So, whatever command option ImageMagick has, im4java should have a method for it. I've had a quick look at the API and there is indeed a
resample
and alayers
method. Using them, your code would look something like this (based on example from here):Hope this helps!