Thank you very much Ryan. What I am trying is to allow zooming and render only the visible part. However, when I scale it, I am not getting the correct part.
In other part of my code, I change the scale of the pdf when the screen is zoomed:
And later, I have the "render" method. I have one question. If draw.setImageSize sets the size of the resulting image, is the cropbox resized to fit the image size?
I used setImageSize because it had a better behaviour at the beginning, but obviusly I have a problem in the cropbox or in the image size.
And "getMyCropBox()" is the method that calculates my cropbox, which maybe I have to redefine.
Actually, I already have a code that works for non-transparent pdfs, so what I am trying to get, is the same code for a transparent pdf:
// mTile has my image properties
Matrix2D matrix = page.getDefaultMatrix(true, 0, 0);
mRasterizer.rasterize(page, // Pagina
And I expect my result stored in mPixels, so in the transparent case, I also do:
bitmap.getPixels(mPixels,0,width, 0, 0 ,width,height);
Which seems to work correctly.
Thank you very much!
El viernes, 7 de abril de 2017, 2:32:27 (UTC+2), Ryan escribió:
What does getMyCropBox do?
You should modify the existing crop box, and not just set a new one. In particular, the crop box might have a displacement, which effectively moves the origin.
As for the bitmap size, that depends on if you use SetDPI or SetImageSize.
Since you set ImageSize, then that is the final size you get, meaning the DPI is variable. The DPI is calculated to fit the CropBox into the image.
If you use SetDPI, then the final image size is variable. Where PDF coordinates are in 1/72 inch. So standard 8.5"x11" page, is 612, 792 units, so with a DPI of 96, you would get an image 586x1056.
You are also turning off preserving aspect ratio in the call to SetImageSize.
What output are you trying to achieve exactly? The more I know of your requirements, the easier I can provide you with the best answer.
If your objective is to draw part of the page, and you are targeting a certain image size, say 1024x1024, then the following is what you would do.
// calculate your crop box, but based on the original crop box. Also, note that pages can be rotated, so you what you see on screen might not be how the page is defined. That is for a 90 degree page rotation, if you see a portaite page, then actually the page is landscaped. page.setCroptBox(new_crop_box); draw.setImageSize(1024, 1024, true); draw.getBitmap();
Note that since aspect ratio was to to true, the long side of the image will be 1024px, but the short side will be less.