2017-07-28 23 views
0

當我從我的應用程序使用相機意圖,然後它打開相機,但點擊它後要求保存圖像,但當我們點擊圖像使用手機相機的應用程序它會自動保存。如何從我的應用程序使用相機意圖時自動保存圖像?

使用相機意圖也打開相同的inbuild相機應用程序,那麼爲什麼雙重行爲?

而且如何讓相機自動保存圖像使用從我的應用程序相機意圖時

+0

? –

回答

0

試試這個

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    //Get Image from Camera 
    if (requestCode == CAMERA_CLICK_RESULT && resultCode == RESULT_OK) { 

     dialog2.dismiss(); 
     Bitmap photo = null; 
     try { 
      photo = MediaStore.Images.Media.getBitmap(
        getContentResolver(), imageUri); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     selectedImage = getResizedBitmap(photo, 900) 


     try { 
      //Write file 
      filename = "your file name.extension"; 
      File file = new File("Directory path where you want to save"); 
      file.mkdir(); 
      FileOutputStream fileOutputStream = new FileOutputStream(file + filename); 
      selectedImage.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream); 

      //Cleanup 
      fileOutputStream.close(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

//Resize Bitmap 
public Bitmap getResizedBitmap(Bitmap image, int maxSize) { 
    int width = image.getWidth(); 
    int height = image.getHeight(); 

    float bitmapRatio = (float) width/(float) height; 
    if (bitmapRatio > 1) { 
     width = maxSize; 
     height = (int) (width/bitmapRatio); 
    } else { 
     height = maxSize; 
     width = (int) (height * bitmapRatio); 
    } 
    return Bitmap.createScaledBitmap(image, width, height, true); 
} 
,你希望它被保存
相關問題