gpt4 book ai didi

java - Android Camera 将图像返回为肖像,将其作为风景?

转载 作者:行者123 更新时间:2023-11-30 01:50:58 25 4
gpt4 key购买 nike

 Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

i.putExtra(MediaStore.EXTRA_OUTPUT, MyFileContentProvider.CONTENT_URI);

startActivityForResult(i, CAMERA_RESULT);

这就是我在我的应用程序中调用相机的方式,因为我需要高质量的输出,所以我在两者之间使用了一个 contentProvider

Bitmap mBitmap = BitmapFactory.decodeFile(out.getAbsolutePath());

ImageView im1 = (ImageView)findViewById(R.id.camTemp);
im1.setImageBitmap(mBitmap);

onActivityResult() ,这就是我显示拍摄图像的方式。

在这两者之间,这是 contentProvider 类的代码。

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");
}

现在,问题是,我最终在ImageView中获取的图像是portrait,如何将其获取为landscape 默认情况下?

最佳答案

您可以轻松地旋转肖像图像并获得风景图像!

Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap , 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

关于java - Android Camera 将图像返回为肖像,将其作为风景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33055150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com