In my application, I use an intent
to get an image filename from the gallery
and im trying to load this filename into a TImage
. I tried to load it with LoadFromFile
as well as getting the JBitmap
, converting it to TBitmap
and Assign
it to my TImage
. This only work with bitmap with a maximum size of 98 x 98 pixels... if the width or the height is bigger than 99 or 98 pixel MOST OF THE TIME I get an error message 'Bitmap size too big'. Sometime I can go up to 250 x 250...
IM trying to find why since 3 days...
Here is the code :
var
jBitmapD, jSmallBitmap: JBitmap;
BitmapD : TBitmap;
imgW, imgH:Integer;
begin
...
jBitmapD := TJBitmapFactory.JavaClass.decodeFile(StringToJString(imgGallerieChm));
...
jSmallBitmap := TJBitmap.JavaClass.createScaledBitmap(jBitmapD, 98, 98, True);
//jSmallBitmap := TJBitmap.JavaClass.createScaledBitmap(jBitmapD, 101, 101, True);
//jSmallBitmap := TJBitmap.JavaClass.createScaledBitmap(jBitmapD, 1234, 567, True);
...
imgH := jSmallBitmap.getHeight;
imgW := jSmallBitmap.getWidth;
bitmapD := TBitmap.Create; //Work if jSmallBitmap if smaller than 99 x 99
//bitmapD.Create(98,98); //Work if jSmallBitmap if smaller than 99 x 99
//bitmapD.Create(222,333); //Don't work
try
bitmapD.SetSize(imgW,ImgH); //without this, its not working and it should be 99 x 99 or less... most of the time
bitmapD := JBitmapToBitmap(jSmallBitmap);
imgLepObs.Bitmap.Assign(bitmapD);
finally
bitmapD.Free;
end;
The next function work if AImage and TBitmap are smaller than 99 x 99 most of the time
function TfrmMain.JBitmapToBitmap(const AImage: JBitmap): TBitmap;
var
bitmapSurface :TBitmapSurface;
begin
bitmapSurface := TBitmapSurface.Create;
try
if JBitmapToSurface(AImage, bitmapSurface) then
begin
Result.Assign(bitmapSurface);
end;
finally
bitmapSurface.Free;
end;
end;
Thank you for your help... im about to giveup...
I tried downscaling my bitmap with this :
bfOptions.inSampleSize := StrToInt(Edit1.Text); //
bfOptions.inJustDecodeBounds := False;
jSmallBitmap := TJBitmapFactory.JavaClass.decodeFile(StringToJString(imgGallerieChm), bfOptions);
It work most of the time... the smaller the resulting bitmap, the higher chance of success... for a given size, it sometime work, sometime not, and sometime it work right after I restart my application...