hbuilder mui呼び出しシステムトリミング画像、アバタートリミング-android
2573 ワード
head.addEventListener('tap',
function() {
var IMAGE_UNSPECIFIED = "image/*"; //
var PHOTOZOOM = 2; // key
var PHOTOLAT = 1; // key
var main = plus.android.runtimeMainActivity(); //h5+ Activity
var Intent = plus.android.importClass("android.content.Intent");
// java intent importClass
var MediaStore = plus.android.importClass("android.provider.MediaStore");
var File = plus.android.importClass("java.io.File");
var Uri = plus.android.importClass("android.net.Uri");
var intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_UNSPECIFIED);
intent.putExtra("scale", true);
intent.putExtra("scaleUpIfNeeded", true);
var outPutPath = plus.io.convertLocalFileSystemURL("_www/head.jpg");
main.startActivityForResult(intent, PHOTOZOOM);
main.onActivityResult = function(requestCode, resultCode, data) {
if (PHOTOZOOM == requestCode) {
var file = new File(outPutPath);
// uri
var outPutUri = Uri.fromFile(file);
if (data == undefined) {
return false;
}
plus.android.importClass(data);
var uri = data.getData();
var cropIntent = new Intent("com.android.camera.action.CROP"); //
cropIntent.setDataAndType(uri, IMAGE_UNSPECIFIED);
//
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, outPutUri);
cropIntent.putExtra("crop", "true");
//aspectX aspectY
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
// outputX outputY
cropIntent.putExtra("outputX", 70);
cropIntent.putExtra("outputY", 70);
cropIntent.putExtra("return-data", true);
main.startActivityForResult(cropIntent, PHOTOLAT);
} else if (requestCode == PHOTOLAT) {
if (data == undefined) {
return false;
}
var a = new File(outPutPath);
if (!a.exists()) {
console.log(outPutPath);
mui.toast(' ');
return false;
}
img.src = outPutPath;
}
}
});
参考記事
http://ask.dcloud.net.cn/question/8314