Delphi XE Firemonkey mobile app - How to resize an image?

Asked

Viewed 1,880 times

0

The problem I face is that I allow the user to insert an image from his mobile device gallery, some images are too big to be recorded in a bank taking into account the wonderful 3g signal quality. The provisional 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 for this reason the component creates a frame with strange appearance. Regarding the file size does not exceed 110kb, the problem is really this frame. Someone has faced the same difficulty?

  • Which component is using to load the image ?

  • use a Timage @Júniormoreira

2 answers

2

The error is because the Timage component is configured to receive a square image, and eventually images are sent in portrait/landscape (rectangular) mode. A way to solve this serial requires the user to crop the image before it is loaded into Timage to a square format, thus eliminating the edges.

  • 1

    good alternative, I will implement and then respond if I succeeded. Thank you

1

Evandro,

I had this same problem in an app I was developing. I allowed users to send a photo to put as their profile image. How I resolved?

1) I put a Tlayout in the form with Center alignment and size 300 x 300 (the important thing is to leave equal width and height, forming a square)

2) Inside this Tlayout, I put a Timageviewer with Client alignment (occupying the entire Tlayout)

3) I upload the image to be treated inside Timageviewer, that way:

ImageViewer1.Bitmap.Assign(imagem);

4) I set the Timageviewer Bitmapscale property as desired (zoom into the image)

5) Finally, after the user adjusted the image as he wanted (dragging with his 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 the user is seeing on the screen, and saves this "print" in the image variable.

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

I hope I’ve helped.

PS: After it all worked out, you can sophisticate your Timageviewer so the user can zoom in on the photo by doing "tweezers" movement with his fingers, you can put option to rotate the image, and so on.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.