Android实例-操作摄像头(XE8+小米2)

时间:2021-12-31 15:18:48

Android实例-操作摄像头(XE8+小米2)

结果:

1.同样是照相,自己的程序设置为高质量时刷新慢,而小米手机的相机那真心反映快呀。

2.就算我设置为最高质量,可相片也没有小米手机的相片大。我最大是2000*1000,而小米可以做到3000*2000,如果有人问我为什么都是整数,我会K你的。

实例代码:

 unit Unit1;

 interface

 uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects, FMX.Media,
FMX.Platform,//需要引入
system.IOUtils,//需要引入
FMX.Layouts; type
TForm1 = class(TForm)
Label1: TLabel;
Image1: TImage;
GroupBox1: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
GroupBox2: TGroupBox;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
RadioButton5: TRadioButton;
GroupBox3: TGroupBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
CameraComponent1: TCameraComponent;
Timer1: TTimer;
Layout1: TLayout;
RadioButton6: TRadioButton;
RadioButton7: TRadioButton;
RadioButton8: TRadioButton;
RadioButton9: TRadioButton;
GroupBox4: TGroupBox;
RadioButton10: TRadioButton;
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure RadioButton5Change(Sender: TObject);
procedure RadioButton1Change(Sender: TObject);
procedure RadioButton2Change(Sender: TObject);
procedure RadioButton4Change(Sender: TObject);
procedure RadioButton3Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure CameraComponent1SampleBufferReady(Sender: TObject;
const ATime: TMediaTime);
procedure RadioButton6Change(Sender: TObject);
procedure RadioButton7Change(Sender: TObject);
procedure RadioButton9Change(Sender: TObject);
procedure RadioButton8Change(Sender: TObject);
procedure RadioButton10Change(Sender: TObject);
private
//需要定义
function AppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
procedure GetImage;
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} //程序事件处理
function TForm1.AppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
begin
case AAppEvent of
TApplicationEvent.aeWillBecomeInactive: // 当程序将要变为不活动时
CameraComponent1.Active := False;
TApplicationEvent.aeEnteredBackground: // 当程序进入后台时
CameraComponent1.Active := False;
TApplicationEvent.aeWillTerminate: // 当程序将要关闭时
CameraComponent1.Active := False;
end;
end; //打开摄像头
procedure TForm1.Button1Click(Sender: TObject);
begin
CameraComponent1.Active := True;
end; //关闭摄像头
procedure TForm1.Button2Click(Sender: TObject);
begin
CameraComponent1.Active := False;
end; //保存照片
procedure TForm1.Button3Click(Sender: TObject);
begin
Image1.Bitmap.SaveToFile(TPath.GetSharedCameraPath+'/temp.jpg');
showmessage('保存成功!');
end; //从摄像头那里取相片
procedure TForm1.CameraComponent1SampleBufferReady(Sender: TObject;
const ATime: TMediaTime);
begin
GetImage;
end; procedure TForm1.FormCreate(Sender: TObject);
var
AppEventSvc: IFMXApplicationEventService;
begin
//启动一个服务,用来监控摄像头的状态
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(AppEventSvc)) then
AppEventSvc.SetApplicationEventHandler(AppEvent); //AppEvent 为具做事的一个函数
CameraComponent1.Quality := TVideoCaptureQuality.vcPhotoQuality;//设置图像质量
//设置对焦方式
CameraComponent1.FocusMode := TFocusMode.fmContinuousAutoFocus;
end; procedure TForm1.FormResize(Sender: TObject);
begin
if Height < Width then //如果是横屏
Image1.RotationAngle := ;
if Height > Width then //如果是竖屏
if CameraComponent1.Kind = FMX.Media.TCameraKind.ckFrontCamera then//如果是前置摄像头
Image1.RotationAngle := -
else
Image1.RotationAngle := ;
end; //取相片
procedure TForm1.GetImage;
begin
CameraComponent1.SampleBufferToBitmap(Image1.Bitmap, true);
end; //选择摄像头
procedure TForm1.RadioButton1Change(Sender: TObject);
begin
//选择后置摄像头
CameraComponent1.Active := False;
CameraComponent1.Kind := FMX.Media.TCameraKind.ckBackCamera;
CameraComponent1.Active := True;
// 后置时,图像要旋转 90 度,如果是竖屏的话
if Height > Width then
Image1.RotationAngle := ;
end; procedure TForm1.RadioButton2Change(Sender: TObject);
begin
//选择前置摄像头
CameraComponent1.Active := False;
CameraComponent1.Kind := FMX.Media.TCameraKind.ckFrontCamera;
CameraComponent1.Active := True;
//前置时,图像要旋转-90 度,如果是竖屏的话
if Height > Width then
Image1.RotationAngle := -;
end; //如果有闪光灯,打开, ,但在程序运行过程中,看不出什么效果
procedure TForm1.RadioButton3Change(Sender: TObject);
begin
if CameraComponent1.HasFlash then
CameraComponent1.FlashMode := FMX.Media.TFlashMode.fmFlashOn;
end; //如果有闪光灯,关闭,但在程序运行过程中,看不出什么效果
procedure TForm1.RadioButton4Change(Sender: TObject);
begin
if CameraComponent1.HasFlash then
CameraComponent1.FlashMode := FMX.Media.TFlashMode.fmFlashOff;
end; //将闪光灯设置为自动模式
procedure TForm1.RadioButton5Change(Sender: TObject);
begin
if CameraComponent1.HasFlash then
CameraComponent1.FlashMode := FMX.Media.TFlashMode.fmAutoFlash;
end; //相片质量
procedure TForm1.RadioButton6Change(Sender: TObject);
begin
CameraComponent1.Quality := TVideoCaptureQuality.PhotoQuality;
end; //高质量
procedure TForm1.RadioButton7Change(Sender: TObject);
begin
CameraComponent1.Quality := TVideoCaptureQuality.HighQuality;
end; //中等质量
procedure TForm1.RadioButton10Change(Sender: TObject);
begin
CameraComponent1.Quality := TVideoCaptureQuality.CaptureSettings;
end; //低质量
procedure TForm1.RadioButton8Change(Sender: TObject);
begin
CameraComponent1.Quality := TVideoCaptureQuality.MediumQuality;
end; //捕捉设置
procedure TForm1.RadioButton9Change(Sender: TObject);
begin
CameraComponent1.Quality := TVideoCaptureQuality.LowQuality;
end; //刷新得到的摄像头的照片的显示
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Image1.Repaint;
end; end.

