SkImageDecoder :: Factory返回null,当我从sqlite显示图像时

时间:2014-12-09 02:46:36

标签: android sqlite

在我的项目中我想将图像存储在DB Sqlite中,但是当我想显示图像时我有问题,请帮助我,这是我选择图像的代码:

public void bt_UFotoClick(View v)
{
    v = Img;

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_PICTURE);
}

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
   if(requestCode == 1)
   {
       if (requestCode == SELECT_PICTURE) {
           Uri selectedImageUri = intent.getData();
           String selectedImagePath = getPath(selectedImageUri);
           System.out.println("Image Path : " + selectedImagePath);
           imageDetail.setVisibility(View.VISIBLE);
           imageDetail.setImageURI(selectedImageUri);

           SQLiteDatabase dbUpdate = dbHelper.getWritableDatabase();
           byte[] byteImage1 = null;

           try {
               FileInputStream instream = new FileInputStream(selectedImagePath);
               BufferedInputStream bif = new BufferedInputStream(instream);
               byteImage1 = new byte[bif.available()];
               bif.read(byteImage1);
               dbUpdate.execSQL("update m_item set image = '"+byteImage1+"' where kd='"+Code_I+"'");

               System.out.println("Success. ");
               System.out.println("Success. " +byteImage1);
           } catch (IOException e) {
               System.out.println("Error. "+e.getMessage()); 
           }

       }

       else if (resultCode == RESULT_CANCELED)
       {

       }

   }
}


@SuppressWarnings("deprecation")
public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

再次显示图像我使用此代码:

SearchDetail = db.rawQuery("SELECT * FROM m_item where kd = '"+GetId+"'",null);
    if(SearchDetail .getCount()>=1) { 
        SearchDetail .moveToFirst();

        byte GBR_II[]= SearchDetail.getBlob(SearchDetail.getColumnIndex("image"));

        imageDetail.setImageBitmap(BitmapFactory.decodeByteArray(GBR_II, 0,GBR_II.length));
        System.out.println("get : "+GBR_II);
     }

但是图片没有显示并且在logcat中:12-09 02:28:50.977:D / skia(561):--- SkImageDecoder :: Factory返回null

谢谢,

0 个答案:

没有答案