如何找到origID为getThumbnail正与camera.TakePicture照片时 [英] How to find origID for getThumbnail when taking a picture with camera.TakePicture

查看:218
本文介绍了如何找到origID为getThumbnail正与camera.TakePicture照片时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关getThumbnail,android的文件有:

For getThumbnail, the android documentation has:

公共静态位图getThumbnail(ContentResolver的CR,长origId,长的groupId,诠释善良,BitmapFactory.Options选项)

public static Bitmap getThumbnail (ContentResolver cr, long origId, long groupId, int kind, BitmapFactory.Options options)

我完全不知道怎么去origId(在执行getThumbnail原始图像的ID)拍摄图片时Camera.TakePicture

I have absolutely no idea how to get origId (The ID of the original image to perform getThumbnail on) when taking a picture with Camera.TakePicture.

我目前的尝试,根据我读过的各种其他问题是:

My current attempt, based on various other questions I've read is:

String[] projection = { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA };
    String sort = MediaStore.Images.ImageColumns._ID + " DESC";
    Log.d("getting IDs:",sort);
    Cursor myCursor = managedQuery(imagesUri, projection, null, null, sort);
    myCursor.moveToFirst();
    thumbBitmap = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns._ID)), MediaStore.Images.Thumbnails.MINI_KIND, null );

不过,我的日志输出什么应该是实际的ID,然后它给了我在哪里我尝试创建myCursor行空指针异常字符串_ID。

However, my log is outputting the string "_ID" for what should be the actual ID, and it then gives me a null pointer exception on the line where I try and create myCursor.

我也读作回答别人的类似的问题SD卡上的图像没有的有无的标识,在这种情况下,我想origID实际上是一个URI和文档只是搞砸向上?我非常困惑,任何的解释是非常非常受欢迎。

I also read as the answer to somebody else's similar question that images on the SD card don't have IDs, in which case I guess origID would actually be a URI and the docs are just messed up? I am extremely confused, and any explanation would be very very welcome.

推荐答案

我最终没有能够使用getThumbnail,因为我无法找到succsessfully使用路径到图像的位置的任何工作方式,以及(在时间至少,我相信有报道称已提交)它有问题与设备不存储在预期的位置的缩略图。

I ended up not being able to use getThumbnail, as I could not find any working way to use the path to the location of the image succsessfully, and (at the time at least, I believe there have been reports submitted) it had issues with devices not storing their thumbnails in the expected location.

我对这个解决方案最终被我所希望我能够避免,写我自己的小缩略图生成器,而不是使用Android的getThumbnail的。

My solution to this ended up being what I had hoped I could avoid, writing my own little thumbnail generator instead of using Android's getThumbnail.

public class CreateThumbnail extends Activity {
    Bitmap imageBitmap;
    public Bitmap notTheBestThumbnail(String file) {
        byte[] imageData = null;
        try     
        {

            final int THUMBNAIL_SIZE = 95;

            FileInputStream fis = new FileInputStream(file); //file is the path to the image-to-be-thumbnailed.
            imageBitmap = BitmapFactory.decodeStream(fis);
            imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();  
            imageBitmap.compress(Bitmap.CompressFormat.JPEG, 10, baos); //What image format and level of compression to use.
            imageData = baos.toByteArray();

        }
        catch(Exception ex) {
            Log.e("Something did not work", "True");
        }
        return imageBitmap;
    }   
}

我使用的类,如:

I use the class like:

CreateThumbnail thumb = new CreateThumbnail();
thumb.notTheBestThumbnail(Environment.getExternalStorageDirectory() + "/exampleDir" + "/" + exampleVar  + "/example_img.jpg");
Bitmap mBitmap = thumb.imageBitmap; //Assigns the thumbnail to a bitmap variable, for manipulation.

虽然我并没有真正弄清楚如何获得ID,希望这将有助于任何人面临着类似的问题getThumbnail。

While I didn't actually figure out how to get the ID, hopefully this will help anybody facing similar problems with getThumbnail.

这篇关于如何找到origID为getThumbnail正与camera.TakePicture照片时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