gpt4 book ai didi

java - 三星手机imageView中的照片方向

转载 作者:太空宇宙 更新时间:2023-11-04 11:46:33 25 4
gpt4 key购买 nike

我在三星设备上遇到图像问题每次我拍摄垂直形式的照片,但当它调用画廊的图像时,教室垂直它使用 ExifInterface 类进行编程,但我找不到结果

每次拍照时,我都会调用我的类 PreviewImage,这是我显示图像的地方随后我有一个按钮可以让我分配个人资料照片我有这个方法 onActivityResult

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {
try {
ExifInterface exifInterface = new ExifInterface(photoFile.getAbsolutePath());
int exif = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (exif) {
case ExifInterface.ORIENTATION_ROTATE_90:
orientation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
orientation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
orientation = 270;
break;
}
} catch (Exception e) {
Log.d("tmessages", e.toString());
}
Intent intent = new Intent(this, PhotoViewer.class);
intent.putExtra(EXTRA_PHOTO_PATH, photoFile.getAbsolutePath());
intent.putExtra(EXTRA_PHOTO_ORIENTATION, orientation);
intent.putExtra(EXTRA_PHOTO_EDIT, false);
startActivityForResult(intent, 10);

}

这是我的 PhotoViewer 类

   private void sendPicture() {
Intent returnIntent = new Intent();
returnIntent.putExtra("photoDescription", photoDescription.getText().toString());
returnIntent.putExtra("photoPath", localPath);
returnIntent.putExtra("orientation", orientation);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}

拍摄照片后,它会将我返回到调用该方法的 Profile 类的 onActivityResult 方法

else if (requestCode == 10 && resultCode == Activity.RESULT_OK) {
if (photoFile != null&&LoginController.getInstance().xmppConnection.isConnected()) {
byte[] photo = AndroidUtilities
.createProfileImage(photoFile.getAbsolutePath());
ProfileManager.getInstance().publishPhoto( photo);
Bitmap decodedByte = BitmapFactory.decodeByteArray(photo, 0, photo.length);
avatar.setImageBitmap(decodedByte);
}else{
Toast.makeText(this,R.string.LabelProfilePhotoFailed, Toast.LENGTH_SHORT).show();
}
}

如何使个人资料照片中的图像显示为垂直?

最佳答案

你已经完成了一半的工作!只需使用您之前计算的方向即可:

else if (requestCode == 10 && resultCode == Activity.RESULT_OK) {
if (photoFile != null&&LoginController.getInstance().xmppConnection.isConnected()) {
byte[] photo = AndroidUtilities
.createProfileImage(photoFile.getAbsolutePath());
ProfileManager.getInstance().publishPhoto( photo);
Bitmap decodedByte = BitmapFactory.decodeByteArray(photo, 0, photo.length);
-> decodedByte = rotate(decodedByte, orientation);
avatar.setImageBitmap(decodedByte);
}else{
Toast.makeText(this,R.string.LabelProfilePhotoFailed, Toast.LENGTH_SHORT).show();
}
}

方向 = getIntent().getExtras().getInt(EXTRA_PHOTO_ORIENTATION) 时。

private static Bitmap rotate(Bitmap bm, int rotation) {
if (rotation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
Bitmap bmOut = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
return bmOut;
}
return bm;
}

关于java - 三星手机imageView中的照片方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42291786/

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