2013-08-12 147 views
2

通过这种方式如何从android相机获取缩略图和图像路径?

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(i, REQUEST_CODE); 

我得到的onActivityResult位图形式的意图,而不是路径!通过这种方式

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); 
startActivityForResult(intent, REQUEST_CODE); 

我可以从意向的路径,而不是位图!!,我怎样才能得到位图(缩略图)和Android相机的路径?

+0

检查这些问题: http://stackoverflow.com/questions/11591825/how-to-get-image-path-just-captured-from-camera http://stackoverflow.com/questions/15322670 /如何获取图像路径从相机意图 http://stackoverflow.com/questions/15432592/get-path-of-image-on-android http://stackoverflow.com/questions/7636697/get-path-and-filename-from-camera-intent-result – akuzma

回答

4

从,你可以得到使用该路径的图片路径创建这样

/** 
* 
* Returns the given size of the bitmap 
* 
* @param path 
* @return {@link Bitmap} 
*/ 
private Bitmap getThumbnailBitmap(String path, int thumbnailSize) { 
    BitmapFactory.Options bounds = new BitmapFactory.Options(); 
    bounds.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(path, bounds); 
    if ((bounds.outWidth == -1) || (bounds.outHeight == -1)) { 
     return null; 
    } 
    int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight 
      : bounds.outWidth; 
    BitmapFactory.Options opts = new BitmapFactory.Options(); 
    opts.inSampleSize = originalSize/thumbnailSize; 
    return BitmapFactory.decodeFile(path, opts); 
} 

缩略图给大小你要多少

+0

mmmmm不错,谢谢你的回答.. :)但是那个thumbnailSize参数怎么样?那是什么 ?它是关于宽度和高度? –

+0

宽度,缩略图的高度.. –

+0

如果我想要100dp x 100dp的图像缩略图,我必须设置什么参数??????????? –

0

试试这个代码,我用这一个应用程序,这将工作完美,

static final int CAMERA_REQUEST = 1888; 
String name = dateToString(new Date(),"yyyy-MM-dd-hh-mm-ss"); 
File destination = new File(Environment.getExternalStorageDirectory(), name + ".jpg"); 
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
destination = new File(Environment.getExternalStorageDirectory(), name + ".jpg"); 
startActivityForResult(cameraIntent, CAMERA_REQUEST); 

在你OnActivityResult()

Bundle bundle = data.getExtras(); 
    if(bundle != null){ 
    if (requestCode == CAMERA_REQUEST) { 
     Bitmap photo = (Bitmap) data.getExtras().get("data"); 

     //Here photo is your bitmap image, use this as per your requirement 
+0

,我们没有获取图像路径? –

+0

我已经编辑了我的答案,请尝试 –

+0

@ RR12您试过上面的答案吗? –

相关问题