Recent

Author Topic: Loading only part of a bitmap  (Read 273 times)

HappyLarry

  • Full Member
  • ***
  • Posts: 155
Loading only part of a bitmap
« on: September 22, 2020, 10:32:57 pm »
I want to look at the pixels in a .pdf image. I converted the .pdf to .bmp using Gimp. The .bmp looks just like the .pdf.  I then tried to import the .bmp into a TBitmap. It worked partly, but not all the image was imported. The right side of the image (about a quarter) was completely black. 

I only displayed the picture in Image1 to see what was going on. The width and height are given as the same as the .bmp, that is  850 x 1100 px.

Here is my code.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Click13(Sender: TObject);
  2. var
  3.     MyPicture:TBitmap;
  4. begin
  5.     MyPicture := TBitmap.Create;
  6.     MyPicture.LoadFromFile('c2.bmp');
  7.     Memo1.Lines.add('Height  - '+inttostr(MyPicture.Height));
  8.     Memo1.Lines.add('Width   - '+inttostr(MyPicture.Width));
  9.     Image1.Canvas.Draw(0,0,MyPicture);
  10. end;
  11.  

Thanks for any suggestions.
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

winni

  • Hero Member
  • *****
  • Posts: 1898
Re: Loading only part of a bitmap
« Reply #1 on: September 22, 2020, 10:50:36 pm »
Hi!

Maybe there is an error in your bmp.
The Gimp is generous with faulty files.

For testing:

Code: Pascal  [Select][+][-]
  1. image1.Picture.LoadFromFile('c2.bmp');
  2.  
Winni


jamie

  • Hero Member
  • *****
  • Posts: 3646
Re: Loading only part of a bitmap
« Reply #2 on: September 22, 2020, 10:53:02 pm »
Those values 850 and 1100 are paper inch sizes so unless you have 100 DPI settings There could be some confusion there.

Also depending on how you acquired the image, its possible you actually didn't get it all
The only true wisdom is knowing you know nothing

HappyLarry

  • Full Member
  • ***
  • Posts: 155
Re: Loading only part of a bitmap
« Reply #3 on: September 22, 2020, 11:01:34 pm »
Yes, the .bmp is 100 pixels per inch. Do you know what I have to do with Lazarus to recognize this? What does Lazarus measure in?
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

HappyLarry

  • Full Member
  • ***
  • Posts: 155
Re: Loading only part of a bitmap
« Reply #4 on: September 22, 2020, 11:07:41 pm »
@winni
I tried that code instead. The image had no black area but it looked stretched sideways, the words were wider than in the original. Perhaps 850 x 1100 in Lazarus is different from 850 x 1100 in Gimp (?).
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

winni

  • Hero Member
  • *****
  • Posts: 1898
Re: Loading only part of a bitmap
« Reply #5 on: September 22, 2020, 11:24:54 pm »
Hi!

In the ObjectInspector set the properties of image1:

AutoSize  to true
Stretch to false

The load it again with

Code: Pascal  [Select][+][-]
  1. image1.Picture.LoadFromFile('c2.bmp');

Now the image has the dimensions of the c2.bmp and it is not stretched.
Now you can decide if this is what you wanted.
Or if you do the export from the Gimp again with other parameters.

Winni

 

TinyPortal © 2005-2018