Android如何在数据库中保存相机图像并在列表视图中显示另一个活动?

我正在使用相机拍照并希望存储在数据库中(sqlite).存储的照片必须显示在另一个活动中,列表视图如此 list view imagesthis iam使用此代码拍照但如何将照片存储在数据库中并显示在另一个活动中任何想法请帮助…..

谢谢….

这是拍照的代码

public class PhotoActivity extends Activity {
    private static final int CAMERA_REQUEST = 1888; 
    public ImageView imageView;  

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photoactivity);

        this.imageView = (ImageView)this.findViewById(R.id.imageView1);          

        Button B = (Button) this.findViewById(R.id.camera);
        B.setonClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                startActivityForResult(cameraIntent,CAMERA_REQUEST); 
            }
        });
    }    
    protected void onActivityResult(int requestCode,int resultCode,Intent data) {  
        if (requestCode == CAMERA_REQUEST) {  
            Bitmap photo = (Bitmap) data.getExtras().get("data");   
            imageView.setimageBitmap(photo);                

        }       
    }
}

解决方法

创建数据库帮助程序类,如 this ..

捕获图像时通过转换为字节插入图像:

Imagehelper help=new Imagehelper(this);

    if (requestCode == CAMERA_REQUEST) {  
                        Bitmap photo = (Bitmap) data.getExtras().get("data");   
                        imageView.setimageBitmap(photo);
                        ByteArrayOutputStream stream = new ByteArrayOutputStream();
                        photo.compress(Bitmap.CompressFormat.PNG,100,stream);
                        byte[] byteArray = stream.toByteArray();

                        help.insert(byteArray);
    }

要检索表单数据库

Imagehelper help=new Imagehelper(this);

       Cursor c= help.getAll();
       int i=0;
       if(c.getCount()>0)
       {  
           Bitmap[]  array=new Bitmap[c.getCount()];
           c.movetoFirst();
           while(c.isAfterLast()==false)
           {

               byte[] bytes=c.getBlob(c.getColumnIndex("imageblob"));

            array[i]=BitmapFactory.decodeByteArray(bytes,0);
            c.movetoNext();
            i++;
            }
           Log.e("Bitmap length",""+array.length);
       }

将此Bitmap数组传递给ListView

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...