How to Resize / Autosize an image

Hi,

I am trying to develop an android application using Delphi XE6.

My requirement is, how to make an image auto size ? I mean, without hard coding the TImage height and width how to auto adjust the size of the TImage based on that image dimensions ?

What i did is,
1. I have taken a ListBox control and added two ListboxItems. Height of ListboxItems is 250.

2. Added an TImage to the *ListBoxItem1* and align is "Client" and wrapmode is "Fit". I have uploaded a small image (small in dimensions). Now image is displaying in center and white space arround it. Now i have manually adjusted the height of the ListBoxItem1 as "110" (instead of 250). Now it is looking good.

3. Added an TImage to the *ListBoxItem2* and align is "Client" and wrapmode is "Fit". I have uploaded a big image (big in dimensions). Now image is fit as per the height. Now i have manually adjusted the height of the ListBoxItem2 as "625" (instead of 250). Now it is looking good.

Now my question is how can i adjust the height of the ListboxItem at run time, so that it should fit properly.
In simple words, i would like to show the images like facebook mobile app wall image.

Thanks in advance.
1
Reddy
7/2/2014 7:04:48 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

5 Replies
3608 Views

Similar Articles

[PageSpeed] 40
Get it on Google Play
Get it on Apple App Store

Set WrapMode to original.

MyListBoxItem.Height := MyImage.Bitmap.Height;

There is also:

MyImage.Bitmap.Canvas.Height and MyImage.Bitmap.Canvas.Bitmap.Height.
0
Eli
7/2/2014 2:29:57 PM
> {quote:title=Eli M wrote:}{quote}
> Set WrapMode to original.
> 
> MyListBoxItem.Height := MyImage.Bitmap.Height;
> 
> There is also:
> 
> MyImage.Bitmap.Canvas.Height and MyImage.Bitmap.Canvas.Bitmap.Height.

Hi,

I tried what you have suggested.
If i set the wrapmode as "Original" then it is showing some part of the image only. Not showing full image.

I have tried with image dimensions (Width : 800, Height : 1400), In this case showing full image and some extra space (considerable white space) below the image. (Note : If i give the ListboxItem1.Height = 650 and ImageWrapMode = Fit, then it shows perfectly.)

I have tried with image dimensions (Width : 3840, Height : 2160), In this case showing some part of the image and some extra space below the image. (Note : If i give the ListboxItem2.Height = 225 and ImageWrapMode = Fit, then it shows perfectly.)

Please suggest anything else can be done ?
0
Reddy
7/3/2014 6:19:15 AM
Any clues please ?

> {quote:title=Reddy G wrote:}{quote}
> > {quote:title=Eli M wrote:}{quote}
> > Set WrapMode to original.
> > 
> > MyListBoxItem.Height := MyImage.Bitmap.Height;
> > 
> > There is also:
> > 
> > MyImage.Bitmap.Canvas.Height and MyImage.Bitmap.Canvas.Bitmap.Height.
> 
> Hi,
> 
> I tried what you have suggested.
> If i set the wrapmode as "Original" then it is showing some part of the image only. Not showing full image.
> 
> I have tried with image dimensions (Width : 800, Height : 1400), In this case showing full image and some extra space (considerable white space) below the image. (Note : If i give the ListboxItem1.Height = 650 and ImageWrapMode = Fit, then it shows perfectly.)
> 
> I have tried with image dimensions (Width : 3840, Height : 2160), In this case showing some part of the image and some extra space below the image. (Note : If i give the ListboxItem2.Height = 225 and ImageWrapMode = Fit, then it shows perfectly.)
> 
> Please suggest anything else can be done ?
0
Reddy
7/14/2014 11:04:52 AM
> {quote:title=Reddy G wrote:}{quote}
> Any clues please ?
> 
you say setting Height and ImageWrapMode = Fit does what you want, so I'm not sure what the problem is.

--
FireMonkey users guide http://bit.ly/10abRZX
Embarcadero MVP
0
Mike
7/14/2014 3:47:25 PM
I was unable to calculate the height programatically.

> {quote:title=Mike Sutton wrote:}{quote}
> > {quote:title=Reddy G wrote:}{quote}
> > Any clues please ?
> > 
> you say setting Height and ImageWrapMode = Fit does what you want, so I'm not sure what the problem is.
> 
> --
> FireMonkey users guide http://bit.ly/10abRZX
> Embarcadero MVP
0
Reddy
7/16/2014 7:02:53 AM
Reply:

Similar Artilces:

How to resize an image when a browser resizes
Say I have an image that is sliced into 3 sections.  ImgSection1 -> ImgSection 2 -> ImgSection3 I'm trying to design my page so that regardless of the screen size or if the browser is resized,  ImgSection1 and ImgSection3 will remain constant (if they scale by percentage, they'll distort), ImgSection2 will stretch to fit, since it's just flat color... Something like this...but of course, it ain't workin' <div><img src="images/headerLogo_01.gif" width="266" height="95" alt="" style=" float:left; margin:0 0 0 0;"></div> <div><img src="images/he...

image resize for image button
my home page have a image button that shows (randomally) one of our album pictures. i want tocreate a smaller image (thumbnail) to be the source for this photo (and i have to use image button, since the users clicking that image...). i read this article and even down loaded a cotrol that does the work. but, both article and control (and as much i ubderstood the "getthumbnail" method) creates a image that can stream only for <img src> tag or "image" object. i couldn't find the way to use them as the "imageurl" adress of the image button. are the...

