2014-10-27 60 views
1

我實際上是新的android,但我設法與我的應用程序拍照,這是我如何拍照並保存它...問題是我需要調整它之前保存在手機上.. 。但我無法弄清楚如何去..我已經GOOGLE了我的問題,但我發現唯一的東西是位圖圖片,這不是我的情況,我想..如何在android中調整照片大小?

這是我的代碼使用拍攝照片:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),"GUASTO" + System.currentTimeMillis() + ".jpg");/

intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath); 

startActivityForResult(intent, SCATTA_FOTO); 

謝謝!

+0

http://stackoverflow.com/questions/10413659/how-to-resize-image-in -Android – marcel 2014-10-27 14:56:35

回答

0
public static int PIC_CROP=81; 

    Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
       //indicate image type and Uri 
      cropIntent.setDataAndType(ImageUri, "image/*"); 
       //set crop properties 
       //indicate aspect of desired crop 
      cropIntent.putExtra("aspectX", 1); 
      cropIntent.putExtra("aspectY", 1); 
       //indicate output X and Y 
      cropIntent.putExtra("outputX", 640); 
      cropIntent.putExtra("outputY", 640); 
       //retrieve data on return 
      cropIntent.putExtra("return-data", true); 
       //start the activity - we handle returning in onActivityResult 
      startActivityForResult(cropIntent, PIC_CROP); 

和onActivityResult()

@Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 
     if(requestCode==PIC_CROP) 
     { 
      if(resultCode==RESULT_OK) 
      { 
      Bundle extras = data.getExtras(); 
       if (extras != null) {    
        Bitmap bmp = extras.getParcelable("data"); 
        saveCropPhoto(bmp); 
       } 
       Toast.makeText(getApplicationContext(), "picture cropped",Toast.LENGTH_SHORT).show(); 
      } 
     } 

     } 

saveCropPhoto()方法

public void saveCropPhoto(Bitmap bmp) 
     { 
     Toast.makeText(getApplicationContext(), "in save",Toast.LENGTH_SHORT).show(); 
     String dir = Environment.getExternalStorageDirectory().toString() + "/folderName/"; 
     File newdir = new File(dir); 
     newdir.mkdirs(); 
     FileOutputStream out = null; 
     Calendar c = Calendar.getInstance(); 
     String date = fromInt(c.get(Calendar.MONTH)) 
        + fromInt(c.get(Calendar.DAY_OF_MONTH)) 
        + fromInt(c.get(Calendar.YEAR)) 
        + fromInt(c.get(Calendar.HOUR_OF_DAY)) 
        + fromInt(c.get(Calendar.MINUTE)) 
        + fromInt(c.get(Calendar.SECOND)); 
     File imageFileName = new File(newdir, "crop_"+date.toString() + ".jpg"); 
     try 
     { 
     out = new FileOutputStream(imageFileName); 
     bmp.compress(Bitmap.CompressFormat.JPEG, 100, out); 
     out.flush(); 
     out.close(); 
     out = null; 
     if(tempFile.exists()) 
     tempFile.delete(); 
     } catch (Exception e) 
     { 
     e.printStackTrace(); 
     } 
     }