Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change resolution of image

Status
Not open for further replies.

martynwheeler

Programmer
May 20, 2008
2
GB
Hi there,
I am new to Delphi and have a simple question. I want to save an image I create on a form to a file, but the resolution is only 96 dpi. Is there any way to change the resolution of the bmp that I output???

Thanks
Martyn
 
If you are talking about DPI, then just change the 96 to 72 or whatever.

This is stored in the BITMAPINFOHEADER fields
Code:
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
They are located in the BMP file at byte offsets 38 and 42 respectively. They are stored in little-endian (Intel-native) byte order.

If you are talking about resizing the image (changing the number of pixels across and/or down an image), then that is a different thing.

I would recommend you to the http://graphics32.org/wiki/"]Graphics32[/url] library.

Changing an image's size then is as easy as:
Code:
uses GR32, GR32_Resamplers;
var
  source:    tBitmap32;
  target:    tBitmap32;
  resampler: tKernelResampler;
begin
source := tBitmap32.Create;
target := tBitmap32.Create;
try
  source.LoadImage( "fooey.bmp" );
  //or
  source.Assign( original_bitmap );

  resampler := tKernelResampler.Create( nil );
  resampler.kernel := tLinearKernel.Create;

  target.boundsRect := Rect( 0, 0, new_width, new_height );

  StretchTransfer(
    target,
    target.boundsRect,
    target.boundsRect,
    source,
    source.boundsRect,
    resampler,
    dmOpaque
    );

  target.SaveToFile( "fooey_resized.bmp" )
  // or
  target.AssignTo( result_bitmap )

finally
  resampler.free;
  source.free;
  target.free
  end
end;

Hope this helps.
 
Thanks for your reply.

I'm not sure if I made myself clear in my original question so here goes again. I am programmatically creating a graphic in a TImage control on my form. I then save this picture to a file using
image1.picture.savetofile('filename.bmp')

The image produced has the same resolution (96 dpi) as the image displayed on the screen. This is fine for viewing on screen but I would like to be able to print this image at a later date. SO I guess my question is:
Is there anyway to create the image with a higher resolution in the first place?

Cheers again
Martyn
 
No, you weren't very clear, but you ought to examine the answer given you before discounting it and asking again.

I've told you both (1) how to change the print resolution, or DPI, and (2) how to change the pixel resolution, or image size.

You'll definitely have to mess with the first, and you may also want to enlarge your image with the second. Both affect print quality.

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top