Delphi XE Firemonkey mobile app - How to decrease the size of an image?

0

The problem I face is that I allow the user to insert an image from their mobile device gallery, some images are too large to be recorded on a bench, taking into account the wonderful 3g signal quality. The temporary solution I found was to generate a thumbnail with predefined dimensions. Ex: 250,250. The image is reasonable, however, some photos do not have their exact dimensions in x and y and so the component creates a weird-looking frame. As for the file size does not exceed 110kb, the problem really is this frame. Has anyone ever faced the same difficulty?

    
asked by anonymous 20.10.2015 / 15:07

2 answers

2

The error occurs because the TImage component is configured to receive a square image, and eventually images are sent in portrait / landscape (rectangular) mode. One way to resolve this is to force the user to crop the image before it is loaded in TImage to a square format, thus eliminating the borders.

    
04.12.2015 / 15:11
0

Evandro,

I had this same problem with an app I was developing. I allowed users to send a photo to put as their profile image. How did I solve it?

1) I placed a TLayout on the form with Center alignment and size 300x300 (the important thing is to leave width and height equal, forming a square)

2) Inside this TLayout, I put a TImageViewer with Client alignment (occupying the entire TLayout)

3) I load the image to be treated inside TImageViewer, like this:

ImageViewer1.Bitmap.Assign(imagem);

4) I set TImageViewer's BitmapScale property as desired (zoom in on the image)

5) Finally, after the user has adjusted the image as you like (by dragging with your finger), I put a button at the bottom of the form with the following code:

var 
imagem : TBitmap;
...
    imagem := Layout1.MakeScreenshot;
...

This causes Delphi to create a "print" of the image that the user is viewing on the screen, and saves that "print" in the image variable.

6) After that, just treat the image variable as you wish! ;)

I hope I have helped.

PS: Once it's all worked out, you can refine your TImageViewer for the user to zoom in on the photo by "pinching" your fingers, you can put the option to rotate the image, and so on.

    
23.03.2017 / 21:10