【发布时间】:2018-11-29 14:15:15
【问题描述】:
我正在使用 android 文档:
培训/相机/摄影基础
这是实现的代码:
public class CFoto extends AppCompatActivity {
private ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cfoto);
img = findViewById(R.id.imageView);
if (ContextCompat.checkSelfPermission(CFoto.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(CFoto.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(CFoto.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 1000);
}
}
//Create unic name
String mCurrentPhotoPath;
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "Backup_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName, ".jpg", storageDir);
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
//take foto
static final int REQUEST_TAKE_PHOTO = 1;
public void tomarFoto(View view) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
}
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this, "com.example.android.fileprovider", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI.toString());
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
//preview image
static final int REQUEST_IMAGE_CAPTURE = 1;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
img.setImageBitmap(imageBitmap);
}
}
}
相机正在工作并将照片保存在本地 我应该更改什么以将照片保存在数据库中? 在数据库中,我为图像分配了 longblob 格式 数据库是远程的
【问题讨论】:
-
这是一个非常宽泛的问题——要有效地回答它,我们需要知道您已经尝试做什么以将其保存到数据库中。 stackoverflow.com/help/mcve 指的是什么是获得答案的好问题。您可能需要一个关于应用程序中的数据库连接的教程,在这种情况下,请先做,并在此处询问您在使用它时遇到的任何困难。