Last active
August 29, 2015 14:20
-
-
Save freeonterminate/6c8488eebd9125e87b6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit JavaSample; | |
interface | |
uses | |
Androidapi.JNI.GraphicsContentViewText; | |
function SaveJavaBitmapToFile( | |
const iSrc: JBitmap; // JBitmap は android.graphics.Bitmap です。同様に接頭辞 J で始まる物は全部 Java のクラスです | |
const iFileName: String): Boolean; | |
implementation | |
uses | |
System.SysUtils | |
, System.IOUtils | |
, Androidapi.Jni | |
, Androidapi.JNI.JavaTypes | |
, Androidapi.Helpers | |
, FMX.Types | |
; | |
function SaveJavaBitmapToFile( | |
const iSrc: JBitmap; | |
const iFileName: String): Boolean; | |
var | |
PngFile: JFile; | |
OS: JOutputStream; | |
begin | |
Result := False; | |
// TJFile は java.io.File を表し、init でインスタンスを生成しています | |
// ちなみに Java 側クラスは Interface で実装されているので Delphi なのに自動解放されます | |
PngFile := TJFile.JavaClass.init(StringToJString(iFileName)); | |
OS := TJFileOutputStream.JavaClass.init(PngFile); // こちらも同様に java.io.FileOutpoutStream を生成しています | |
try | |
try | |
iSrc.compress(TJBitmap_CompressFormat.JavaClass.PNG, 100, OS); // シームレスに Java のメソッドを呼び出せます | |
Result := True; | |
except on E: Exception do | |
Log.d('Error: ' + E.Message); | |
end; | |
finally | |
OS.close; | |
end; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment