Alaska Software Inc. - How to keep image DPI
Username: Password:
AuthorTopic: How to keep image DPI
Itai Ben-ArtziHow to keep image DPI
on Fri, 09 Oct 2020 02:25:19 -0700
Hi,
I am reading a 200 DPI TIFF file into a PS, and save (code below).
The saved file is 96 DPI.
Is it possible to keep the saved file 200 DPI? How?

Many thanks,
-Itai

           
oImage   := XbpBitmap():new():create()
oImage:loadFile( cImageFile )
oPS := XbpPresSpace():new():Create()
oImage:PresSpace(oPS)
oImage:saveFile('c:\Temp\Test.tif', XBPBMP_FORMAT_TIFF)
Andreas Gehrs-Pahl
Re: How to keep image DPI
on Fri, 09 Oct 2020 07:15:16 -0400
Itai,

>I am reading a 200 DPI TIFF file into a PS, and save (code below).
>The saved file is 96 DPI.
>Is it possible to keep the saved file 200 DPI? How?

Yes, you should be able to set the DPI values before saving the file:

oImage:SetProperty('System.Image.ResolutionUnit', 2)    Inches (DPI)
oImage:SetProperty('System.Image.HorizontalResolution', 200)
oImage:SetProperty('System.Image.VerticalResolution',   200)
oImage:SaveFile('c:\Temp\Test.tif', XBPBMP_FORMAT_TIFF)

Hope that helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
Andreas Gehrs-Pahl
Re: How to keep image DPI
on Fri, 09 Oct 2020 08:14:57 -0400
Itai,

>Is it possible to keep the saved file 200 DPI? How?

Keep in mind that those are just meta data tags. Those values don't actually 
change the image size or format or anything else.

Also, Xbase++ doesn't seem to let you change those meta data tags if they 
don't exist in a loaded image. So, if you create a new image, there is no 
way to change those tags, even though the 96 DPI (default) value is always 
saved.

You can of course always manually change the DPI values in the saved TIFF 
file after it was saved. Just search for those tags -- XResolution: 282 
(0x11A) and YResolution: 283 (0x11B) -- and change their values from 96 
(0x77) to 200 (0xC8). The TIFF Revision 6 format is described here:

https://www.adobe.io/content/dam/udp/en/open/standards/tiff/TIFF6.pdf

Hope that helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
Itai Ben-ArtziRe: How to keep image DPI
on Fri, 09 Oct 2020 12:03:08 -0700
Thank you, Andreas!!!
It does not work.  The saved file shows 96, not 200 (code below).
This function handles checks' images that must comply with bank's
regulations for remote deposit.
Also, the third parameter of :SaveFile() has no effect on the saved
file.  0 or 100 yields the same file size.

-Itai

        *
oImage   := XbpBitmap():new():create()
oImage:loadFile( cImageFile )
oPS := XbpPresSpace():new():Create()
oImage:PresSpace(oPS)
oImage:SetProperty('System.Image.ResolutionUnit', 2)    Inches (DPI)
oImage:SetProperty('System.Image.HorizontalResolution', 200)
oImage:SetProperty('System.Image.VerticalResolution',   200)
oImage:saveFile('c:\Temp\Test.tif', XBPBMP_FORMAT_TIFF)
Jim LeeRe: How to keep image DPI
on Fri, 09 Oct 2020 23:27:16 +0200
hi,

if you cant do it with Xbase++ only what about 3-PP LIB called FreeImage.
Pablo have a Wrapper using ot4xb to use FreeImage.DLL with Xbase++
Itai Ben-ArtziRe: How to keep image DPI
on Fri, 09 Oct 2020 21:58:18 -0700
Thank you, Jim.
I'll take a second look into this lib.
At first glance, there is no function to write content into existing
Tiff.
Jim LeeRe: How to keep image DPI
on Sat, 10 Oct 2020 21:27:43 +0200
hi,

> I'll take a second look into this lib.
> At first glance, there is no function to write content into existing Tiff.

i use FreeImage while Xbase++ v1.9.355 does not have TIF
when Xbase++ v2.x fail than you have to look for other Solution.

i use FREE_DRAWPICTURE() for resize. it draw Image into hDC with given Size.
this is the Windows Way which does not know Xbase++ Presspace

if Source was bigger than Target i got higher DPI when draw all Pixel, or ?

---

FreeImage is a 3-PP DLL with many Grafic Format.
if it not include a Function you need write Author and ask him.
Jim LeeRe: How to keep image DPI
on Wed, 14 Oct 2020 07:09:45 +0200
hi,

found in FreeImage SetDotsPerMeterX / SetDotsPerMeterY

https://freeimage.sourceforge.io/fnet/html/8C3F1901.htm

SetDotsPerMeterX
Set the horizontal resolution, in pixels-per-meter, of the target device for 
the bitmap.

SetDotsPerMeterY
Set the vertical resolution, in pixels-per-meter, of the target device for 
the bitmap.
Andreas Gehrs-Pahl
Re: How to keep image DPI
on Sat, 10 Oct 2020 07:18:26 -0400
Itai,

>It does not work. The saved file shows 96, not 200 (code below).

I would consider that a PDR-worthy issue. The Get/SetProperty methods of the 
XbpBitmap() class doesn't seem to work (as advertised/documented). Xbase++ 
only saves EXIF data and doesn't allow the changing of the DPI settings in 
either the JPG, TIF, or the EXIF data.

If you associate a Presentation Space with the bitmap, then the default 
value for screen output -- 96 DPI -- is used, and the original DPI settings 
of the original file will be either replaced with 96 (in TIF files) or are 
completely lost (in JPG files)!

Besides that, when saving or updating any (EXIF) values, many of the other 
original EXIF values (from the original file) are simply lost. In addition 
to that, many EXIF values can't be accessed or changed in the first place.

>Also, the third parameter of :SaveFile() has no effect on the saved
>file. 0 or 100 yields the same file size.

That is because Xbase++ uses LZW-compression for TIF files by default. That 
type of compression is a loss-less compression that has no levels to choose 
from. That third parameter is only relevant for the JPG and PNG formats, as 
documented (under the XbpBitmap:SaveFile() method).

As I mentioned before, if you don't want to use an external, third-party 
product to accomplish what you want to do, you can always manually change 
those DPI values in the TIF files with some minor low-level file operations 
using pure Xbase++.

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
Itai Ben-ArtziRe: How to keep image DPI
on Sat, 10 Oct 2020 13:52:11 -0700
Thank you, Andreas.
I keep my eyes peeled for the resolution of that PDR.
I'll check if banks accept/reject the xBase++ Tif.

-Itai