无法将高分辨率图像保存为blob的sqlite数据库

时间:2014-08-30 08:38:19

标签: android sqlite bitmap image-scaling

是否可以将大图像保存到数据库?如果不是,是否有更有效的方法可以将图像保存到我的sqlite数据库?我可以在我的数据库中保存和检索低于1mb的图像存储,但是如果它超过了那个,当我尝试保存它时应用程序崩溃。

这是我的代码:

       @Override
    public void onActivityResult( int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == Activity.RESULT_OK){
            Uri targetUri = data.getData();
            picture_location = targetUri.toString();
            textTargetUri.setText(targetUri.toString());
            Bitmap bitmap;
            try {

                bitmap = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(targetUri));  
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
                byte[] byteArray = stream.toByteArray();
                loginDataBaseAdapter.insertPhoto(byteArray);
                showpic();


            } 
            catch (FileNotFoundException e){

                e.printStackTrace();
            }

        }   
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }

    public void showpic() {

        LoginDataBaseAdapter db = loginDataBaseAdapter.open();
         boolean emptytab = false;
         boolean empty = db.checkPic(null, emptytab);

        //Cursor cursor = loginDataBaseAdapter.fetchProfileImageFromDatabase();  

         if(empty==false)  
         {  
             Cursor cursor = loginDataBaseAdapter.fetchProfileImageFromDatabase();
             cursor.moveToFirst();
                   byte[] data = cursor.getBlob(cursor.getColumnIndex("Path"));  
                    ByteArrayInputStream imageStream = new ByteArrayInputStream(data);  
                    Bitmap theImage = BitmapFactory.decodeStream(imageStream);  
                    targetImage.setImageBitmap(theImage);  
            cursor.close(); 
                }  





        } 

0 个答案:

没有答案