2014-10-18 87 views
0

我得到使用JNI采用Delphi XE7从Android图库位图工作。同样的代码,用Delphi XE6工作:在Image1.Bitmap.Assign(面),我得到一个破碎类错误充分利用通过JNI采用Delphi库中的位图,但没有对德尔福XE7,德尔福XE6

unit home; 

interface 

uses 
    FMX.Platform.Android, Androidapi.Helpers, Androidapi.JNI.App, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNIBridge, 
    FMX.Helpers.Android, Androidapi.JNI.Net, Androidapi.JNI.Provider, Androidapi.JNI.Media, Androidapi.JNI.JavaTypes, 
    System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.Messaging, 
    FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 
    FMX.Objects, FMX.Surfaces, Data.DB, MemDS, DBAccess, MyAccess, Strutils, 
    FMX.Layouts, FMX.Memo; 

type 
    TForm1 = class(TForm) 
    ToolBar1: TToolBar; 
    SpeedButton1: TSpeedButton; 
    Label1: TLabel; 
    Image1: TImage; 
    procedure SpeedButton1Click(Sender: TObject); 
    private 
    { Private declarations } 
    const ScanRequestCode = 0; 
    var FMessageSubscriptionID: Integer; 
    procedure HandleActivityMessage(const Sender: TObject; const M: TMessage); 
    function OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent): Boolean; 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.fmx} 
{$R *.NmXhdpiPh.fmx ANDROID} 

procedure TForm1.SpeedButton1Click(Sender: TObject); 
var 
    Intent: JIntent; 
begin 
    FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification, 
    HandleActivityMessage); 
    Intent := TJIntent.Create; 
    Intent.setAction(TJIntent.JavaClass.ACTION_GET_CONTENT); 
    Intent.setType(StringToJSTring('image/*')); 
    SharedActivity.startActivityForResult(Intent,0); 
end; 

procedure TForm1.HandleActivityMessage(const Sender: TObject; const M: TMessage); 
begin 
    if M is TMessageResultNotification then 
    OnActivityResult(TMessageResultNotification(M).RequestCode, TMessageResultNotification(M).ResultCode, 
     TMessageResultNotification(M).Value); 
end; 

function TForm1.OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent): Boolean; 
var 
    uri: Jnet_Uri; 
    bitmap: JBitmap; 
    surface: TBitmapSurface; 
begin 

    TMessageManager.DefaultManager.Unsubscribe(TMessageResultNotification, FMessageSubscriptionID); 
    FMessageSubscriptionID := 0; 

    if Assigned(Data) then 
    begin 
    try 
     uri:=Data.getData; 
     bitmap := TJImages_Media.JavaClass.getBitmap(SharedActivity.getContentResolver, uri); 
     surface := TBitmapsurface.Create; 
     JBitMapToSurface(bitmap,surface); 
     // Fails here in Delphi XE7 
     //Image1.Bitmap.Assign(surface); 
    finally 
     surface.Free; 
     Result := true; 
    end; 

    end 
    else Result := false; 

end; 

end. 

代码失败。

Delphi XE7中发生了什么变化导致了此错误?

+0

TBitmapsurface应在尝试之前创建.. finally块 – mjn 2014-10-18 12:14:25

+1

什么是确切的错误消息文本? – mjn 2014-10-18 12:15:57

+0

最后和免费电话不需要与ARC – 2014-10-18 12:23:17

回答

0

尝试:

TThread.Syncronize(零, 过程 开始 Image1.Bitmap.Assign(表面); 端 );

+0

谢谢,它的工作原理 – 2015-02-04 21:15:25

+0

它适用于像三星Galaxy S的平板电脑,并在手机上失败,如三星S4。但是,如果应用程序使用Delphi XE6进行编译,则适用于所有设备。用XE7或XE8编译失败。 – 2015-05-20 09:50:05