-1

I'm using Delphi 10.1 Berlin and I need to create an image and set his Canvas size equals to be equal to the bitmap size. To be more specific I want to access this properties: enter image description here

Where say: "Sized by Image". But I can't figure out how can I acces this, help please! :-D

EDIT: This is the code that I'm using, if you guys need to understand better what I'm trying to achieve:

imgProdutoZoom := TImage.Create(rtFundoArredondadoZoom);
imgProdutoZoom.Parent := rtFundoArredondadoZoom;
imgProdutoZoom.Align := TAlignLayout.Client;
imgProdutoZoom.Bitmap.Assign(imgProduto.Bitmap);
imgProdutoZoom.WrapMode := TImageWrapMode.Fit;
imgProdutoZoom.Name := 'imgZoom'+ IntToStr(i);

I found this code: imgProdutoZoom.MultiResBitmap.SizeKind.Source; But the console give me an error: '[dcc32 Error] MainFrm.pas(628): E2018 Record, object or class type required'

Danilo Casa
  • 506
  • 1
  • 9
  • 18
Diego Bittencourt
  • 595
  • 10
  • 28
  • I'm not sure if I get the question right. But the original's resolution shouldn't be imgProducto.Bitmap.Height and imgProducto.Bitmap.Width ?. Is that what you are looking for ?. – Marc Guillot Oct 19 '16 at 22:04
  • I just want to have access to this property "Seize by image". I don't want the Height and Width of my Image – Diego Bittencourt Oct 19 '16 at 22:51
  • I can be wrong, but I don't think that's a property. If you want to set the size of your TImage exactly as the original source, then just do : imgProdutoZoom.Height := imgProduto.Bitmap.Height; and imgProductoZoom.Width := imgProduto.Bitmap.Width; – Marc Guillot Oct 19 '16 at 23:10
  • No, didn't worked. 'imgProdutoZoom.Height' is a single and 'imgProdutoZoom.Bitmap.Height' is a integer. Also my image just disapear... – Diego Bittencourt Oct 19 '16 at 23:28
  • I am extremely confused what you are trying to accomplish. Please read your entire question from our perspective, knowing nothing about what your project is, and ask yourself if you could answer it if you were us? – Jerry Dodge Oct 20 '16 at 06:03
  • Also, it appears you're working with Firemonkey, yet are creating a simple Windows application. Is there any particular reason you're using Firemonkey instead of VCL? – Jerry Dodge Oct 20 '16 at 06:04
  • @MarcGuillot Perhaps you're thinking of VCL, but the question is still very unclear. – Jerry Dodge Oct 20 '16 at 06:05
  • Thanks Jerry, indeed I was thinking of VCL and I was also confused about the question. Diego, look a this blog, on Firemonkey you can use a Rectangle to get the same effect than a TImage, and it lets you set its size in Pixels (using the Height and Width of your original Bitmap). http://www.fmxexpress.com/trectangle-bitmap-instead-of-timage-for-delphi-xe5-firemonkey-on-android-and-ios/ – Marc Guillot Oct 20 '16 at 06:28
  • I need to create an image and set his Canvas size equals to the bitmap size – Diego Bittencourt Oct 20 '16 at 13:44
  • If my post doesn't answer your question, please comment on it explaining what is wrong. Otherwise provide a [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) to eliminate any guessing. – Tom Brunberg Oct 20 '16 at 14:31
  • I'll do this tonight. I think your post will help me, thanks man! – Diego Bittencourt Oct 20 '16 at 16:23

1 Answers1

3

You did not show what rtFundoArredondadoZoom is, but I assume it is a TRectangle.

When you set

imgProdutoZoom.Parent := rtFundoArredondadoZoom;
imgProdutoZoom.Align := TAlignLayout.Client;

you are telling to fill up the area of the parent (rtFundoArredondadoZoom). However, since TImage.WrapMode by default is TImageWrapMode.Fit, the image retains its aspect ratio and doesn't stretch to fill the parent.

Now, the limiting factor in your setup is the rtFundoArredondadoZoom rectangle, and specifically its height. To show the image in its full size, you need to set

rtFundoArredondadoZoom.Height := imgProdutoZoom.Bitmap.Height;

You may at times also want to set the width of the rectangle.

The following image shows an image in original size to the left, and te same image on a rectangle with smaller height using basically your code

enter image description here

Then after applying the height setting on the rectangle

enter image description here

Your code corrected accordingly would be:

imgProdutoZoom := TImage.Create(rtFundoArredondadoZoom);
imgProdutoZoom.Parent := rtFundoArredondadoZoom;
imgProdutoZoom.Align := TAlignLayout.Client;
imgProdutoZoom.Bitmap.Assign(imgProduto.Bitmap);
// imgProdutoZoom.WrapMode := TImageWrapMode.Fit; // not needed
rtFundoArredondadoZoom.Height := imgProdutoZoom.Bitmap.Height; // add this
imgProdutoZoom.Name := 'imgZoom'+ IntToStr(i);
Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54