开发者

Getting an image from SD card and store it in Android Database

Can i get an image from SD card and store it in the application database?? Is this idea effective in my application??

Thanks in开发者_运维百科 advance!!

Regards


Yes you can get the image from your sd card and store it in sqlite database, we have done it but it will be too expensive for your device....... So be careful about that,

call image picker intent by calling this

Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                    startActivityForResult(i, 12);

It will open default gallery picker view , when you select an image you will be returned in your current activity, So override onActivityResult() and look for result code 12.

in that code you can get cursor by these lines

Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
cursor.moveToFirst();

From that cursor object you can get the file path of image by these lines

 int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
 String filePath = cursor.getString(columnIndex);

Here is the bitmap object

Bitmap bMap = BitmapFactory.decodeFile(filePath);

Get byte arrays

ByteArrayOutputStream out = new ByteArrayOutputStream();

bMap.compress(Bitmap.CompressFormat.PNG, 100,out); 
byte[] imageArray = out.toByteArray();

Now you have to store imageArray as blob in your database. And you are done.... Don't forget to refer this post from where i got the solution...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