如何在我的应用程序中将相机捕获的图像存储在SQLite数据库中?

时间:2011-09-23 01:04:46

标签: android sqlite

在我的应用程序中,我想从辅助摄像头捕获图像并将照片存储到我的SQLite数据库而不是SD卡中。请任何人帮我如何使用一些示例源代码

2 个答案:

答案 0 :(得分:3)

您如何看待一个名为SQLite的数据库系统,强调精简版,可以处理每张2.5mb的50张图片?这是一个125Mb的数据库,不包括其他数据。我支持网站的大部分完整版MS SQL数据库尚未达到这个规模。存储在SD卡上符合您的最佳利益:)。

如果这仍然无法阻止你,那么请查看SQLite中的blob数据类型。

答案 1 :(得分:0)

You can save camera captured image into SQLitedatabase in this way.. 

public class CamActivity extends Activity {



    byte[] byteArray;
    private static final int CAMERA_REQUEST = 1888;
    protected static final int TAKE_PHOTO_CODE = 0;
    public ImageView imageView;
    private DBAdapter db;
    byte [] imgbyte;
    EditText txtView ;
    String name;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        db=new DBAdapter(CamActivity.this);
        db.open();
        this.imageView = (ImageView)this.findViewById(R.id.imageView1);          
      txtView=(EditText)findViewById(R.id.editText1);
        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); 
               // cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,getImageUri());
                startActivityForResult(cameraIntent,CAMERA_REQUEST ); 
            }
        }); 

        Button save = (Button)findViewById(R.id.saving);
        save.setOnClickListener(new View.OnClickListener() {            
            public void onClick(View v) {




                name=txtView.getText().toString();


                try
                {

db.insertImageDetails(byteArray,name);  

                }              

                catch (Exception e) {
                    e.printStackTrace();
                }
                 //mySQLiteAdapter.close();

                Toast.makeText(getApplicationContext(), "processing", Toast.LENGTH_SHORT).show();
                Toast.makeText(getApplicationContext(), "image saved", Toast.LENGTH_SHORT).show();

                }});

        Button G = (Button) this.findViewById(R.id.get);
        G.setOnClickListener(new View.OnClickListener() {           
            public void onClick(View v)

            {

                Intent intent= new Intent(CamActivity.this,SecondActivity.class);
                startActivity(intent);

    }
            });
        }


protected void onActivityResult(int requestCode, int resultCode, Intent data) {  

        //final byte[] byteArray;
        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);
             byteArray = stream.toByteArray();
           System.out.println(byteArray);
           Toast.makeText(getApplicationContext(), byteArray.toString(), Toast.LENGTH_SHORT).show();

        }

    }



        }