take a picture with camera on android? lazarus / 43-Android ---------------------------------------------------------------------- DelphiFreak · 2013-11-29 18:24 Hi, does someone have a working example on how to take a picture on android? Thanks, Sam ---------------------------------------------------------------------- jmpessoa · 2013-12-14 05:43 Hi, you can try Lazarus Android Module Wizard Please,  see AppDemo2 http://forum.lazarus.freepascal.org/index.php/topic,21919.msg136213/to picseen.html Just for a taste of... *.lfm Code: [Select]object AndroidModule1: TAndroidModule1   OnCreate = DataModuleCreate   OldCreateOrder = False   BackButton = True   Title = 'jForm'   BackgroundColor = colbrBlack   OnActive = DataModuleActive   OnRotate = DataModuleRotate   OnActivityRst = DataModuleActivityRst   OnJNIPrompt = DataModuleJNIPrompt   Height = 513   HorizontalOffset = 424   VerticalOffset = 125   Width = 301   object jPanel1: jPanel     Id = 139436     PosRelativeToAnchor = []     PosRelativeToParent = []     LayoutParamWidth = lpMatchParent     LayoutParamHeight = lpOneFifthOfParent     MarginLeft = 0     MarginTop = 0     MarginRight = 0     MarginBottom = 0     Visible = True     BackgroundColor = colbrLightSteelBlue     left = 16     top = 8   end   object jPanel2: jPanel     Id = 386695     Anchor = jPanel1     PosRelativeToAnchor = [raBelow]     PosRelativeToParent = []     LayoutParamWidth = lpMatchParent     LayoutParamHeight = lpOneThirdOfParent     MarginLeft = 0     MarginTop = 0     MarginRight = 0     MarginBottom = 0     Visible = True     BackgroundColor = colbrLightSlateBlue     left = 16     top = 208   end   object jTextView1: jTextView     Id = 3313746     PosRelativeToAnchor = []     PosRelativeToParent = [rpCenterHorizontal]     LayoutParamWidth = lpWrapContent     LayoutParamHeight = lpWrapContent     MarginLeft = 10     MarginTop = 10     MarginRight = 10     MarginBottom = 10     ParentPanel = jPanel1     Alignment = taLeft     Visible = True     Enabled = True     BackgroundColor = colbrDefault     FontColor = colbrRed     FontSize = 0     Text = 'jPanel And Camera Demo'     left = 80     top = 8   end   object jButton1: jButton     Id = 2882086     Anchor = jTextView1     PosRelativeToAnchor = [raBelow]     PosRelativeToParent = []     LayoutParamWidth = lpMatchParent     LayoutParamHeight = lpWrapContent     MarginLeft = 5     MarginTop = 5     MarginRight = 5     MarginBottom = 5     ParentPanel = jPanel1     Visible = True     BackgroundColor = colbrDefault     Text = 'Take Photo'     FontColor = colbrDefault     FontSize = 0     OnClick = jButton1Click     left = 80     top = 72   end   object jTextView2: jTextView     Id = 0     Anchor = jButton1     PosRelativeToAnchor = []     PosRelativeToParent = [rpBottom, rpRight]     LayoutParamWidth = lpWrapContent     LayoutParamHeight = lpWrapContent     MarginLeft = 10     MarginTop = 10     MarginRight = 10     MarginBottom = 5     ParentPanel = jPanel1     Alignment = taLeft     Visible = True     Enabled = True     BackgroundColor = colbrDefault     FontColor = colbrMidnightBlue     FontSize = 0     Text = 'Panel 1'     left = 80     top = 136   end   object jTextView3: jTextView     Id = 9682626     PosRelativeToAnchor = []     PosRelativeToParent = [rpTop, rpLeft]     LayoutParamWidth = lpWrapContent     LayoutParamHeight = lpWrapContent     MarginLeft = 10     MarginTop = 5     MarginRight = 10     MarginBottom = 5     ParentPanel = jPanel2     Alignment = taLeft     Visible = True     Enabled = True     BackgroundColor = colbrDefault     FontColor = colbrSlateBlue     FontSize = 0     Text = 'Lazarus_Logo'     left = 80     top = 208   end   object jTextView4: jTextView     Id = 5428635     Anchor = jTextView3     PosRelativeToAnchor = [raAlignBaseline, raAlignRight]     PosRelativeToParent = [rpRight]     LayoutParamWidth = lpWrapContent     LayoutParamHeight = lpWrapContent     MarginLeft = 10     MarginTop = 5     MarginRight = 10     MarginBottom = 5     ParentPanel = jPanel2     Alignment = taLeft     Visible = True     Enabled = True     BackgroundColor = colbrDefault     FontColor = colbrMidnightBlue     FontSize = 0     Text = 'Panel 2'     left = 144     top = 208   end   object jCamera1: jCamera     Filename = 'photo1.jpg'     FilePath = fpathDCIM     left = 208     top = 280   end   object jBitmap1: jBitmap     FilePath = fpathDCIM     ImageIndex = -1     Width = 0     Height = 0     left = 144     top = 280   end   object jView1: jView     Id = 0     Anchor = jTextView3     PosRelativeToAnchor = [raBelow]     PosRelativeToParent = []     LayoutParamWidth = lpMatchParent     LayoutParamHeight = lpMatchParent     MarginLeft = 10     MarginTop = 5     MarginRight = 10     MarginBottom = 5     ParentPanel = jPanel2     Visible = True     BackgroundColor = colbrDefault     OnDraw = jView1Draw     left = 80     top = 280   end   object jPanel3: jPanel     Id = 0     Anchor = jPanel2     PosRelativeToAnchor = [raBelow]     PosRelativeToParent = []     LayoutParamWidth = lpMatchParent     LayoutParamHeight = lpMatchParent     MarginLeft = 0     MarginTop = 0     MarginRight = 0     MarginBottom = 0     Visible = True     BackgroundColor = colbrSteelBlue     left = 16     top = 368   end   object jImageView1: jImageView     Id = 0     Anchor = jTextView5     PosRelativeToAnchor = [raBelow]     PosRelativeToParent = []     LayoutParamWidth = lpMatchParent     LayoutParamHeight = lpMatchParent     MarginLeft = 10     MarginTop = 5     MarginRight = 10     MarginBottom = 5     ParentPanel = jPanel3     ImageIndex = -1     Visible = True     BackgroundColor = colbrDefault     IsBackgroundImage = False     left = 80     top = 432   end   object jTextView5: jTextView     Id = 7974229     PosRelativeToAnchor = []     PosRelativeToParent = [rpTop, rpLeft]     LayoutParamWidth = lpWrapContent     LayoutParamHeight = lpWrapContent     MarginLeft = 10     MarginTop = 5     MarginRight = 10     MarginBottom = 5     ParentPanel = jPanel3     Alignment = taLeft     Visible = True     Enabled = True     BackgroundColor = colbrDefault     FontColor = colbrSilver     FontSize = 0     Text = 'jTextView'     left = 80     top = 368   end   object jTextView6: jTextView     Id = 0     Anchor = jTextView5     PosRelativeToAnchor = [raAlignBaseline, raAlignRight]     PosRelativeToParent = [rpRight]     LayoutParamWidth = lpWrapContent     LayoutParamHeight = lpWrapContent     MarginLeft = 10     MarginTop = 5     MarginRight = 10     MarginBottom = 5     ParentPanel = jPanel3     Alignment = taLeft     Visible = True     Enabled = True     BackgroundColor = colbrDefault     FontColor = colbrSilver     FontSize = 0     Text = 'Panel 3'     left = 152     top = 368   end end *.pas Code: [Select]{Hint: save all files to location: C:\adt32\eclipse\workspace\AppDemo2\jni } unit unit1;   {$mode delphi}   interface   uses   Classes, SysUtils, And_jni, And_jni_Bridge, Laz_And_Controls;   type   { TAndroidModule1 }   TAndroidModule1 = class(jForm)       jBitmap1: jBitmap;       jButton1: jButton;       jCamera1: jCamera;       jImageView1: jImageView;       jPanel1: jPanel;       jPanel2: jPanel;       jPanel3: jPanel;       jTextView1: jTextView;       jTextView2: jTextView;       jTextView3: jTextView;       jTextView4: jTextView;       jTextView5: jTextView;       jTextView6: jTextView;       jView1: jView;       procedure DataModuleActive(Sender: TObject);       procedure DataModuleActivityRst(Sender: TObject; requestCode,         resultCode: Integer; jData: jObject);       procedure DataModuleCreate(Sender: TObject);       procedure DataModuleJNIPrompt(Sender: TObject);       procedure DataModuleRotate(Sender: TObject; rotate: integer;         var rstRotate: integer);       procedure jButton1Click(Sender: TObject);       procedure jView1Draw(Sender: TObject; Canvas: jCanvas);     private       {private declarations}       FPhotoExist: boolean;       FSaveRotate: integer;     public       {public declarations}   end;   var   AndroidModule1: TAndroidModule1; implementation   {$R *.lfm} { TAndroidModule1 } procedure TAndroidModule1.DataModuleCreate(Sender: TObject); begin   FPhotoExist:= False;   FSaveRotate:= 1;   //just to fix *.lfm parse fail. Why fail ?   OnJNIPrompt:= DataModuleJNIPrompt;     {<-- delphi mode: do not use '@' !}   OnRotate:= DataModuleRotate;   OnActivityRst:= DataModuleActivityRst;   OnActive:= DataModuleActive; end; procedure TAndroidModule1.DataModuleActivityRst(Sender: TObject; requestCode, resultCode: Integer; jData: jObject); begin    if  resultCode = 0 then ShowMessage('Photo Canceled!')    else if resultCode = -1 then //ok...         begin            FPhotoExist:= True;            jView1.Refresh;            jImageView1.Refresh;         end         else ShowMessage('Photo Fail!'); end; procedure TAndroidModule1.DataModuleActive(Sender: TObject); begin    if Self.Orietation = 2 then   // device is on horizontal...    begin               //reconfigure....       FSaveRotate:= 2;       jPanel1.LayoutParamHeight:=lpMatchParent;       jPanel1.LayoutParamWidth:= lpOneThirdOfParent;       jPanel2.LayoutParamHeight:= lpMatchParent;       jPanel2.LayoutParamWidth:= lpOneThirdOfParent;       jPanel2.PosRelativeToAnchor:= [raToRightOf,raAlignBaseline];       jPanel3.LayoutParamHeight:= lpMatchParent;       jPanel3.LayoutParamWidth:= lpMatchParent;       jPanel3.PosRelativeToAnchor:= [raToRightOf,raAlignBaseline];;       Self.UpdateLayout;     end end; procedure TAndroidModule1.DataModuleJNIPrompt(Sender: TObject); begin   jTextView3.Text:= jCamera1.Filename;   jTextView5.Text:= jCamera1.Filename;   Self.Show; end; procedure TAndroidModule1.jButton1Click(Sender: TObject); begin   jCamera1.TakePhoto; end; procedure TAndroidModule1.jView1Draw(Sender: TObject; Canvas: jCanvas); var   ratio: integer; begin     if FPhotoExist then     begin        //jTextView3.Text:= jCamera1.FullPathToBitmapFile;        jBitmap1.LoadFromFile(jCamera1.FullPathToBitmapFile);        if FSaveRotate = 2 then        begin           Ratio:= Round(jBitmap1.Width/jBitmap1.Height);           jView1.Canvas.drawBitmap(jBitmap1, 0, 0,                                              jView1.Width,                                              Round((jView1.Width)*(1/Ratio)));        end        else        begin          Ratio:= Round(jBitmap1.Height/jBitmap1.Width);          jView1.Canvas.drawBitmap(jBitmap1, 0, 0,                                             jView1.Height,                                             Round((jView1.Height)*(1/Ratio)));        end;        { //or you can do simply this...        jView1.Canvas.drawBitmap(jBitmap1, 0, 0,                                 jView1.Width,                                 jView1.Height);        }        //just to ilustration.... you can draw or write over draw....        jView1.Canvas.setColor(colbrRed);        jView1.Canvas.drawLine(0, 0, jView1.Width, jView1.Height);        jView1.Canvas.drawText('Hello People!', 30,30);        //or simply this other control...        jImageView1.SetImageBitmap(jBitmap1.GetJavaBitmap);     end; end; {rotate=1 --> device is on  vertical/default position; rotate=2 device is on horizontal position} procedure TAndroidModule1.DataModuleRotate(Sender: TObject; rotate: integer; var rstRotate: integer); begin    FSaveRotate:=  rotate;    if rotate = 2 then   //after rotation device is on horizontal    begin       jPanel1.LayoutParamHeight:=lpMatchParent;       jPanel1.LayoutParamWidth:= lpOneThirdOfParent;       jPanel2.LayoutParamHeight:= lpMatchParent;       jPanel2.LayoutParamWidth:= lpOneThirdOfParent;       jPanel2.PosRelativeToAnchor:= [raToRightOf,raAlignBaseline];       jPanel3.LayoutParamHeight:= lpMatchParent;       jPanel3.LayoutParamWidth:= lpMatchParent;       jPanel3.PosRelativeToAnchor:= [raToRightOf,raAlignBaseline];;     end     else {1} //after rotation device is on vertical :: default     begin       jPanel1.LayoutParamHeight:= lpOneFifthOfParent;       jPanel1.LayoutParamWidth:= lpMatchParent;       jPanel2.LayoutParamHeight:= lpOneThirdOfParent;       jPanel2.LayoutParamWidth:= lpMatchParent;       jPanel2.PosRelativeToAnchor:= [raBelow];       jPanel3.LayoutParamHeight:= lpMatchParent;       jPanel3.PosRelativeToAnchor:= [raBelow];     end;     Self.UpdateLayout; end; end. Some picture on attachments, just to illustration... Greetings