8
votes

Has anyone been able to take pictures from camera on Android from within the app written in Delphi Firemonkey XE5? How about the video capture?

This is believed to be either a bug in a framework or just something with missing documentation about it.

Can anyone tell why the code bellow doesn't work / retrieve any image from a camera on Android?

Dropped a TCameraComponent on a form, and a TImage component as well, and nothing happens.

procedure TCameraComponentForm.OnCreate(Sender: TObject);
begin
  CameraComponent1.Kind := FMX.Media.TCameraKind.ckFrontCamera;
  CameraComponent1.FlashMode := FMX.Media.TFlashMode.fmFlashOff;
  CameraComponent1.Active := True;
end;

procedure TCameraComponentForm.CameraComponent1SampleBufferReady(
  Sender: TObject; const ATime: Int64);
begin
  CameraComponent1.SampleBufferToBitmap(Image1.Bitmap, True);
  Image1.Width := Image1.Bitmap.Width;
  Image1.Height := Image1.Bitmap.Height;
end;

Permissions are set correctly.

1
Now why is that a down-voted question? Is it forbidden to ask if people managed to do something just in order to know if it's even possible, or should I always put some code in a question? Because as for the camera and code about it, I already opened a thread yesterday, but got no replies, so now I want to know if it's even possible? stackoverflow.com/questions/21200177/… - That Marc
As stated above, the concrete programming question was made on a thread linked above. Since there were no concrete programming comment, answer nor opinion shared there, I putted up a non-concrete, yet still programming question, which I believe actually is useful to know the answer to. But if what you're trying to say is that Stack Overflow is not for basic stuff, (even though the camera thing isn't basic at all, especially if it's believed to be serious problem or bug in a framework) or for beginners, say it that way. Sometimes that's the feeling I get about it... :/ - That Marc
@Just Marc : I think that people often just pass by questions which contain no code. You might want to have a look in EMBA's delphi/android newsgroup. It contains a post about camera problems which mentions this Quality Central post qc.embarcadero.com/wc/qcmain.aspx?d=118764 and this: edn.embarcadero.com/article/43468 - MartynA
Haven't seen this article while browsing the web :O Thanks. Yet, it's strange since I do have Update 1 indeed... ? - That Marc
You did see the sample app that takes a picture in C:\Users\Public\Documents\RAD Studio\12.0\Samples\MobileCodeSnippets\AccessCameraApp, right? - Ken White

1 Answers

2
votes

This code works fine:

procedure TfrmPrincipal.SampleBufferSync;
begin
  cmcPrincipal.SampleBufferToBitmap(imgFoto.Bitmap, true);
end;

procedure TfrmPrincipal.cmcPrincipalSampleBufferReady(Sender: TObject;
  const ATime: Int64);
begin
  TThread.Synchronize(TThread.CurrentThread, SampleBufferSync);
//  CameraComponent1.SampleBufferToBitmap(imgFoto.Bitmap, True);
//  imgFoto.Width := imgFoto.Bitmap.Width;
//  imgFoto.Height := imgFoto.Bitmap.Height;
end;

procedure TfrmPrincipal.FormShow(Sender: TObject);
begin
  cmcPrincipal.Kind := FMX.Media.TCameraKind.ckBackCamera;
  try
    cmcPrincipal.FlashMode := FMX.Media.TFlashMode.fmFlashOff;
  except

  end;
  cmcPrincipal.Active := True;
end;