logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
cyberchen Posted: Wednesday, January 2, 2019 10:44:13 AM(UTC)
 
Originally Posted by: Paul Rayman Go to Quoted Post
(bitmap.Image as Bitmap).SetResolution(...)


W0rks! Thank you :)
Paul Rayman Posted: Tuesday, January 1, 2019 3:20:29 AM(UTC)
 
Code:

(bitmap.Image as Bitmap).SetResolution(...)

cyberchen Posted: Tuesday, January 1, 2019 3:16:09 AM(UTC)
 
Originally Posted by: Paul Rayman Go to Quoted Post
Try bitmap.Image.SetResolution before saving.

This is not supported by pdfBitmap :(
Paul Rayman Posted: Monday, December 31, 2018 4:54:58 PM(UTC)
 
Try bitmap.Image.SetResolution before saving.
cyberchen Posted: Monday, December 31, 2018 5:15:53 AM(UTC)
 
Ok, then the right calculation would be:

Code:


int dpi = 300; // DPI 
int targetWidth = (int)(page.Width / 72 * dpi);
int targetHeight = (int)(page.Height / 72 * dpi);



but the rendered Tiff is still 96dpi and the Filesize is far to small.

... can you maybe provide alternative code snipped to render something real?

For example:

I use this Code to Render a A3 at 300DPI.

Code:

int dpi = 300;
int targetWidth = (int)(page.Width / 72 * dpi);
int targetHeight = (int)(page.Height / 72 * dpi);

using (var bitmap = new PdfBitmap(targetWidth, targetHeight, true))
                                {
                                    //Fill background
                                    bitmap.FillRect(0, 0, targetWidth, targetHeight, Color.White);
                                    //Render contents in a page to a drawing surface specified by a coordinate pair, a width, and a height.
                                    page.Render(bitmap, 0, 0, targetWidth, targetHeight,
                                        Patagames.Pdf.Enums.PageRotate.Normal,
                                        Patagames.Pdf.Enums.RenderFlags.FPDF_ANNOT);


                                    bitmap.Image.Save(temppath + filename, System.Drawing.Imaging.ImageFormat.Tiff);

                                }


What i get is a TIFF with 3508 x 4961 Pixels (A3 @ 300dpi, thats good..). But the Filesize is only 1.2 Mb. But it should be around 50Mb.

This is stsrting to driving me crazy....
Paul Rayman Posted: Sunday, December 30, 2018 5:41:47 PM(UTC)
 
The DPI (the dots per inch) does not work that way. When we talking about the raster images, the DPI does not make any sense without a target device.

Inside the PDF all coordinates are given in points. One point has a fixed size - 1/72 of an inch.

Rendering is always in pixels. Pixels have a certain size which depends on the device (monitor for example). Typically it is 1/96 of an inch.
Therefore, the calculation of the image size in pixels in your code is made according to the formula

Code:
int targetWidth = (int)(page.Width / 72 * dpi );
int targetHeight = (int)(page.Height / 72 * dpi );


For example, if dpi is equal to monitor DPI (96), then you receive the true size of the document on this monitor.

The bitmap.SetResolution simply writes the DPI values (horizontal and vertical) inside the image metadata. Due to this, it is possible to find out the original size of the document in inches by dividing pixels to this DPI.

That is all when it comes to DPI and raster images.
cyberchen Posted: Saturday, December 29, 2018 1:38:28 PM(UTC)
 
In other Libs its possible to tell the Render Method what DPI Res. shoud be used. How can i do it here?

I whant to Render to a Tiff via a bitmap, i think bitmap.SetResolution(dpi, dpi); alone will not do the job :(

Here is my Rendering code:
Code:
      
                      int targetWidth = (int)(page.Width / 72 * dpi );
                                int targetHeight = (int)(page.Height / 72 * dpi );

                                using (var bitmap = new Bitmap(targetWidth, targetHeight))
                                {

                                    bitmap.SetResolution(dpi, dpi);
                                    using (var g = Graphics.FromImage(bitmap))
                                    {
                                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, targetWidth, targetHeight);
                                        using (var pdfBitmap = new PdfBitmap(targetWidth, targetHeight, true))
                                        {
                                            page.Render(pdfBitmap, 0, 0, targetWidth, targetHeight, PageRotate.Normal, RenderFlags.FPDF_ANNOT);
                                            g.DrawImageUnscaled(pdfBitmap.Image, 0, 0);
                                        }
                                    }
                                    bitmap.Save(temppath + filename, System.Drawing.Imaging.ImageFormat.Tiff);