superreview requested: [Bug 189982] automatic image resizing: state of the image should be kept after resizing the browser window : [Attachment 178979] patch
Chris Thomas (CTho) <cst@andrew.cmu.edu> has asked Robert O'Callahan (Novell) <roc@ocallahan.org> for superreview: Bug 189982: automatic image resizing: state of the image should be kept after resizing the browser window https://bugzilla.mozilla.org/show_bug.cgi?id=189982 Attachment 178979: patch https://bugzilla.mozilla.org/attachment.cgi?id=178979&action=edit ------- Additional Comments from Chris Thomas (CTho) <cst@andrew.cmu.edu> With this patch, resizing the window does not toggle scaling (if it was scaled before, it continues to be scaled, and if it...

superreview granted: [Bug 189982] automatic image resizing: state of the image should be kept after resizing the browser window : [Attachment 178979] patch
Robert O'Callahan (Novell) <roc@ocallahan.org> has granted Chris Thomas (CTho) <cst@andrew.cmu.edu>'s request for superreview: Bug 189982: automatic image resizing: state of the image should be kept after resizing the browser window https://bugzilla.mozilla.org/show_bug.cgi?id=189982 Attachment 178979: patch https://bugzilla.mozilla.org/attachment.cgi?id=178979&action=edit ...

Bad image quality of resized images
Why is the quality of the resized pictures via the pesonal starter kit/.net less than what I can get from photo editing packages such as Photoshop? Most pictures on my site and sites posted via this forum have this problem. I've looked around and most examples use the same/similar code that is in the ResizeImageFile method.     I agree with you on this one. To get over this issue for at least the large images, I had them resized in Photoshop first to 600px width then upload them. It doesn't really bother me much with the meduim or smaller images.http://www.ourweddingphotos.in...

upload image then resize image handler
Hi Guys i have a handler page - upload.ashx That uploads a file fine. I want to add Resize functionality to that, i searched for a resize function on the forums but cant figure out how i would call it during/after the upload? What do i put in for the variable "stream buffer"?This is what i've got so far, appreciate any help you can give me -   <%@ WebHandler Language="C#" Class="Uploader" %>using System.IO;using System.Web;using System.Web.Configuration;public class Uploader : IHttpHandler {      public void ProcessRequest...

Resizing an image after a text is drawn on the image.
My appologies if this is in the forums, I trolled and had to sort through a lot and found nothing specific to my question.  If a post exists anywhere on this, please just provide the link. My technical challenge is to resize an image after it has text drawn on it and I don't want to save the image to disk. I'm already drawing the image using GDI+ and using... g.MeasureString(msg, myFont, originalWidth, stringFormat) ...to make sure that I am going to be wrapping the text correctly on the image.  The problem is that I can't seem to resize the image in memory so that the image c...

Image resize when image loads in page
 <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ID As Integer = Convert.ToInt32(Request.QueryString("ID")) 'Connect to the database and bring back the image contents & MIME type for the specified picture Using myConnection As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").Connec...

Better Image Quality for Image Resizing
I did some research and modified this function to allow for higher quality image resizing    public static byte[] MakeThumb(byte[] fullsize, int maxwidth)   {      Image iOriginal, iThumb;      double scale;       iOriginal = Image.FromStream(new MemoryStream(fullsize));       if (iOriginal.Width > maxwidth)      {         scale = (double)iOriginal.Width / (double)maxwidth;   &...

Insert image feature DOES NOT WORK with resized images
Name: Steve Email: mindcontrolcentralatcomcastdotnet Product: Thunderbird Summary: Insert image feature DOES NOT WORK with resized images Comments: As my summary states, the insert image feature (of Thunderbird) does not work if you resize your image (using the custom size function found in the Image Properties Window). It appears to work, and Thunderbird acts as if the email is sent, BUT IT IS NOT. I repeat, no email is sent! I've used the feature many times, and each time, the email appears to be sent - but NO ONE RECIEVES IT! I finally found this out the h...

image resizing script... compression? resizing algorithm?
I have created a image resizing script, partly pinched from else where but modified to suit my requirements. I have 2 problems im not sure about: How do you change the image resizing algorithm? As currently the image seems to sharp and id prefer it to be resized to create a smoother style of image. How do you change the compression settings of the jpg? The script im using is as follows: <script language="VB" runat="server"> Sub Page_Load(sender as Object, e as EventArgs) Response.Cache.VaryByParams("Image;Width;Height") = True Response.ContentType = "image/jpeg" Di...

Maintain Image quality while resizing image control
Hi  Everyone,   I am dynamically loading  image control over a panel . When I change the width and height of image control , the image shrinks or streches . Can any one help in maintaining image quality while resize the image control.  Thnx B.Vetrivelan remove image width and height such as ASP.NET will handle it's height and width.We All move to our original place.Don't forget.Imran Baloch Hi, I want to maintain the height and width of all the dynamically loaded image control to fit in to panel . For example if the panel width is 500 and i want to l...

Does image cache still work if the same image is resized
Hi I was wondering if anyone could help.I currently have a website that displays images, first as a grid of thumbnails and then when the user clicks on the image it shows them the full sized image. Currently these images are read from a server then resized and finally uploaded to the server. Currently I have the image resizer making two copies one thumbnail and one full size (although still resized from 1200x1200 to 600x600)I was wondering though if I was to use one image (the 600x600) and resize that to 120x120 using the <img style="width:120px; height:120px;" /> would cache...

Delphi 5 Image & ASA Image
Hi. I am facing problems on writing and reading Delphi image to ASA 6.03(2984) image field. I wrote a simple application with TTable component connected to a table with an image field, the writing is going well (I think), but when I try to read the image with my application I am getting "Invalid Blob Length". Any Idea why, as I remember in ASA 5.xxx it worked well. Best Regards. Yossi Zaig. Are the 'Keys in SQL Statistics' and 'Prevent Driver Not Capable Errors' checkboxes checked in your ODBC DSN? If they are not, you could get the error you...