2012-03-14 15 views
12

मैं एक तस्वीर कैप्चर करने के लिए कैमरा इरादा का उपयोग कर रहा हूं। यह मेरा कोड है और यह बहुत अच्छा काम करता है:कैमरा इरादा छोटी तस्वीर

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); 
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 

मेरी onActivityResult इस तरह दिखता है:

if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { 
    if (resultCode == RESULT_OK) { 
     Bundle extras = data.getExtras(); 
     Bitmap photo = (Bitmap) extras.get("data"); 
    } 
} 

समस्या यह है, कि जब तक तस्वीर कैमरे से ली गई है 480 * 800 (मैं उपयोग कर रहा हूँ एचटीसी डिजायर), बिटमैप लौटा केवल 1 9 4 * 324 है!

कोई विचार क्यों ऐसा होता है और इसे कैसे हल किया जाए?

धन्यवाद!

उत्तर

10

जब आप अतिरिक्त से Bitmap पढ़ने का उपयोग पूर्ण छवि का आकार How to capture an image and store it with the native Android Camera


प्राप्त करने के लिए इस जवाब को पढ़ने, आप छवि

+0

मैंने इसका पीछा किया था और मैं छवि को गैलरी में स्टोर करने में सफल नहीं हूं। लेकिन छवि खराब गुणवत्ता वाली छवि के साथ भी संग्रहीत .. अच्छी गुणवत्ता कैसे प्राप्त करें? – Kasnady

0

यदि हम कैमरा गतिविधि से उच्च गुणवत्ता वाली छवि का उत्पादन करना चाहते हैं तो हम नहीं करते हैं 'टी एक विकल्प है, लेकिन यह फाइल में सहेज लें और फिर उपयोग करने के लिए:

  1. तो सबसे पहले पहले के रूप में हम एक स्थिर पूर्णांक है कि हमारे requestCode हो जाएगा बनाने की जरूरत:

सार्वजनिक स्थिर अंतिम int CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE = 1777;

  1. अगला हम फिर से आशय आग परिणाम के लिए गतिविधि शुरू करने के लिए:

आशय आशय = नए आशय ("android.media.action.IMAGE_CAPTURE"); फ़ाइल फ़ाइल = नई फ़ाइल (पर्यावरण .getExternalStorageDirectory() + File.separator + "image.jpg"); intent.putExtra (MediaStore.EXTRA_OUTPUT, Uri.fromFile (फ़ाइल)); startActivityForResult (इरादा, CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE);

यहां हम वास्तव में छवि को बचाने के लिए इरादे के अतिरिक्त एक यूआरआई पास कर रहे हैं।

  1. अंत में हम onActivityResult में परिणाम प्राप्त होगा:

     protected void onActivityResult(int requestCode, int resultCode, Intent data) 
         { 
          //Check that request code matches ours: 
          if (requestCode == CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE) 
          { 
           //Get our saved file into a bitmap object: 
    
           File file = new File(Environment.getExternalStorageDirectory()+File.separator + 
         "image.jpg"); 
           Bitmap bitmap = decodeSampledBitmapFromFile(file.getAbsolutePath(), 1000, 700); 
          } 
        } 
    

decodeSampledBitmapFromFile विधि है:

public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight) 
{ // BEST QUALITY MATCH 

    //First decode with inJustDecodeBounds=true to check dimensions 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(path, options); 

    // Calculate inSampleSize, Raw height and width of image 
    final int height = options.outHeight; 
    final int width = options.outWidth; 
    options.inPreferredConfig = Bitmap.Config.RGB_565; 
    int inSampleSize = 1; 

    if (height > reqHeight) 
    { 
     inSampleSize = Math.round((float)height/(float)reqHeight); 
    } 
    int expectedWidth = width/inSampleSize; 

    if (expectedWidth > reqWidth) 
    { 
     //if(Math.round((float)width/(float)reqWidth) > inSampleSize) // If bigger SampSize.. 
     inSampleSize = Math.round((float)width/(float)reqWidth); 
    } 

    options.inSampleSize = inSampleSize; 

    // Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 

    return BitmapFactory.decodeFile(path, options); 
} 

लिए प्रासंगिक कैमरा अनुमतियां जोड़ने मेनिफेस्ट फ़ाइल:

<uses-permission android:name="android.permission.CAMERA" /> 
<uses-feature android:name="android.hardware.camera" /> 
<uses-feature android:name="android.hardware.camera.autofocus" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

आशा है कि यह समाधान के लिए सर्चिंग करने में किसी की भी मदद करेगा। क्योंकि यह मेरे लिए 100% काम किया।

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