Mega Search
23.2 Million


Sign Up

Make a donation  
Save image from TImage to filesystem [Android]  
News Group: embarcadero.public.delphi.multimedia

I'd like to save image from TImage to filesystem on Android:

procedure TForm1.btnSaveEvidenceClick(Sender: TObject);
var
  FileName : String;
  BMP : TBitmap;
begin
  FileName := TPath.Combine(TPath.GetPicturesPath, 'File');
  ShowMessage(FileName);
  BMP.Create;
  BMP.CopyFromBitmap(imgBarcodePhoto.Bitmap);
  BMP.Assign(imgBarcodePhoto.Bitmap);
  BMP.SaveToFile(FileName);
end;

Both CopyFromBitmap, and Assign gives me Access Violation...
imgBarcodePhoto is taken with camera and is visible.

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 11-Mar-2014, at 10:35 AM EST
From: Sebastian Kozub
 
Re: Save image from TImage to filesystem [Android] [Edit]  
News Group: embarcadero.public.delphi.multimedia
I changed the procedure:

procedure TForm1.btnSaveEvidenceClick(Sender: TObject);
var
  FileName : String;
  BMP : TBitmap;
begin
  FileName := TPath.Combine(TPath.GetPicturesPath, 'File.bmp');
  ShowMessage(FileName);
  BMP := TBitmap.Create;
  //BMP.CopyFromBitmap(imgBarcodePhoto.Bitmap);
  BMP.Assign(imgBarcodePhoto.Bitmap);
  Image1.Bitmap.Assign(BMP);
  BMP.SaveToFile(FileName);
end;

What is fastinating Image1 is updated with BMP bitmap :-)
I have "Write external storage" True

When I use Assign() then ReWrite with the same TPath it saves the file to Pictrues folder... it looks like SaveToFile from TBitmap doesn't work well...

When I use string 'File.png' instead of 'File.bmp' it works perfect ;)
How can I pass it to have bmp?

Edited by: Sebastian Kozub on Mar 12, 2014 4:51 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Mar-2014, at 7:52 AM EST
From: Sebastian Kozub
 
Re: Save image from TImage to filesystem [Android]  
News Group: embarcadero.public.delphi.multimedia
> When I use string 'File.png' instead of 'File.bmp' it works perfect ;)
> How can I pass it to have bmp?

You cannot using standard FMX for Android code - if the file extension isn't .png, then the code writes a JPEG file.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Mar-2014, at 4:23 PM EST
From: Chris Rolliston
 
Re: Save image from TImage to filesystem [Android]  
News Group: embarcadero.public.delphi.multimedia
Thanks, now it works...

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 13-Mar-2014, at 4:57 AM EST
From: Sebastian Kozub