android 4.3 그림 선택 "그림을 불러올 수 없습니다"
7208 단어 테크니컬
//
4
private void getAlbum() {
String intentactiong = "";
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {//4.4
intentactiong = Intent.ACTION_PICK;
} else {//4.4
intentactiong = Intent.ACTION_GET_CONTENT;
}
Intent openAlbumIntent = new Intent(intentactiong);
openAlbumIntent.setDataAndType(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
startActivityForResult(openAlbumIntent, FLAG_SELECT_PHOE);
}
다음은 그림을 캡처하는 방법입니다. 두 버전의 그림은 선택 경로가 다르기 때문에 서로 다른 버전 시스템에 맞게 그림을 주동적으로 저장했습니다.// public void cropImage(Uri uri, int outputX, int outputY, int requestCode) { if (uri != null) { Intent intent = new Intent("com.android.camera.action.CROP"); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {//4.4
// String fileName = String.valueOf(System.currentTimeMillis()) + ".png"; SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("tempName", fileName); editor.commit();
// Uri Uri imageUri = Uri.fromFile(new File(Environment .getExternalStorageDirectory(), fileName)); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); } intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("outputX", outputX); intent.putExtra("outputY", outputY); intent.putExtra("outputFormat", "PNG"); intent.putExtra("noFaceDetection", true); intent.putExtra("return-data", true); startActivityForResult(intent, requestCode); } }
onactivityresult
onActivityResult
Uri uri = null; if (data != null) { uri = data.getData(); System.out.println("Data"); } else { System.out.println("File"); String fileName = getSharedPreferences("temp", Context.MODE_PRIVATE).getString("tempName", ""); uri = Uri.fromFile(new File(Environment .getExternalStorageDirectory(), fileName)); } try { Bitmap bitmaps = MediaStore.Images.Media.getBitmap( this.getContentResolver(), uri); img_1.setImageBitmap(bitmaps); } catch (IOException e) { e.printStackTrace(); } cropImage(uri, PHOTOSIZE, PHOTOSIZE, FLAG_CROP_PHONE);
소스 코드 추가https://github.com/longyuan02/Interceptpictures
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
golang에서 대상 방법을 함수 지침으로 삼다누드 함수 를 지침 으로 삼는 것 은 그리 신기한 일 이 아니다. 다른 언어 도 괜찮다. 골롱 도 당연히 가능하다. 예를 들면 그러나 아래와 같이 대상의 실례적인 방법은 함수 매개 변수로 전달될 수 있습니까? 답은 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.