私のアプリケーションでは、ユーザーは Android のカメラまたはギャラリーから画像を選択できます。画像を選択した後、ユーザーは元の画像から円形の画像をトリミングすることもできます。しかし、円を切り取った後、HTC デバイス (エクスプローラーやその他の HTC デバイス) から黒い四角形の画像を取得しています。サムスンのデバイスでは正常に動作します。以下のコードを使用して画像をトリミングしています。
intent.setDataAndType(selectedImage, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("outputX", 96);
intent.putExtra("outputY", 96);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
intent.putExtra("circleCrop", "true");
startActivityForResult(intent, CROP_FROM_CAMERA);
トリミングされた画像を取得する onactivityresult メソッドは次のとおりです。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
Bundle extras = data.getExtras();
Bitmap photo = null;
if (extras != null) {
photo = extras.getParcelable("data");
}
if (photo != null) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, bytes);
byte[] b = bytes.toByteArray();
FileOutputStream out;// = new FileOutputStream(filename);
out = openFileOutput("cropImage.png", Context.MODE_PRIVATE);
out.write(b);
out.close();
pref.edit().putString(PrefernceData.PREF_IMAGE_CROP_URL,"cropImage.png").commit();
Log.i("capute", "success after crop......");
}catch (Exception e) {
Toast.makeText(this, "Can not find image crop app",
Toast.LENGTH_SHORT).show();
}
}
上記のコードで、この行を削除すると:intent.putExtra("circleCrop", "true"); すべての HTC および samsung デバイスの長方形クロップ画像で問題なく動作します。しかし、サークルクロップ画像のみが必要です。この問題を解決するにはどうすればよいですか?