Board index » delphi » TBitmap.SaveToFile resolution

TBitmap.SaveToFile resolution

Does anybody know if/how I can set the resolution of the image that
results from calling TBitmap.SaveToFile?  When I save a bitmap image,
the saved image is at 75 pixels per inch; when I save a jpeg image,
it's at 150 ppi.

Thanks,

Jack

 

Re:TBitmap.SaveToFile resolution


A bitmap or image is not set at a resolution, but at a size :
eg. 300x400 pixels.

Rene

Quote
"Jack V. Johnson" wrote:

> Does anybody know if/how I can set the resolution of the image that
> results from calling TBitmap.SaveToFile?  When I save a bitmap image,
> the saved image is at 75 pixels per inch; when I save a jpeg image,
> it's at 150 ppi.

> Thanks,

> Jack

Re:TBitmap.SaveToFile resolution


Hmm... I think I may have asked this backwards - let me try again...

When I open an image that I save from TBitmap.SaveToFile in a paint
program such as PicturePublisher, I see that the same image saved as a
bitmap at 150x150 pixels shows a ppi setting of 75 and prints as 2
inches x 2 inches.  If I save the same image as a jpeg, it shows a ppi
of 150 and prints at 1 inch x 1 inch.  I'm curious why this is and how
I can control it.

Thanks,

Jack Johnson

On Thu, 25 Feb 1999 16:52:02 +0100, Rene Tschaggelar

Quote
<tschagge...@access.ch> wrote:
>A bitmap or image is not set at a resolution, but at a size :
>eg. 300x400 pixels.

>Rene

>"Jack V. Johnson" wrote:

>> Does anybody know if/how I can set the resolution of the image that
>> results from calling TBitmap.SaveToFile?  When I save a bitmap image,
>> the saved image is at 75 pixels per inch; when I save a jpeg image,
>> it's at 150 ppi.

>> Thanks,

>> Jack

Re:TBitmap.SaveToFile resolution


On Thu, 25 Feb 1999 15:28:08 GMT, {*word*104}n...@{*word*104}worlds.com (Jack V.

Quote
Johnson) wrote:
>Does anybody know if/how I can set the resolution of the image that
>results from calling TBitmap.SaveToFile?  When I save a bitmap image,
>the saved image is at 75 pixels per inch; when I save a jpeg image,
>it's at 150 ppi.

I don't know of an easy way to change the existing resolution of an
in-memory bitmap without creating a new bitmap and then copying the
data from the original to the new one. However, tweaking the
resolution information in a .BMP file is a simple process; the
following function will do it for you. It sets the resolution in the
bitmap file to the new value, and returns the old value as the
function result. If you pass 0 as the new value, it just returns the
old value without modifying it.

 const
   MetersPerInch = 0.0254;

 function TweakBitmapResolution(const FileName: String;
   NewResolution: LongInt): LongInt;
   var
     Stream: TStream;
     FileHeader: TBitmapFileHeader;
     Info: TBitmapInfo;
   begin
   Stream := TFileStream.Create(FileName, fmOpenReadWrite);
   try
     Stream.Read(FileHeader, SizeOf(FileHeader));
     Stream.Read(Info, SizeOf(Info));
     Result := Round(MetersPerInch * Info.bmiHeader.biXPel{*word*237}eter);
     if NewResolution > 0 then begin
       Info.bmiHeader.biXPel{*word*237}eter := Round(NewResolution /
         MetersPerInch);
       Info.bmiHeader.biYPel{*word*237}eter := Round(NewResolution /
         MetersPerInch);
       Stream.Position := SizeOf(FileHeader);
       Stream.Write(Info, SizeOf(Info)) end;
   finally
     Stream.Free end end;

-Steve

Re:TBitmap.SaveToFile resolution


Jack,

  The difference is probably in the defaults that PicturePublisher assumes
for image files that carry no dpi information.  BMP files have pel{*word*237}eter
fields in the header, but are seldom actually used.  JPG files have a
similar indicator, which also defaults to zero in most cases.  

-Danny Thorpe
Senior Engineer, Delphi R&D
Inprise Corporation

Jack V. Johnson <{*word*104}n...@{*word*104}worlds.com> wrote in article
<36d573c7.126982...@forums.inprise.com>...

