2016-06-23 57 views
0

在我的應用程序,我必須讓用戶從相機拍照/從畫廊中選擇。 我的代碼在某些設備上工作正常,但是當我在Galaxy s4上運行並且通過攝像頭拍照時,該照片沒有顯示在imageView上(從畫廊中選擇 - 可以正常工作),問題是在Galaxy s4中通過攝像頭拍照時。 我在將圖片顯示在imageView之前縮放了圖片。 這裏是我的代碼拍照:當我拍照時,它不顯示在只有在銀河s4的imageView

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
         File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg"); 
         intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); 
         startActivityForResult(intent, 1); 

這是起飛後的照片我的代碼:

if (requestCode == 1) 
        { 
         File f = new File(Environment.getExternalStorageDirectory().toString()); 
         File image_file = new File(Environment.getExternalStorageDirectory().toString()); 
         for (File temp : f.listFiles()) 
         { 
          if (temp.getName().equals("temp.jpg")) 
          { 
           f = temp;       
           break; 
          } 
         } 
         try 
         { 
          Bitmap bitmap; 
          //BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); 
          //bitmap=decodeFile(f.getAbsolutePath());//Collapse image       
          //setImageOnBitmap(bitmap);//Set the image on the imageview 



          BitmapHandler b=new BitmapHandler(getApplicationContext()); 
          bitmap=b.decodeFileAsPath(f.getAbsolutePath(),"camera"); 
          setImageOnBitmap(bitmap); 




          String path = android.os.Environment 
            .getExternalStorageDirectory() 
            + File.separator 
            + "Phoenix" + File.separator + "default"; 
          f.delete();      
         } 
         catch (Exception e) 
         { 
          e.printStackTrace(); 
         } 
        } 

這是我的函數的圖像文件進行解碼:

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

有錯誤嗎? –

+0

沒有。我檢查它,它只是不顯示圖像沒有錯誤 – Toda

回答

0

我在S4上有類似的問題,這就是爲我解決的問題:

mImageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

希望這會有所幫助。

相關問題