skip to Main Content

Experiencing problems creating thumbnails in XE7-Update1 FMX Windows7-64bit. This problem is not present in XE5.

I have three TImage components, one button and a TOpenDialog component on FMX HD form.

With TOpenDialog I choose an existing PNG that has been tested in Photoshop/Corel and seems good. The image displays correctly in Image1.

At runtime I create two thumbnails using Image1.Bitmap.CreateThumbnail and assign the result to Image2 and Image3. On XE7 Image2 and Image3 has corrupted background with random sections of the form. With XE5 everything works well.

The corruption increases as I repeat the process (load a PNG in Image1… create thumbnails and display).

The corrupted background is present when saving to file.

Here’s the code:

procedure TForm1.Button1Click(Sender: TObject);
begin
  FormShow(nil);
end;

procedure TForm1.FormShow(Sender: TObject);
var
  thumbX, thumbY : Integer;
  SaveParams: TBitmapCodecSaveParams;
  thumb1, thumb2 : TBitmap;
begin
  if OpenDialog1.Execute then
  begin
    Image1.Bitmap.LoadFromFile(OpenDialog1.FileName);
    try        
      thumbX := Round(Image1.Width / 4);
      thumbY := Round(Image1.Height / 4);
      thumb1 := Image1.Bitmap.CreateThumbnail(thumbX, thumbY);
      Image2.Bitmap.SetSize(thumbX, thumbY); //this has no impact
      Image2.Bitmap.Assign(thumb1);
    finally
      thumb1.free;
    end;

    try
      thumbX := Round(Image1.Width / 2);
      thumbY := Round(Image1.Height /2);
      thumb2 := Image1.Bitmap.CreateThumbnail(thumbX, thumbY);
      Image3.Bitmap.SetSize(thumbX, thumbY); //this has no impact
      Image3.Bitmap.Assign(thumb2);
    finally
      thumb2.Free;   
    end;

    SaveParams.Quality := 100;
    Image2.Bitmap.SaveToFile('c:blackdotimage_quarter.png', @SaveParams);
    Image3.Bitmap.SaveToFile('c:blackdotimage_half.png', @SaveParams);
  end;
end;

Any ideas on how to address this issue would be extremely helpful.

We tried:

  1. invalidate
  2. set the size of image2, image3 before assigning the thumbnail
  3. clearing image2, image3 before assigning the thumbnail

Looked at the CreateThumbnail code in FMX.Graphics but there’s nothing much there that we see could be changed to patch this problem.

2

Answers


  1. Chosen as BEST ANSWER

    Since it seems that this is a bug with XE7 I took another approach that seems to work in the test code. Instead of creating the thumb with TBitmap.CreateThumbnail I create the thumb using TBitmap.LoadThumbnailFromFile passing the desired thumb width and height. I guess in the real app we can load the thumb directly in the visual component and not create TBitmaps at runtime.

    Although this approach repeatedly loads the file from disk it allows us to move forward with our app development. With the test code I can repeatedly load images which are both visually and saved to file correctly.

    var
       thumbX, thumbY : Integer;
       SaveParams: TBitmapCodecSaveParams;
       thumb1, thumb2 : TBitmap;
    begin
         if OpenDialog1.Execute then
         begin
           Image1.Bitmap.LoadFromFile(OpenDialog1.FileName);
    
             thumbX := Round(Image1.Width / 4);
             thumbY := Round(Image1.Height / 4);
             //thumb1 := Image1.Bitmap.CreateThumbnail(thumbX, thumbY);
             thumb1 := TBitmap.Create;
           try
             thumb1.LoadThumbnailFromFile(OpenDialog1.FileName, thumbX, thumbY);
             thumb1.SaveToFile('c:blackdotthumb1.png');  //just to compare with our visual components
             Image2.Bitmap.SetSize(thumbX, thumbY);
             Image2.Bitmap.Assign(thumb1);
           finally
             thumb1.Free;
           end;
    
    
             thumbX := Round(Image1.Width / 2);
             thumbY := Round(Image1.Height /2);
             //thumb2 := Image1.Bitmap.CreateThumbnail(thumbX, thumbY);
             thumb2 := TBitmap.Create;
           try
             thumb2.LoadThumbnailFromFile(OpenDialog1.FileName, thumbX, thumbY);
             thumb2.SaveToFile('c:blackdotthumb2.png');  //just to compare with our visual components
             Image3.Bitmap.SetSize(thumbX, thumbY);
             Image3.Bitmap.Assign(thumb2);
           finally
             thumb2.Free;
           end;
    
           SaveParams.Quality := 100;
           Image2.Bitmap.SaveToFile('c:blackdotimage_quarter.png', @SaveParams);
           Image3.Bitmap.SaveToFile('c:blackdotimage_half.png', @SaveParams);
    
         end;
    end;
    

  2. It is certainly a big bug. I took the example code and tried it myself.

    Results:

    1) Image2 does not scale well and is always the same size as Image3

    2) After 3 tries Image2 consists of two overlayed images: In front the image from the third try and in the back the image of the first try.

    The process is repeatable and the choice of images is also not relevant

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search