我是Delphi XE的新手,我正在尝试构建一个可以保存相机图像或位图的Android应用。我运行并部署到我的android设备,然后captureButton
从
procedure TForm1.captureButtonClick(Sender: TObject);
然后出现此消息:
java.lang.illegalargumentexception:宽度和高度必须> 0。
这是我的代码:
unit Unit1;
interface
uses
System.IOUtils,System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
Winsoft.Android.ComPort, System.Actions, FMX.ActnList, FMX.Objects, FMX.Media, FMX.Platform,
FMX.StdCtrls,FMX.Helpers.Android,
Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Net, Androidapi.JNI.JavaTypes,
Androidapi.JNI.Telephony,Androidapi.Helpers, FMX.StdActns,
FMX.MediaLibrary.Actions, FMX.Ani, FMX.Effects, IdMessage, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
IdMessageClient, IdSMTPBase, IdSMTP, IdAttachmentFile;
type
TForm1 = class(TForm)
startKamera: TButton;
stopKamera: TButton;
frontKamera: TButton;
backKamera: TButton;
smsButton: TButton;
settingsButton: TButton;
connectButton: TButton;
CameraComponent: TCameraComponent;
kameraView: TImage;
ActionList: TActionList;
AComPort: TAComPort;
Timer: TTimer;
TakePhotoFromCameraAction1: TTakePhotoFromCameraAction;
captureButton: TButton;
ToolBar1: TToolBar;
Label1: TLabel;
dropdown: TSpeedButton;
popup: TRectangle;
ShadowEffect1: TShadowEffect;
popupAnimation: TFloatAnimation;
SMTP: TIdSMTP;
msg: TIdMessage;
Email: TButton;
StyleBook1: TStyleBook;
procedure startKameraClick(Sender: TObject);
procedure stopKameraClick(Sender: TObject);
procedure frontKameraClick(Sender: TObject);
procedure backKameraClick(Sender: TObject);
procedure CameraComponentSampleBufferReady(Sender: TObject;
const ATime: Int64);
procedure smsButtonClick(Sender: TObject);
procedure ComportError(ComPort: TAComPort; E: EComError;
var Action: TComAction);
procedure connectButtonClick(Sender: TObject);
procedure settingsButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure clikdropdown(Sender: TObject);
procedure EmailClick(Sender: TObject);
procedure captureButtonClick(Sender: TObject);
private
{ Private declarations }
procedure AmbilGambar;
procedure SendImage(const Comment, AImage: String);
public
{ Public declarations }
img: TBitmap;
procedure showpopup;
procedure hidepopup;
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.fmx}
procedure TForm1.AmbilGambar;
begin
CameraComponent.SampleBufferToBitmap(kameraView.Bitmap, True);
kameraView.SendToBack;
end;
procedure TForm1.backKameraClick(Sender: TObject);
begin
CameraComponent.Active := False;
CameraComponent.Kind := FMX.Media.TCameraKind.BackCamera;
CameraComponent.Active := True;
hidepopup;
end;
procedure TForm1.CameraComponentSampleBufferReady(Sender: TObject;
const ATime: Int64);
begin
TThread.Synchronize(TThread.CurrentThread, AmbilGambar);
end;
procedure TForm1.captureButtonClick(Sender: TObject);
var
bmp:TBitmap;
begin
//bmp:= kameraView.Bitmap;
//bmp := kameraView.Bitmap;
///bmp.SetSize(200,200);
//bmp.SaveToFile('/sdcard/Pictures/tes.bmp');
kameraView.Bitmap.Create;
kameraView.Bitmap.SetSize(200,200);
//kameraView.Bitmap.Assign(bmp);
kameraView.Bitmap.SaveToFile(GetHomePath+PathDelim+'Documents'+PathDelim+'Pictures'+PathDelim+ 'e.png');
kameraView.Free;
hidepopup;
end;
我该如何解决我的问题?
摆脱这一行:
kameraView.Bitmap.Create;
当您从TImage.Bitmap
属性中读取内容时,它会创建一个TBitmap
(如果尚未创建)的所有者TImage
。Create()
在这种情况下,您无需手动呼叫。仅在创建新TBitmap
变量以分配给自己的变量时,例如:
bmp:= TBitmap.Create;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句