作者jun11108 (jun)
看板AndroidDev
标题[问题] 使用相机问题
时间Fri Apr 15 13:55:43 2011
开发层: (应用/框架/库/核心)
应用
问题:
想请教有关照相机使用的问题
之前是使用Camera class来做
但是偶尔会出现当机的问题(找不到原因orz)
後来直接改用intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE)
去呼叫照相机再经由路径去读取照片作处理
以下是我的程式(参考网路)
开启相机部分
public static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 1234567;
...
mBtnTakePicture.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
//define the file-name to save photo taken by Camera activity
String fileName = "new-photo-name.jpg";
//create parameters for Intent with filename
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
//imageUri is the current activity attribute, define and save it for later
usage (also in onSaveInstanceState)
imageUri =
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
//create new Intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
读取照片部分
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
//use imageUri here to access the image
Cursor cursor = null;
try {
String [] proj={ MediaStore.Images.Media.DATA }; //,
MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.ORIENTATION };
cursor = RecordView.this.managedQuery(imageUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int file_ColumnIndex =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
//int orientation_ColumnIndex =
cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION);
if (cursor.moveToFirst()) {
String imagePath = cursor.getString(file_ColumnIndex);
....
} finally {
if (cursor != null) {
cursor.close();
}
我的问题是,
现在可以顺利的读取到照片,
那请问我该如何从记忆卡中删除这张照片,
我试过用File去读imagePath,
再用delete()去删除,
但没有产生任何效果,
另外想请问,
用这种方式开启相机还有办法去修改相机的参数吗?
比如说限制闪光或是照片大小等,
麻烦各位高手了,
谢谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.87.151.40