Android 如何将相机图像保存在数据库中并在列表视图中显示另一个活动? [英] Android How to save camera images in database and display another activity in list view?

查看:20
本文介绍了Android 如何将相机图像保存在数据库中并在列表视图中显示另一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用相机拍照并想存储在数据库(SQLite)中.存储的照片必须显示在另一个具有列表视图的活动中,如下所示 列表视图图像this 我使用此代码拍摄照片但如何存储照片在数据库中并在另一个活动中显示任何想法请帮助.....

i am using camera to take photos and want to store in database(SQLite). Stored photos have to be displayed in the another activity with list view like this list view images and this iam using this code take photo but how to store the photo in database and display in another activity any idea please help .....

谢谢....

这是拍照的代码

  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);                

        }       
    }
}

推荐答案

Create DataBase helper class like this..

Create DataBase helper class like this..

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

On Capturing the image insert the image by converting into bytes:

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, 0);
            c.moveToNext();
            i++;
            }
           Log.e("Bitmap length",""+array.length);
       }

将此 Bitmap 数组传递给 ListView

Pass this Bitmap array to ListView

这篇关于Android 如何将相机图像保存在数据库中并在列表视图中显示另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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