从相机图像保存到源码 [英] save image from camera into sqlite

查看:170
本文介绍了从相机图像保存到源码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个摄像头活动是这样的:

I have an camera Activity like this:

public void startCamera() 
{
    Log.d("ANDRO_CAMERA", "Starting camera on the phone...");
    String fileName = "testphoto.jpg";
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, fileName);
    values.put(MediaStore.Images.Media.DESCRIPTION,
            "Image capture by camera");
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    imageUri = getContentResolver().insert(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
    startActivityForResult(intent, IMAGE_CAPTURE);
}

我应该怎么做这个图像保存到SQLite数据库?

What should I do to save this image to a SQLite database?

我有code是这样的:

I have code like this:

fileName = helper.getKdStore(c) + "_" + System.currentTimeMillis() + ".jpg";
_path = Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera/" + fileName;

在启动摄像头:

Cursor c = helper.getById(almagId);
c.moveToFirst();
File file = new File(_path, null);
try {
    file.createNewFile();
} catch (IOException e) {
    e.printStackTrace();
}
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, IMAGE_CAPTURE);
System.out.println(file);

Dbhelper helper = new Dbhelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL("update alfamapp set gambar ='"+file+"' where kdstore='"+helper.getKdStore(c)+"'");
db.close();
helper.close();

System.out.println(db);

和我创建的方法public void load()来显示我的形象:

and I create method public void load() to display my image:

detGam.setImageDrawable(Drawable.createFromPath(_path));

但我的应用程序无法显示图像。谢谢你的帮助。

but my application can't display the image. Thank you for your help.

推荐答案

在保存图像到SQLite是坏主意,但是如果你还想走得更远,还有这里是code

Saving Image in to sqlite is bad idea, however if you still want to go further, there here is code

public static void insertPicture(byte[] data)
{

    SQLiteDatabase db = thisAct.openOrCreateDatabase(ConstantCodes.IMAGE_DATABASE, 2, null);
    ContentValues values = new ContentValues(1);
    values.put("photo", data);
    db.insert("photos", null, values);
    db.close();

} 

这篇关于从相机图像保存到源码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