如何将缩略图位图转换为Uri?

时间:2015-12-13 19:40:31

标签: android sqlite video bitmap thumbnails

我正在尝试将Uri视频存储在我的数据库中以便我可以将其作为缩略图,我已成功将其转换为位图但我似乎无法获得该位图的Uri以便我可以显示视频缩略图我的列表在后端使用光标。 以下行显示由空值提供的错误。

Uri Uri1= Uri.parse(path);\\from__NEWS_Feedoverlay---class

请查看以下代码片段

------------------------来自助手类的XXXXXXXXXXMethod ------------------- -------------------------------------------------- ---

public Cursor getCursor()
{
    String where=null;
    db= this.getReadableDatabase();
    //db.rawQuery("select image , name from images",null);
    //Cursor cursor = db.rawQuery("select _id, name from images",null);
    Cursor cursor= db.query(true,TABLE_Images,KEY,where,null,null,null,null,null,null);
    if (cursor!=null)
    {
        cursor.moveToFirst();

    }
    return cursor;

------------------------------ XXXXXXXXXXXX - NEWS_Feedoverlay ---类--------- ------------

Cursor cursor = helper.getCursor();
        startManagingCursor(cursor);
        //setup for MApping in view fields
        Uri myUri= Uri.parse(helper.KEY_IMAGE);
      // Uri Uri1=  MediaStore.Video.Thumbnails.getContentUri(helper.KEY_FILE);
       Bitmap bMap = ThumbnailUtils.createVideoThumbnail(helper.KEY_FILE, MediaStore.Video.Thumbnails.MICRO_KIND);

        String path = MediaStore.Images.Media.insertImage(getContentResolver(), bMap, "Title", null);
        Uri Uri1= Uri.parse(path);
       // ContentResolver crThumb = getContentResolver();

        //Bitmap bitmap =MediaStore.Video.Thumbnails.getThumbnail(crThumb, Long.parseLong(helper.KEY_FILE),MediaStore.Video.Thumbnails.MICRO_KIND,null);

        String [] fromFieldNames=new String[]{helper.KEY_NAME, String.valueOf(Uri1)};


        int[] toViewID= new int[]{R.id.title,R.id.list_video};
        SimpleCursorAdapter myadaptor= new SimpleCursorAdapter(this, R.layout.list_row, cursor,fromFieldNames,toViewID );
        ListView mylist= (ListView)findViewById(R.id.list);
        mylist.setAdapter(myadaptor);

------------------------------ logcat的---------------- ------------

FATAL EXCEPTION: main
                                                                              Process: com.example.sanya.ar_expeditor, PID: 2675
                                                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sanya.ar_expeditor/com.example.sanya.ar_expeditor.NewsFeed_Viewoverlay}: java.lang.NullPointerException: uriString
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:156)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:211)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5371)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
                                                                               Caused by: java.lang.NullPointerException: uriString
                                                                                  at android.net.Uri$StringUri.<init>(Uri.java:475)
                                                                                  at android.net.Uri$StringUri.<init>(Uri.java:465)
                                                                                  at android.net.Uri.parse(Uri.java:437)
                                                                                  at com.example.sanya.ar_expeditor.NewsFeed_Viewoverlay.onCreate(NewsFeed_Viewoverlay.java:48)
                                                                                  at android.app.Activity.performCreate(Activity.java:5990)
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:156) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:211) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5371) 
                                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740) 

也许是我将视频uri转换为缩略图的方式,但无论哪种方式都是相同的错误..我已经按照以下链接有人知道究竟是什么错误n如何把它正确.. ???谢谢... How to get the video thumbnail path, and not the bitmap Android: Is it possible to display video thumbnails?

0 个答案:

没有答案