Dưới đây là số code snippet
liên quan của chúng tôi trong đó chuyển hướng đến thiết bị cropping app
sau khi ảnh được chụp từ máy ảnh. Tôi thường theo dõi số example này. Nhưng trong giai đoạn/thời điểm giữa hình ảnh được chụp từ máy ảnh và làm cho có sẵn trong ứng dụng cây trồng, nó cho thấy liên tục tải và làm cho ứng dụng của tôi khủng khiếp không phản hồi. Nếu điều này xảy ra ít nhất một lần, mỗi khi tôi mở ứng dụng, nó chỉ hiển thị tải.Vấn đề về hình ảnh cắt ảnh khi chụp từ camera
Sự cố này không xảy ra trong one scenario
-> Khi tôi không di chuyển thiết bị của mình (nghĩa là, chỉ khi không có hướng màn hình nào xảy ra). Có thể một số đề nghị tôi để tránh vấn đề này?
public void shotFromCamera(View view)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageCaptureUri);
try {
intent.putExtra("return-data", true);
startActivityForResult(intent, PICK_FROM_CAMERA);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
protected void onActivityResult(int requestCode, int resultCode,Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && requestCode == PICK_FROM_CAMERA){
doCrop();
} else if(resultCode == RESULT_OK && requestCode == CROP_FROM_CAMERA)
{
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photoBitmap = extras.getParcelable("data");
imageView.setImageBitmap(photoBitmap);
if(mImageCaptureUri != null)
{
File f = new File(mImageCaptureUri.getPath());
if (f.exists()) f.delete();
}
mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+ "/MyApp",
"avatar" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
File file = new File(mImageCaptureUri.getPath());
selectedImagePath = mImageCaptureUri.getPath();
Log.d("pic1 ","pic to be created: "+selectedImagePath);
OutputStream fOut = null;
try {
fOut = new FileOutputStream(file);
photoBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(IOException e)
{
e.printStackTrace();
}
}
}
}
private void doCrop() {
final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0);
int size = list.size();
if (size == 0) {
Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
return;
} else {
intent.setData(imageCaptureUri);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
if (size == 1) {
Intent i = new Intent(intent);
ResolveInfo res = list.get(0);
i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
startActivityForResult(i, CROP_FROM_CAMERA);
}
}
Để làm rõ vấn đề của mình, tôi đã chạy mã nguồn trong ví dụ đó, vấn đề tương tự cũng xảy ra. Tôi đã chạy một vài ví dụ khác chuyển hướng đến ứng dụng cắt xén. Cùng một vấn đề xảy ra trong khi thay đổi định hướng trong giai đoạn được giải thích ở trên.
P.S: Nếu ai đó có ví dụ làm việc chắc chắn hoạt động ngay cả khi thay đổi hướng, tôi rất vui khi chấp nhận câu trả lời.
Có, nó phá vỡ nhưng nó không giải quyết được vấn đề của tôi. Bạn có bất cứ đề xuất nào khác và bất kỳ kịch bản làm việc nào ngay cả trong trường hợp này. – Kanth
để chụp ảnh bằng máy ảnh, vui lòng xem http://developer.android.com/training/camera/photobasics.html –