내 응용 프로그램에서 나는 카메라에서 이미지를 얻고 있습니다. 이 코드는 대부분의 장치에서 완전히 작동하지만 sumsung galaxy grand quattro 응용 프로그램에서 테스트 할 때 충돌이 발생했습니다.
내 시도는 다음과 같습니다.
if(resultCode == RESULT_OK) {
Bitmap photo = (Bitmap)data.getExtras().get("data");
try {
resized = Bitmap.createScaledBitmap(photo, 200, 200, true);
final_image = Bitmap.createScaledBitmap(photo, 200, 200, true);
} catch(Exception e) {
Toast.makeText(getApplicationContext(), "Failed To Load ", 5000).show();
}
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if(currentapiVersion >= android.os.Build.VERSION_CODES.KITKAT) {
Bitmap blurredBitmap = BlurBuilder.blur(getApplicationContext(), resized);
BitmapDrawable ob = new BitmapDrawable(getResources(), blurredBitmap);
ll.setBackground(ob);
} else {
Bitmap blur = BitmapFactory.decodeResource(getResources(), R.drawable.blurback);
BitmapDrawable ob = new BitmapDrawable(getResources(), blur);
ll.setBackground(ob);
}
try {
Bitmap circleimg = getCircularBitmapWithWhiteBorder(resized, 2);
iv.setImageBitmap(circleimg);
final_image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String encodedImageString = Base64.encodeToString(b, Base64.DEFAULT);
imgpath = encodedImageString;
} catch(Exception e) {
}
}
노트 :
I tasted my app in
complite 작업의 위 장치
LogCat :
java.lang.RuntimeException: Unable to resume activity {com.example.camera/com.example.camera.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/50298 (has extras) }} to activity {com.example.camera/com.example.camera.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2643)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2671)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.access$700(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/50298 (has extras) }} to activity {com.example.camera/com.example.camera.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3209)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2630)
... 12 more
Caused by: java.lang.NullPointerException
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:490)
at com.example.camera.MainActivity.onActivityResult(MainActivity.java:93)
at android.app.Activity.dispatchActivityResult(Activity.java:5387)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
... 13 more
충돌의 이유는 데이터가 null이기 때문입니다. 이는 일부 장치에서 발생하며 대신 콘텐츠 제공 업체를 사용합니다. 데이터에는 읽을 수있는 경로가 포함됩니다.
Bitmap photo;
if(data.getData() == null) {
photo = (Bitmap)data.getExtras().get("data");
} else {
photo = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
}
그것은 당신을 위해 일할 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다