Java Android摄像头将图像返回为肖像,将其作为风景?
这就是我在应用程序中调用camera的方式,因为我需要高质量的输出,所以在两者之间使用Java Android摄像头将图像返回为肖像,将其作为风景?,java,android,android-camera,Java,Android,Android Camera,这就是我在应用程序中调用camera的方式,因为我需要高质量的输出,所以在两者之间使用contentProvider Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT, MyFileContentProvider.CONTENT_URI); startActivityForResult(i, C
contentProvider
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, MyFileContentProvider.CONTENT_URI);
startActivityForResult(i, CAMERA_RESULT);
在activityResult()上,这就是我显示拍摄图像的方式
这是contentProvider
类的代码
Bitmap mBitmap = BitmapFactory.decodeFile(out.getAbsolutePath());
ImageView im1 = (ImageView)findViewById(R.id.camTemp);
im1.setImageBitmap(mBitmap);
公共类MyFileContentProvider扩展ContentProvider{
公共静态最终Uri内容\u Uri=Uri.parse
("content://obx.com.futurister/");
私有静态最终哈希映射MIME_类型=
新的HashMap();
静止的{
MIME_类型.put(“.jpg”,“image/jpeg”);
MIME_类型.put(“.jpeg”,“image/jpeg”);
}
@凌驾
public int delete(Uri、字符串选择、字符串[]selectionArgs){
//实现此操作以处理删除一行或多行的请求。
抛出新的UnsupportedOperationException(“尚未实现”);
}
@凌驾
公共字符串getType(Uri){
字符串路径=uri.toString();
for(字符串扩展名:MIME_TYPES.keySet()){
if(路径endsWith(扩展)){
返回(MIME_TYPES.get(扩展));
}
}
返回(空);
}
@凌驾
公共Uri插入(Uri、ContentValues){
//TODO:实现此功能以处理插入新行的请求。
抛出新的UnsupportedOperationException(“尚未实现”);
}
@凌驾
公共布尔onCreate(){
试一试{
File mFile=新文件(getContext().getFilesDir(),“newImage.jpg”);
如果(!mFile.exists()){
mFile.createNewFile();
}
getContext().getContentResolver().notifyChange(内容URI,null);
返回(真);
}捕获(例外e){
e、 printStackTrace();
返回false;
}
}
@凌驾
公共ParcelFileDescriptor openFile(Uri,字符串模式)
抛出FileNotFoundException{
文件f=新文件(getContext().getFilesDir(),“newImage.jpg”);
如果(f.exists()){
返回(ParcelFileDescriptor.open)(f,
ParcelFileDescriptor.MODE_READ_WRITE));
}
抛出新的FileNotFoundException(uri.getPath());
}
@凌驾
公共游标查询(Uri、字符串[]投影、字符串选择、,
字符串[]selectionArgs,字符串排序器){
//TODO:实现此功能以处理来自客户端的查询请求。
抛出新的UnsupportedOperationException(“尚未实现”);
}
@凌驾
公共int更新(Uri、ContentValues、字符串选择、,
字符串[]selectionArgs){
//TODO:实现此功能以处理更新一行或多行的请求。
抛出新的UnsupportedOperationException(“尚未实现”);
}
}
现在,问题是,我在
图像视图
中最终获得的图像是纵向
,默认情况下如何获得它作为横向
您可以轻松旋转纵向图像并获得横向图像
public class MyFileContentProvider extends ContentProvider {
public static final Uri CONTENT_URI = Uri.parse
("content://obx.com.futurister/");
private static final HashMap<String, String> MIME_TYPES =
new HashMap<String, String>();
static {
MIME_TYPES.put(".jpg", "image/jpeg");
MIME_TYPES.put(".jpeg", "image/jpeg");
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
// Implement this to handle requests to delete one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public String getType(Uri uri) {
String path = uri.toString();
for (String extension : MIME_TYPES.keySet()) {
if (path.endsWith(extension)) {
return (MIME_TYPES.get(extension));
}
}
return (null);
}
@Override
public Uri insert(Uri uri, ContentValues values) {
// TODO: Implement this to handle requests to insert a new row.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public boolean onCreate() {
try {
File mFile = new File(getContext().getFilesDir(), "newImage.jpg");
if(!mFile.exists()) {
mFile.createNewFile();
}
getContext().getContentResolver().notifyChange(CONTENT_URI, null);
return (true);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
throws FileNotFoundException {
File f = new File(getContext().getFilesDir(), "newImage.jpg");
if (f.exists()) {
return (ParcelFileDescriptor.open(f,
ParcelFileDescriptor.MODE_READ_WRITE));
}
throw new FileNotFoundException(uri.getPath());
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
// TODO: Implement this to handle query requests from clients.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
// TODO: Implement this to handle requests to update one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
}
一般来说,您无法控制生成图像的摄像头应用程序。但奇怪的是,结果是肖像画。你试过哪种设备?谷歌nexus 5安卓5.1是你在启动intent时的活动?
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap , 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);