9

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.

brasofilo
  • 25,496
  • 15
  • 91
  • 179
That Marc
  • 1,134
  • 3
  • 19
  • 42
  • 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? http://stackoverflow.com/questions/21200177/taking-pictues-tcameracomponent-on-android-with-delphi-firemonkey-xe5-not-work – That Marc Jan 19 '14 at 18:14
  • 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 Jan 19 '14 at 18:20
  • 2
    @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 http://qc.embarcadero.com/wc/qcmain.aspx?d=118764 and this: http://edn.embarcadero.com/article/43468 – MartynA Jan 19 '14 at 18:36
  • Haven't seen this article while browsing the web :O Thanks. Yet, it's strange since I do have Update 1 indeed... ? – That Marc Jan 19 '14 at 18:42
  • @Just Marc : Sorry I'm no android expert, just noticed you plight in a few qs lately. – MartynA Jan 19 '14 at 18:43
  • @b__ I deleted the other one, since it was a dead end. I'll see if I can get the Update 2 to see whether it will resolve the problem. Too bad that this bug haven't been mentioned anywhere around yet, and then I get the downvote for bringing it up... MartynA thank you for your links. Never got any result from their newsgroup when browsing the web... – That Marc Jan 19 '14 at 18:51
  • 3
    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 Jan 19 '14 at 21:41
  • Actually, I was seeing sample app CameraComponent, that should work as well, but didn't seem to do the trick. However, just putted up XE5 Update 2 and now it seems that it actually does the trick. Now not sure whether I had mistakenly updated to Update 1, or didn't get the correct update at all, but it does work now, so it was a bug in a component itself, as @MartynA provided the link about. I guess the answer is to update to latest. Or is there a way to extract this fix only and apply it to pre-updated version of XE5? If it's a component fix, I guess the component could be replaced, right? – That Marc Jan 19 '14 at 23:54

1 Answers1

2

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;
arghtype
  • 4,376
  • 11
  • 45
  • 60
Diron
  • 21
  • 2