Jump to content
banaguitar

Graphics32 -> Load png into TBitmap32, wrong size

Recommended Posts

Posted (edited)

Hello,

 

I want to load a png, which is a clickable button, into a TBitmap32, but the size of the png is wrong.

Here is my code:

ImgView.Layers.Clear;
ImgView.scalemode := smResize;
ImgView.Bitmap.LoadFromFile('background.jpg');

BL := TBitmapLayer.Create(ImgView.Layers);
LoadBitmap32FromPNG(BL.bitmap,'button.png');
BL.Bitmap.DrawMode := dmtransparent;
BL.Scaled := true;
BL.OnClick := OnClickButton;

I need your help. Thank you very much.

 

Kind regards

 

Edited by banaguitar

Share this post


Link to post

You don't need to use LoadBitmap32FromPNG; You can just use TBitmap32.LoadFromFile directly and let that figure the format out for you.

BL.Bitmap.LoadFromFile('button.png');

 

Also, you should probably be using dmBlend DrawMode instead of dmTransparent:

BL.Bitmap.DrawMode := dmBlend;

dmTransparent is for color key transparency (like what TBitmap does). dmBlend is for alpha blending.

 

 

7 hours ago, banaguitar said:

the size of the png is wrong

What do you mean? What size is it? What size should it be?

Share this post


Link to post
Posted (edited)
4 hours ago, Anders Melander said:

You don't need to use LoadBitmap32FromPNG; You can just use TBitmap32.LoadFromFile directly and let that figure the format out for you.


BL.Bitmap.LoadFromFile('button.png');

 

Also, you should probably be using dmBlend DrawMode instead of dmTransparent:


BL.Bitmap.DrawMode := dmBlend;

dmTransparent is for color key transparency (like what TBitmap does). dmBlend is for alpha blending.

 

 

What do you mean? What size is it? What size should it be?

Thank you. I mean a normale size. The png should be clearly visible. The proportions are wrong and the edges of the icon look horrible.

Edited by banaguitar

Share this post


Link to post

Without knowing the size of the base and layer bitmap I can't tell how their relative sizes should be. You have setup the layer scale to follow the base scale (Scaled=True), but have you specified the initial size of the layer?

 

The ugly edges are most likely caused by having DrawMode=dmTransparent.

 

You can experiment with layers and bitmaps using the Imgview_Layers example:

image.thumb.png.8176a7d11edfddc4d04fb0b98dc59a53.png

 

If you continue having problems, please create an issue at the Graphics32 issue tracker: https://github.com/graphics32/graphics32/issues

Include a minimal, reproducible example.

Share this post


Link to post
6 minutes ago, banaguitar said:

Hello, thanks for help. Here is a minimal example.

Okay, but:

7 hours ago, Anders Melander said:

If you continue having problems, please create an issue at the Graphics32 issue tracker: https://github.com/graphics32/graphics32/issues

Include a minimal, reproducible example. 

And don't include the exe or dcu files in your zip.

Also, a description or a mockup of what you expected the result to be would also be needed; I can't read your mind.

 

That said,

  1. You are not specifying the size/position of the bitmap layer.
  2. The size of the PNG (4774x4345) is much larger than the size of the background (1920x1247). That in itself is not a problem but the size does seem pretty excessive.

Share this post


Link to post

Good to know, but SetSize doesn't change anything in this case. You agree that the png looks not good at the edges? How to adjust the size of the png?

Share this post


Link to post
37 minutes ago, banaguitar said:

How to adjust the size of the png?

If you mean the size of the layer, something like this:

// Half size of background bitmap, centered
BL.Location := FloatRect(ImgView.Bitmap.Width/4, ImgView.Bitmap.Height/4, ImgView.Bitmap.Width/2, ImgView.Bitmap.Height/2);

 

Share this post


Link to post

This looks good, thank you, but it's not centered. I try to figure out how to position the arrow at top center.

Share this post


Link to post
Posted (edited)
11 hours ago, banaguitar said:

but it's not centered.

My bad. That should have been:

BL.Location := FloatRect(ImgView.Bitmap.Width/4, ImgView.Bitmap.Height/4, ImgView.Bitmap.Width/4*3, ImgView.Bitmap.Height/4*3);

as a rect is (x1,y1, x2,y2)

Edited by Anders Melander

Share this post


Link to post
Posted (edited)

Thank you. The "arrow" is too big. How can I adjust the size of the arrow?

Edited by banaguitar

Share this post


Link to post

Show us what you mean; We still can't read your mind.

  • What does it look like?
  • What do you want it to look like?

Share this post


Link to post

Okay. It would be so much easier if you actually read and answered the questions I have asked you.

 

The position and size of the layer determines where the bitmap is drawn. Isn't that what you are seeing?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×