谢谢….
这是拍照的代码
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如何在数据库中保存相机图像并在列表视图中显示另一个活动?全部内容,希望文章能够帮你解决Android如何在数据库中保存相机图像并在列表视图中显示另一个活动?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)