2013-07-30 19 views
6

नीचे मेरा संबंधित code snippet है जहां यह कैमरे से तस्वीर को गोली मारने के बाद डिवाइस के cropping app पर रीडायरेक्ट करता है। मैं आमतौर पर इस example का पालन करता हूं। लेकिन कैमरे से ली गई तस्वीर और फसल ऐप में उपलब्ध कराने के बीच चरण/पल के दौरान, यह लगातार लोडिंग दिखाता है और मेरे ऐप को बहुत ही उत्तरदायी बनाता है। यदि यह कम से कम एक बार होता है, हर बार जब मैं ऐप खोलता हूं, तो यह सिर्फ लोडिंग दिखाता है।कैमरे से लिया गया छवि समस्या फसल

यह समस्या one scenario में नहीं होती है -> जब मैं अपना डिवाइस नहीं लेता (यानी, केवल जब कोई स्क्रीन अभिविन्यास नहीं होता है)। क्या कोई मुझे इस मुद्दे से बचने के लिए सुझाव दे सकता है?

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); 
       } 
    } 

मेरी समस्या को स्पष्ट करने के लिए, मैंने उस उदाहरण में स्रोत कोड चलाया था, वही समस्या होती है। मैंने कुछ अन्य उदाहरण चलाए जो क्रॉपिंग ऐप पर रीडायरेक्ट करते थे। उपरोक्त समझाया चरण के दौरान अभिविन्यास को बदलने के दौरान एक ही समस्या होती है।

पीएस: अगर किसी के पास काम करने का उदाहरण है जो निश्चित रूप से अभिविन्यास परिवर्तनों पर भी काम करता है, तो मुझे इसे उत्तर के रूप में स्वीकार करने में खुशी होगी।

उत्तर

0

जांच imageCaptureUri का मूल्य! = लाइन intent.setData(imageCaptureUri); से पहले अशक्त doCrop()

में संपादित

पहले फ़ाइल में कैमरा परिणाम बचाने के लिए और एप्लिकेशन

intent.setData(Uri.fromFile(new File(path))); 
+0

हाँ, यह circumvents लेकिन यह मेरी समस्या का समाधान नहीं करता है। क्या आपके पास इस मामले में भी कोई अन्य सुझाव और कोई कामकाजी परिदृश्य है। कैमरे का उपयोग कर फोटो लेने के लिए – Kanth

+0

कृपया देखें http://developer.android.com/training/camera/photobasics.html –

1

आप फसल के लिए फ़ाइल पारित इसके साथ जा सकते हैं-

  1. जबकि छवि

  2. एक छोटा बिटमैप बनाने का उपयोग कर संपीड़ित निर्दिष्ट यूआरआई, यानी एक पूर्ण छवि

    photo = android.provider.MediaStore.Images.Media.getBitmap(cr, Uri.fromFile(imageCaptureUri));

  3. उपयोग Bitmap.CompressFormat.PNG का उपयोग कर आकार से बिटमैप मिल

    photo= Bitmap.createScaledBitmap(background, YourWidth, YourHeight, true);

  4. यह आपकी स्केल (क्रॉप) छवि है।

+1

आपके उत्तर के लिए धन्यवाद :) मैं यह कर सकता था। लेकिन मैं उपयोगकर्ताओं को खुद को फसल लगाने की सुविधा देना चाहता हूं। – Kanth

संबंधित मुद्दे