android - 在 Android 上的 SQLite 数据库中实现相机图像存储的问题
问题描述
我最近制作了一个具有基本 Intent 的应用程序,可以在设备上打开默认的相机应用程序。但我想扩展它的功能,使其能够将捕获的图像从相机存储到 SQLite 数据库。连同显示已经存储在数据库中的图像。我还想显示在图像下方捕获的图像的日期和时间,以及在图像的日期/时间下方添加评论框。
MainActivity 的代码如下:
import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCamera = (Button) findViewById(R.id.btnCamera);
imageView = (ImageView) findViewById(R.id.imageView);
btnCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
}
Activity 的 Layout XML 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="vertical"
android:weightSum="10"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_weight="9"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
<Button
android:id="@+id/btnCamera"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_dark"
android:textColor="@android:color/white"
android:text="Open Camera"
/>
</LinearLayout>
解决方案
推荐阅读
- list - 删除n-1个顶点后查找n边多边形的最后一个剩余顶点
- google-apps-script - 验证身份验证范围“../auth/script.storage”,而不是仅在我的同意屏幕中列出
- c - 如何用 C 中的一些现有数组元素创建一个新数组?
- python - 尝试使用 ESP32 从电容式土壤湿度传感器收集数据
- ios - 如何为 xamrin 应用程序启用“始终嵌入 swift 标准库”?
- codenameone - SideMenu 在模拟器和应用程序上失败
- tsql - 执行的查询与查询的执行方式不同(使用身份插入)
- html - 更改文件夹后找不到图像
- ansible - 如何在发布期间使用 Ansible 匹配特定文件?
- spring - 如何在春季批处理中用 openCSV 替换 flatFileItemReader