我正在使用相机拍照并希望存储在数据库中(sqlite).存储的照片必须显示在另一个活动中,列表视图如此
list view images和
this iam使用此代码拍照但如何将照片存储在数据库中并显示在另一个活动中任何想法请帮助…..
@H_403_9@解决方法@H_502_10@
谢谢….
这是拍照的代码
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