Quote
> Hmm... I think I may have asked this backwards - let me try again...

> When I open an image that I save from TBitmap.SaveToFile in a paint
> program such as PicturePublisher, I see that the same image saved as a
> bitmap at 150x150 pixels shows a ppi setting of 75 and prints as 2
> inches x 2 inches.  If I save the same image as a jpeg, it shows a ppi
> of 150 and prints at 1 inch x 1 inch.  I'm curious why this is and how
> I can control it.

> Thanks,

> Jack Johnson

> On Thu, 25 Feb 1999 16:52:02 +0100, Rene Tschaggelar
> <tschagge...@access.ch> wrote:

> >A bitmap or image is not set at a resolution, but at a size :
> >eg. 300x400 pixels.

> >Rene

> >"Jack V. Johnson" wrote:

> >> Does anybody know if/how I can set the resolution of the image that
> >> results from calling TBitmap.SaveToFile?  When I save a bitmap image,
> >> the saved image is at 75 pixels per inch; when I save a jpeg image,
> >> it's at 150 ppi.

> >> Thanks,

> >> Jack

Re:TBitmap.SaveToFile resolution


Thanks to all for the replies...
I'll take a look at the headers.  BTW, it's not just PicturePublisher
that sees things this way - any program I load the files in ends up
displaying the bmp and jpg in the same 2:1 ratio.

Regards,

Jack

On 6 Mar 1999 20:57:56 GMT, "Danny Thorpe" <dtho...@inprise.com>
wrote:

Quote
>Jack,

>  The difference is probably in the defaults that PicturePublisher assumes
>for image files that carry no dpi information.  BMP files have pel{*word*237}eter
>fields in the header, but are seldom actually used.  JPG files have a
>similar indicator, which also defaults to zero in most cases.  

>-Danny Thorpe
>Senior Engineer, Delphi R&D
>Inprise Corporation

>Jack V. Johnson <{*word*104}n...@{*word*104}worlds.com> wrote in article
><36d573c7.126982...@forums.inprise.com>...
>> Hmm... I think I may have asked this backwards - let me try again...

>> When I open an image that I save from TBitmap.SaveToFile in a paint
>> program such as PicturePublisher, I see that the same image saved as a
>> bitmap at 150x150 pixels shows a ppi setting of 75 and prints as 2
>> inches x 2 inches.  If I save the same image as a jpeg, it shows a ppi
>> of 150 and prints at 1 inch x 1 inch.  I'm curious why this is and how
>> I can control it.

>> Thanks,

>> Jack Johnson

>> On Thu, 25 Feb 1999 16:52:02 +0100, Rene Tschaggelar
>> <tschagge...@access.ch> wrote:

>> >A bitmap or image is not set at a resolution, but at a size :
>> >eg. 300x400 pixels.

>> >Rene

>> >"Jack V. Johnson" wrote:

>> >> Does anybody know if/how I can set the resolution of the image that
>> >> results from calling TBitmap.SaveToFile?  When I save a bitmap image,
>> >> the saved image is at 75 pixels per inch; when I save a jpeg image,
>> >> it's at 150 ppi.

>> >> Thanks,

>> >> Jack

Re:TBitmap.SaveToFile resolution


So you say ANY viewing program produces this 2:1 anomolie. Go to my site and get
MY viewing program and tell me what happens with the images.

http://smatters.com/turboview

Davie

Quote
"Jack V. Johnson" wrote:
> Thanks to all for the replies...
> I'll take a look at the headers.  BTW, it's not just PicturePublisher
> that sees things this way - any program I load the files in ends up
> displaying the bmp and jpg in the same 2:1 ratio.

> Regards,

> Jack

> On 6 Mar 1999 20:57:56 GMT, "Danny Thorpe" <dtho...@inprise.com>
> wrote:

> >Jack,

> >  The difference is probably in the defaults that PicturePublisher assumes
> >for image files that carry no dpi information.  BMP files have pel{*word*237}eter
> >fields in the header, but are seldom actually used.  JPG files have a
> >similar indicator, which also defaults to zero in most cases.

> >-Danny Thorpe
> >Senior Engineer, Delphi R&D
> >Inprise Corporation

