Error (Bitmap size too big) when using Timage in android firemonkey thread

1

I use this function to generate thumbs of the images in the system:

procedure converte_jpg(Bitmap: TBitmap; Stream: TMemoryStream);
var
  surf: TBitmapSurface;
  saveParams : TBitmapCodecSaveParams;
begin
  surf := TBitmapSurface.Create;

  try
    surf.Assign(Bitmap);
    saveParams.Quality:= 20;
    if not TBitmapCodecManager.SaveToStream(Stream, surf, '.jpg',@saveParams) 
    then
      raise EBitmapSavingFailed.Create(SBitmapSavingFailed);
  finally
    Surf.Free;
  end;
end;

I call it like this

img.Bitmap.LoadFromStream(imagem);
converte_jpg(img.Bitmap,thumb_img);

The result of the function is a TMemoryStream that I save in the database, the function normally works on the main thread, but when I put it inside an anonymous thread, it gives the following error

  

Bitmap size too big.

    
asked by anonymous 19.06.2018 / 14:55

0 answers