Recent

Author Topic: I think i found a ugly bug in TImage  (Read 4674 times)

Fantablup

  • Full Member
  • ***
  • Posts: 171
I think i found a ugly bug in TImage
« on: July 04, 2021, 09:28:53 pm »
When i am developing the DB admin application, i also add images and memo as binary possibilities.

When saving a image to the database, it was only saving as BMP, even if i loaded a JPG file.

I used image.picture.SaveToStream, but no go.

I found out that after doing anything with it like changing width or height, it automatically goes to a BMP type.
Also with checking Image.Picture.Bitmap.Empty It turns automatically to a BMP.

I had to create an extra TImage beside the display image in the grid where i don't do anything with it.
And i had to check empty with Image.Picture.Graphic.Empty. Instead of checking with Image.Picture.Bitmap.Empty.

Now i can save the  extra TImage with image.picture.SaveToStream, and it save it as the file type it was loaded with.

The  extra TImage i create was because the original TImage i use for display is changing to BMP type every time i change anything like with or height.

I call this an ugly bug. Or, several ugly bugs in the TImage.

I also was able to create a function that checks what image type it is in the blob field and also if it is an image or binary text.


lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: I think i found a ugly bug in TImage
« Reply #1 on: July 04, 2021, 10:54:15 pm »
I don't think it's a bug but a consequence of how TImage and the underlying TPicture works.

TPicture is meant to be able to hold almost any kind of graphics in its Graphic property, but when you make it hold an specific kind of graphic (say, Jpeg, a TJpegImage) and you try to access one of the others (like Bitmap, a TBitmap) it takes it to mean you're done with the "original" and you're tryng a new one; note, though, that if you only access Graphic this doesn't happens, since it then checks which specific "graphic" it holds and it access it.

The  extra TImage i create was because the original TImage i use for display is changing to BMP type every time i change anything like with or height.

That quite depends on exactly how you're trying to change the width/height but note that, generally speaking, TImage is not really meant to edit graphics but to show them.

When you want to edit the underlying graphic the solution is almost always to create a new TImage (or, better, a TPicture or the specific container for the kind of image you want) to hold the "new" graphic which can then be assigned back to the original "view-only" TImage.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Fantablup

  • Full Member
  • ***
  • Posts: 171
Re: I think i found a ugly bug in TImage
« Reply #2 on: July 04, 2021, 11:04:38 pm »
Thanks lucamar!

I understand what your saying. And i think understand how it's working after i saw this.

But i call it a bug. Because also only checking if empty on bitmap also change it to BMP. And i did not change any graphic. I only changed width and height of the component. And this made it turn to BMP.

It should be clear in the description of the component. But i can't see any.
This made me work extra for 6 hours just to figure out.
« Last Edit: July 04, 2021, 11:15:28 pm by Fantablup »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: I think i found a ugly bug in TImage
« Reply #3 on: July 04, 2021, 11:15:28 pm »
Hi!

It is not a bug.

But as a workaround for your strange desires you can store it as a blob.

Winni

Fantablup

  • Full Member
  • ***
  • Posts: 171
Re: I think i found a ugly bug in TImage
« Reply #4 on: July 04, 2021, 11:17:15 pm »
I don't think it is any strange desire to be able to save to stream as the original image type.

I solved it by adding an extra TImage that i don't do anything with.

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: I think i found a ugly bug in TImage
« Reply #5 on: July 05, 2021, 02:23:54 am »
But i call it a bug. Because also only checking if empty on bitmap also change it to BMP. And i did not change any graphic. I only changed width and height of the component. And this made it turn to BMP.

Accessing Bitmap, even if just to check whether it's empty, is accessing Bitmap.

What makes little sense is the second: changing the width/height (or indeed almost almost any other property pertaining of TImage except those relating to the underlying graphic) should not affect the graphic at all.

And in fact, it doesn't here (Xubuntu 18.04 AMD64, Laz/FPC 2.0.12/3.2.0): if I load a jpeg or png or whatever to a TImage and change the bounds of the TImage itself, it all works as it should and the image keeps showing the graphic, depending on the various TImage properties: centered, proportional, stretched, etc.

I think it's time for you to show some code so we can see exactly what you are doing and how. And a little more info about your development environment wouldn't be amiss: OS, bitness, Laz/FPC versions, etc.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1584
    • Lebeau Software
Re: I think i found a ugly bug in TImage
« Reply #6 on: July 05, 2021, 08:18:42 pm »
Accessing Bitmap, even if just to check whether it's empty, is accessing Bitmap.

Exactly. And this is even documented:

https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/tpicture.bitmap.html

Quote
Bitmap - Returns a bitmap. If the contents is not already a bitmap, the contents are thrown away and a blank bitmap is returned.

If you want to check if the Picture's current graphic is empty, use Picture.Graphic.Empty() instead of Picture.Bitmap.Empty().  Make sure you check first that Picture.Graphic is not nil.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Fantablup

  • Full Member
  • ***
  • Posts: 171
Re: I think i found a ugly bug in TImage
« Reply #7 on: July 05, 2021, 08:20:59 pm »
Thanks Remy!

Fantablup

  • Full Member
  • ***
  • Posts: 171
Re: I think i found a ugly bug in TImage
« Reply #8 on: July 05, 2021, 08:33:57 pm »
I think it's time for you to show some code so we can see exactly what you are doing and how. And a little more info about your development environment wouldn't be amiss: OS, bitness, Laz/FPC versions, etc.

Maybe i was wrong about just that.
I was spending so much time on it that i was tired of it.

But, i solved it though.

Thanks for all you help Lucamar. You defiantly can your stuff.

It's totally different here in the forum compared to the Delphi forums i used when i was doing Delphi. They where mostly very arrogant, and always seemed like angry all the time to each other :)

 

TinyPortal © 2005-2018