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 ...
随机推荐
- hibernate 字段名最好不要使用数据库的保留字
请看如下红色部分,show为mysql的保留字,所以我在hibernate修改show字段值的时候出现错误,原来是show跟mysql的保留字相同了 CREATE TABLE `t_letter` ( ...
- thinkphp多表关联并且分页
$db_prefix = C('DB_PREFIX'); $Model = new Model(); $data = $Model->table("{$db_prefix}ordern ...
- HeadFirst设计模式之单例模式
一. 1.The Singleton Pattern ensures a class has only one instance, and provides a global point of acc ...
- 数据库存储安全之(MD5+盐)加密
一般系统数据库密码加密方式: MD5后存入数据库 SHA1 Hash后存入数据库 缺点:黑客可以通过密码暴力破解获取密码信息,具体做法是将常用密码进行Hash后做成一个字典, 破解的时候,只需要查字典 ...
- linux文件系统-基本磁盘2
直入主题-基本磁盘 硬盘数据按照不同特点和作用大致分为5部分:MBR区.DBR区.FAT区.DIR区和DATA区 1.MBR MBR(Main Boot Record 主引导记录区)位于整个硬盘的0磁 ...
- nagios&pnp4nagios--yum 安装
一. 环境: 1. centos 6.4 2. 设置hostname 并且安装好apache 3. 关闭selinux及iptables 二. 安装nagios服务器端: 1. rpm -Uvh ht ...
- RTL 与 technology schematic的区别,包含概念与实例
2013-06-25 16:40:45 下面是xilinx官网上的问答贴: http://china.xilinx.com/support/answers/41500.htm#solution The ...
- I.MX6 android shutdown 内核崩溃
/**************************************************************************** * I.MX6 android shutdo ...
- 【转】JNI和NDK的区别
原文网址:http://blog.csdn.net/ithomer/article/details/6828830 NDK(Native Development Kit)“原生”也就是二进制 andr ...
- PostgreSql字符串函数和操作符
本节描述了用于检查和操作字符串数值的函数和操作符.在这个环境中的字符串包括所有 character, character varying, text 类型的值.除非另外说明,所有下面列出的函数都可以处 ...