> >Jack V. Johnson <{*word*104}n...@{*word*104}worlds.com> wrote in article
> ><36d573c7.126982...@forums.inprise.com>...
> >> Hmm... I think I may have asked this backwards - let me try again...

> >> When I open an image that I save from TBitmap.SaveToFile in a paint
> >> program such as PicturePublisher, I see that the same image saved as a
> >> bitmap at 150x150 pixels shows a ppi setting of 75 and prints as 2
> >> inches x 2 inches.  If I save the same image as a jpeg, it shows a ppi
> >> of 150 and prints at 1 inch x 1 inch.  I'm curious why this is and how
> >> I can control it.

> >> Thanks,

> >> Jack Johnson

> >> On Thu, 25 Feb 1999 16:52:02 +0100, Rene Tschaggelar
> >> <tschagge...@access.ch> wrote:

> >> >A bitmap or image is not set at a resolution, but at a size :
> >> >eg. 300x400 pixels.

> >> >Rene

> >> >"Jack V. Johnson" wrote:

> >> >> Does anybody know if/how I can set the resolution of the image that
> >> >> results from calling TBitmap.SaveToFile?  When I save a bitmap image,
> >> >> the saved image is at 75 pixels per inch; when I save a jpeg image,
> >> >> it's at 150 ppi.

> >> >> Thanks,

> >> >> Jack

Re:TBitmap.SaveToFile resolution


Thanks, but...
This wasn't a challenge, just an observation based on my experience
(and my clients' experience).  Even if TurboView doesn't show this 2:1
display difference, the software my clients use does - and that's what
my program's images have to work with.  I've worked around the issue
for now (by documenting it, mostly) and my clients are happy.

Thanks,

Jack

On Tue, 09 Mar 1999 00:46:43 -0500, Davie Reed <da...@smatters.com>
wrote:

Quote
>So you say ANY viewing program produces this 2:1 anomolie. Go to my site and get
>MY viewing program and tell me what happens with the images.

>http://smatters.com/turboview

>Davie

>"Jack V. Johnson" wrote:

>> Thanks to all for the replies...
>> I'll take a look at the headers.  BTW, it's not just PicturePublisher
>> that sees things this way - any program I load the files in ends up
>> displaying the bmp and jpg in the same 2:1 ratio.

>> Regards,

>> Jack

>> On 6 Mar 1999 20:57:56 GMT, "Danny Thorpe" <dtho...@inprise.com>
>> wrote:

>> >Jack,

>> >  The difference is probably in the defaults that PicturePublisher assumes
>> >for image files that carry no dpi information.  BMP files have pel{*word*237}eter
>> >fields in the header, but are seldom actually used.  JPG files have a
>> >similar indicator, which also defaults to zero in most cases.

>> >-Danny Thorpe
>> >Senior Engineer, Delphi R&D
>> >Inprise Corporation

>> >Jack V. Johnson <{*word*104}n...@{*word*104}worlds.com> wrote in article
>> ><36d573c7.126982...@forums.inprise.com>...
>> >> Hmm... I think I may have asked this backwards - let me try again...

>> >> When I open an image that I save from TBitmap.SaveToFile in a paint
>> >> program such as PicturePublisher, I see that the same image saved as a
>> >> bitmap at 150x150 pixels shows a ppi setting of 75 and prints as 2
>> >> inches x 2 inches.  If I save the same image as a jpeg, it shows a ppi
>> >> of 150 and prints at 1 inch x 1 inch.  I'm curious why this is and how
>> >> I can control it.

>> >> Thanks,

>> >> Jack Johnson

>> >> On Thu, 25 Feb 1999 16:52:02 +0100, Rene Tschaggelar
>> >> <tschagge...@access.ch> wrote:

>> >> >A bitmap or image is not set at a resolution, but at a size :
>> >> >eg. 300x400 pixels.

>> >> >Rene

>> >> >"Jack V. Johnson" wrote:

>> >> >> Does anybody know if/how I can set the resolution of the image that
>> >> >> results from calling TBitmap.SaveToFile?  When I save a bitmap image,
>> >> >> the saved image is at 75 pixels per inch; when I save a jpeg image,
>> >> >> it's at 150 ppi.

>> >> >> Thanks,

>> >> >> Jack

Other Threads