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)的更多相关文章
- Android实例-手机震动(XE8+小米2)
相关资料:http://blog.csdn.net/laorenshen/article/details/41148843 结果: 1.打开Vibrate权限为True. 2.规律震动我没感觉出来,有 ...
- Android实例-LocationSensor位置传感器(XE8+小米2)
结果: 1.启动后有时会闪退,后来重新做的工程就好了.原因不明(可能与地理反码有关). 2.原文是用的GOOGLE地图显示位置,但在咱们这里好像不行,改为百度,但百度用的是HTML文件.太麻烦了,大家 ...
- Android实例-MotionSensor加速度(XE8+小米2)
结果: 1. 实例代码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classe ...
- Android实例-消息框(XE8+小米2)
方法一支持. 方法二与方法三都是三方单元,功能相同. 方法4与方法5报错,提示平台不支持. 第三方单元一: unit Android.JNI.Toast; // Java bridge class i ...
- Android实例-操作sqlite数据库之Grid显示图片(XE8+小米2)
结果: 1.数据库文件,记得打包到程序中(assets\internal\). 操作方法: 1.新建firemonkey mobile application①菜单->File->New- ...
- Android实例-操作sqlite数据之自建导航(XE8+小米2)
相关资料: 源文:http://blog.sina.com.cn/s/blog_77691fb90101g9hh.html help://embarcadero.rs_xe5/rad/Mobile_T ...
- Android实例-实现扫描二维码并生成二维码(XE8+小米5)
相关资料: 第三方资料太大没法写在博文上,请下载CSDN的程序包. 程序包下载: http://download.csdn.net/detail/zhujianqiangqq/9657186 注意事项 ...
- Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(无图)
注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYinYinQi ...
- Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)
相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...
随机推荐
- [Unity菜鸟] 材质
1. 材质定义: 2. 把材质都改成支持透明通道 因为物体太多了,比如树跟房子材质必须用不一样的.所以办法还是你得改每个材质的Shader,都改成支持透明通道的. 在Project的搜索窗口输入t: ...
- vmware tools安装程序无法继续,Microsoft Runtime DLL安装程序未能完成安装。的解决方法
vmware tools安装程序无法继续,Microsoft Runtime DLL安装程序未能完成安装.的解决方法_华英雄_新浪博客 http://blog.sina.com.cn/s/blog_5 ...
- POJ3259——Wormholes(Bellman-Ford+SPFA)
Wormholes DescriptionWhile exploring his many farms, Farmer John has discovered a number of amazing ...
- SVN使用方法总结
SVN使用方法 SVN版本管理模式:http://www.cnblogs.com/newstar/archive/2011/01/04/svn.html (集中式-trunk和分散式-branch ...
- 程序员的自我修养(2)——计算机网络(转) good
相关文章:程序员的自我修养——操作系统篇 几乎所有的计算机程序,都会牵涉到网络通信.因此,了解计算机基础网络知识,对每一个程序员来说都是异常重要的. 本文在介绍一些基础网络知识的同时,给出了一些高质量 ...
- GCC编译警告和错误
1 error: expected expression before 'else' else之前无表达式. 2 error: lvalue required as left operand of a ...
- “WIZnet杯”以太网技术竞赛即将开始!
- [置顶] Maven多模块项目 eclipse热部署 Maven项目实现 tomcat热部署 二
最近看到有好多童鞋比较热衷热部署,特别是多模块的项目,其实这热部署如果多模块比较大资源,容易内存溢出或者电脑卡住,并不建议这么做. 不过了解下也没有关系,这里我就在说说热部署的另外一种方法,因为我之前 ...
- MySQL 普通索引、唯一索引和主索引
1.普通索引 普通索引(由关键字KEY或INDEX定义的索引)的唯一任务是加快对数据的访问速度.因此,应该只为那些最经常出现在查询条件(WHEREcolumn=)或排序条件(ORDERBYcolumn ...
- poj 3126 Prime Path( bfs + 素数)
题目:http://poj.org/problem?id=3126 题意:给定两个四位数,求从前一个数变到后一个数最少需要几步,改变的原则是每次只能改变某一位上的一个数,而且每次改变得到的必须是一个素 ...