Android实例-操作摄像头(XE8+小米2)的更多相关文章

  1. Android实例-手机震动&lpar;XE8&plus;小米2&rpar;

    相关资料:http://blog.csdn.net/laorenshen/article/details/41148843 结果: 1.打开Vibrate权限为True. 2.规律震动我没感觉出来,有 ...

  2. Android实例-LocationSensor位置传感器&lpar;XE8&plus;小米2&rpar;

    结果: 1.启动后有时会闪退,后来重新做的工程就好了.原因不明(可能与地理反码有关). 2.原文是用的GOOGLE地图显示位置,但在咱们这里好像不行,改为百度,但百度用的是HTML文件.太麻烦了,大家 ...

  3. Android实例-MotionSensor加速度&lpar;XE8&plus;小米2&rpar;

    结果: 1. 实例代码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classe ...

  4. Android实例-消息框&lpar;XE8&plus;小米2&rpar;

    方法一支持. 方法二与方法三都是三方单元,功能相同. 方法4与方法5报错,提示平台不支持. 第三方单元一: unit Android.JNI.Toast; // Java bridge class i ...

  5. Android实例-操作sqlite数据库之Grid显示图片&lpar;XE8&plus;小米2&rpar;

    结果: 1.数据库文件,记得打包到程序中(assets\internal\). 操作方法: 1.新建firemonkey mobile application①菜单->File->New- ...

  6. Android实例-操作sqlite数据之自建导航&lpar;XE8&plus;小米2&rpar;

    相关资料: 源文:http://blog.sina.com.cn/s/blog_77691fb90101g9hh.html help://embarcadero.rs_xe5/rad/Mobile_T ...

  7. Android实例-实现扫描二维码并生成二维码&lpar;XE8&plus;小米5&rpar;

    相关资料: 第三方资料太大没法写在博文上,请下载CSDN的程序包. 程序包下载: http://download.csdn.net/detail/zhujianqiangqq/9657186 注意事项 ...

  8. Android实例-调用GOOGLE的TTS实现文字转语音&lpar;XE7&plus;小米2&rpar;&lpar;无图&rpar;

    注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYinYinQi ...

  9. Android实例-调用GOOGLE的TTS实现文字转语音&lpar;XE7&plus;小米2&rpar;&lpar;XE10&period;1&plus;小米5&rpar;

    相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...

随机推荐

  1. ODAC &lpar;odp&period;net&rpar; 从开发到部署

    2013-09-30 16:08 4097人阅读 评论(0) 收藏 举报  分类: Oracle(10)  版权声明:本文为博主原创文章,未经博主允许不得转载. 1. 确定你开发机和服务器的操作系统是 ...

  2. centos7通过yum安装mysql,并授权远程连接

    安装: CentOS 7的yum源中没有正常安装MySQL的mysql-sever文件,需要去官网上下载(通过安装mysql的yum容器,再通过yum安装mysql) 注:安装前,需要卸载所有的mar ...

  3. linux下alias命令详解

    功能说明:设置指令的别名. 语 法:alias[别名]=[指令名称] 形如: alias cp=“cp -i” : 补充说明:用户可利用alias,自定指令的别名.若仅输入alias,则可列出目前所有 ...

  4. HDOJ 1303 Doubles&lpar;简单题&rpar;

    Problem Description As part of an arithmetic competency program, your students will be given randoml ...

  5. 解决Linux文档显示中文乱码问题以及编码转换

    解决Linux文档显示中文乱码问题以及编码转换 解决Linux文档显示中文乱码问题以及编码转换 使vi支持GBK编码 由于Windows下默认编码是GBK,而linux下的默认编码是UTF-8,所以打 ...

  6. 洛谷-烤鸡-BOSS战-入门综合练习1

    题目背景 Background 猪猪hanke得到了一只鸡  题目描述 Description 猪猪Hanke特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke吃鸡很特别,为什么特别呢?因为他有10 ...

  7. Android调用系统自带的文件管理器进行文件选择

    http://blog.csdn.net/zqchn/article/details/8770913的补充 FileUtils文件 public class FileUtils {     publi ...

  8. 001&lowbar;HTTP参数中Etag的重要性

    在研究tornado时,有个Etag比较好奇,从网上查询摘录如下:

  9. &lbrack;LeetCode&rsqb; 99&period; Recover Binary Search Tree&lpar;复原BST&rpar; &star;&star;&star;&star;&star;

    Recover Binary Search Tree leetcode java https://leetcode.com/problems/recover-binary-search-tree/di ...

  10. bootstrap基础学习小记(一)简介模板、全局样式

    2011年,twitter的“一小撮”工程师为了提高他们内部的分析和管理能力,用业余时间为他们的产品构建了一套易用.优雅.灵活.可扩展的前端工具集--BootStrap.Bootstrap由MARK ...