Android 安卓摄像头
有人能给我提供一些关于从相机捕获“完整”图像的代码示例,然后将其转换为“startActivityForResult”中的一个字节,以及在imageView中显示的位图。任何帮助都将受到真诚的感谢Android 安卓摄像头,android,Android,有人能给我提供一些关于从相机捕获“完整”图像的代码示例,然后将其转换为“startActivityForResult”中的一个字节,以及在imageView中显示的位图。任何帮助都将受到真诚的感谢 山姆你可能已经看到了这一点,但是。这里有一个很棒的教程 用于位图 实际上,我有一个应用程序可以做到这一点,我可以在下班回家后发送给你。你可能已经看到了这一点,但是。这里有一个很棒的教程 用于位图 实际上,我有一个应用程序可以做到这一点,我可以在下班回家后发送给你。处理相机有点棘手。下面是我为一
山姆你可能已经看到了这一点,但是。这里有一个很棒的教程 用于位图
实际上,我有一个应用程序可以做到这一点,我可以在下班回家后发送给你。你可能已经看到了这一点,但是。这里有一个很棒的教程 用于位图
实际上,我有一个应用程序可以做到这一点,我可以在下班回家后发送给你。处理相机有点棘手。下面是我为一个应用程序编写的一段代码
private final int RECEIVE_CAMERA_PICTURE = 10;
private Uri mCameraUri = null;
mCameraUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraUri);
mtimeCameraAcessed = System.currentTimeMillis();
startActivityForResult(cameraIntent, RECEIVE_CAMERA_PICTURE);
现在,要处理图像捕获,应将以下内容放在onActivityResult()方法中。您会注意到,我已经输入了一个复选框来获取所拍摄图像的方向。此值将有助于通过不同活动中的ImageView显示图像:
int orientation = -10;
Intent displayCameraPictureIntent = new Intent(MainActivity.this, FilterActivity.class);
displayCameraPictureIntent.setData(mCameraUri);
String filePath = OtherUtils.getRealPathFromURI(mContext, mCameraUri);
long fileSize = new File(filePath).length();
Cursor mediaCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(mtimeCameraAcessed/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + " desc");
//ensure that the app doesn't consume inappropriate data
if (mediaCursor != null && mtimeCameraAcessed != 0 && mediaCursor.getCount() != 0 ) {
while(mediaCursor.moveToNext()){
long size = mediaCursor.getLong(1);
//Extra check to make sure that we are getting the orientation from the proper file
if(size == fileSize){
orientation = mediaCursor.getInt(0);
break;
}
}
}
displayCameraPictureIntent.putExtra("orientationValue", orientation);
startActivity(displayCameraPictureIntent);
private Bitmap imageBitmap = null;
Uri imageUri = getIntent().getData();
shareImageUri = imageUri;
try {
imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
} catch (Exception e) {
// TODO Auto-generated catch block
}
// check whether image is in landscape or portrait mode
if(getIntent().getIntExtra("orientationValue", 1) == 90) {
//image is in portrait. So, rotate the image by 90degrees so that it is displayed in portrait mode
}
//now, set the bitmap to the appropriate imageView. You might want to scale the bitmap, to avoid
//memory issues.
现在,要在新活动中显示图像:
int orientation = -10;
Intent displayCameraPictureIntent = new Intent(MainActivity.this, FilterActivity.class);
displayCameraPictureIntent.setData(mCameraUri);
String filePath = OtherUtils.getRealPathFromURI(mContext, mCameraUri);
long fileSize = new File(filePath).length();
Cursor mediaCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(mtimeCameraAcessed/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + " desc");
//ensure that the app doesn't consume inappropriate data
if (mediaCursor != null && mtimeCameraAcessed != 0 && mediaCursor.getCount() != 0 ) {
while(mediaCursor.moveToNext()){
long size = mediaCursor.getLong(1);
//Extra check to make sure that we are getting the orientation from the proper file
if(size == fileSize){
orientation = mediaCursor.getInt(0);
break;
}
}
}
displayCameraPictureIntent.putExtra("orientationValue", orientation);
startActivity(displayCameraPictureIntent);
private Bitmap imageBitmap = null;
Uri imageUri = getIntent().getData();
shareImageUri = imageUri;
try {
imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
} catch (Exception e) {
// TODO Auto-generated catch block
}
// check whether image is in landscape or portrait mode
if(getIntent().getIntExtra("orientationValue", 1) == 90) {
//image is in portrait. So, rotate the image by 90degrees so that it is displayed in portrait mode
}
//now, set the bitmap to the appropriate imageView. You might want to scale the bitmap, to avoid
//memory issues.
您还需要检查此链接,它解释了这段代码的方向:
如果您还有任何问题或顾虑,请告诉我。如果您想使用Camera api,我预先警告您,这是一项极具挑战性的任务,但绝对是可行的。处理摄像头有点棘手。下面是我为一个应用程序编写的一段代码
private final int RECEIVE_CAMERA_PICTURE = 10;
private Uri mCameraUri = null;
mCameraUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraUri);
mtimeCameraAcessed = System.currentTimeMillis();
startActivityForResult(cameraIntent, RECEIVE_CAMERA_PICTURE);
现在,要处理图像捕获,应将以下内容放在onActivityResult()方法中。您会注意到,我已经输入了一个复选框来获取所拍摄图像的方向。此值将有助于通过不同活动中的ImageView显示图像:
int orientation = -10;
Intent displayCameraPictureIntent = new Intent(MainActivity.this, FilterActivity.class);
displayCameraPictureIntent.setData(mCameraUri);
String filePath = OtherUtils.getRealPathFromURI(mContext, mCameraUri);
long fileSize = new File(filePath).length();
Cursor mediaCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(mtimeCameraAcessed/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + " desc");
//ensure that the app doesn't consume inappropriate data
if (mediaCursor != null && mtimeCameraAcessed != 0 && mediaCursor.getCount() != 0 ) {
while(mediaCursor.moveToNext()){
long size = mediaCursor.getLong(1);
//Extra check to make sure that we are getting the orientation from the proper file
if(size == fileSize){
orientation = mediaCursor.getInt(0);
break;
}
}
}
displayCameraPictureIntent.putExtra("orientationValue", orientation);
startActivity(displayCameraPictureIntent);
private Bitmap imageBitmap = null;
Uri imageUri = getIntent().getData();
shareImageUri = imageUri;
try {
imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
} catch (Exception e) {
// TODO Auto-generated catch block
}
// check whether image is in landscape or portrait mode
if(getIntent().getIntExtra("orientationValue", 1) == 90) {
//image is in portrait. So, rotate the image by 90degrees so that it is displayed in portrait mode
}
//now, set the bitmap to the appropriate imageView. You might want to scale the bitmap, to avoid
//memory issues.
现在,要在新活动中显示图像:
int orientation = -10;
Intent displayCameraPictureIntent = new Intent(MainActivity.this, FilterActivity.class);
displayCameraPictureIntent.setData(mCameraUri);
String filePath = OtherUtils.getRealPathFromURI(mContext, mCameraUri);
long fileSize = new File(filePath).length();
Cursor mediaCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(mtimeCameraAcessed/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + " desc");
//ensure that the app doesn't consume inappropriate data
if (mediaCursor != null && mtimeCameraAcessed != 0 && mediaCursor.getCount() != 0 ) {
while(mediaCursor.moveToNext()){
long size = mediaCursor.getLong(1);
//Extra check to make sure that we are getting the orientation from the proper file
if(size == fileSize){
orientation = mediaCursor.getInt(0);
break;
}
}
}
displayCameraPictureIntent.putExtra("orientationValue", orientation);
startActivity(displayCameraPictureIntent);
private Bitmap imageBitmap = null;
Uri imageUri = getIntent().getData();
shareImageUri = imageUri;
try {
imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
} catch (Exception e) {
// TODO Auto-generated catch block
}
// check whether image is in landscape or portrait mode
if(getIntent().getIntExtra("orientationValue", 1) == 90) {
//image is in portrait. So, rotate the image by 90degrees so that it is displayed in portrait mode
}
//now, set the bitmap to the appropriate imageView. You might want to scale the bitmap, to avoid
//memory issues.
您还需要检查此链接,它解释了这段代码的方向:
如果您还有任何问题或顾虑,请告诉我。相反,如果您想使用CameraAPI,我预先警告您,这是一项极具挑战性的任务,但绝对可行