banaguitar 0 Posted April 11 (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 April 11 by banaguitar Share this post Link to post
Anders Melander 1783 Posted April 11 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
banaguitar 0 Posted April 12 (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 April 12 by banaguitar Share this post Link to post
Anders Melander 1783 Posted April 12 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: 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
banaguitar 0 Posted April 12 Hello, thanks for help. Here is a minimal example. Example Layer.zip Share this post Link to post
Anders Melander 1783 Posted April 12 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, You are not specifying the size/position of the bitmap layer. 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
banaguitar 0 Posted April 12 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
Anders Melander 1783 Posted April 12 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
banaguitar 0 Posted April 12 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
Anders Melander 1783 Posted April 13 (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 April 13 by Anders Melander Share this post Link to post
banaguitar 0 Posted April 13 (edited) Thank you. The "arrow" is too big. How can I adjust the size of the arrow? Edited April 13 by banaguitar Share this post Link to post
Anders Melander 1783 Posted April 13 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
banaguitar 0 Posted April 13 (edited) Something like this. Edited April 13 by banaguitar Share this post Link to post
banaguitar 0 Posted April 13 I mean, I don't know how to adjust the size as shown above Share this post Link to post
Anders Melander 1783 Posted April 13 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
Anders Melander 1783 Posted April 13 BL.Location := FloatRect(x1, y1, x2, y2); Share this post Link to post