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



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

你认为一个叫做SQLite的数据库系统,强调的是Lite,如何以每张2.5mb的速度处理50张图片?这是一个125Mb的数据库,不包括其他数据。我的大多数支持网站的完整的MS SQL数据库还没有达到这个规模。你最好把它存储在SD卡上:)。

如果这还不能阻止你,那么看看SQLite中的blob数据类型。

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

        }

最新更新