【发布时间】:2014-07-24 23:39:02
【问题描述】:
我正在自己学习 android/java @the moment,我正在学习的应用程序的一部分出现问题。
我在 www 的帮助下编写了代码,我的问题是,如果我从图库中打开一张图片,它会发送到编辑活动,但图片的质量真的很差。
我认为主要问题的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case PICK_IMAGE_FROM_GALLERY:
{
if (resultCode == RESULT_OK)
{
Log.d(TAG, "Got Picture!");
Log.d(TAG,"File type - " + data.getType());
Uri photoUri = data.getData();
if (photoUri != null)
{
try {
String[] filePathColumn = {MediaStore.Images.Media.DATA};
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
int orientation = -1;
Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
cursor = getContentResolver().query(photoUri, orientationColumn, null, null, null);
if(cursor != null && cursor.moveToFirst()){
orientation = cursor.getInt(cursor.getColumnIndex(orientationColumn[0]));
}
cursor.close();
HashMap<String, Integer> pRes = this.getImageResolutionSetting();
Bitmap shrunkenBitmap = FileUtilsHelper.shrinkBitmap(filePath, pRes.get("width"), pRes.get("height"));
shrunkenBitmap = rotateBitmapToOrientation(shrunkenBitmap, orientation);
String res = FileUtilsHelper.saveBitmapAsJpeg(shrunkenBitmap, this);
Log.d(TAG,"File Path: " + res);
shrunkenBitmap.recycle();
Intent editImage = new Intent(this, EditImage.class);
editImage.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
editImage.putExtra("stuff.path", res);
startActivity(editImage);
}catch(Exception e){
Toast.makeText(this, R.string.cant_save_image,Toast.LENGTH_SHORT).show();
}
}
}
}
break;
}
}}
我现在想重写完整的 onActivityResult 以便它使用画廊中的图片 1:1 或删除部分: shrinkBitmap(我认为这是质量差的主要问题) rotateBitmapToOrientation(因为它总是错误的方向)
但我不知道它是如何工作的......
如果我要删除那些部分,它就不再起作用了,我真的需要一位老师:)
谢谢你的帮助伙计们!!
【问题讨论】:
-
据我了解,在
filePath你有文件路径。因此,如果您传递它(通过 putExtra())而不是res,您将编辑原始图像。 -
我必须将 res 更改为 filePath 是如何工作的?我试过了,但它是一样的。谢谢! @18446744073709551615
-
我的意思是它的工作我可以删除那些部分,但质量是一样的(坏)你知道我的问题是什么吗?我应该发布我的 FileUtilsHelper 类吗?谢谢你的帮助。 @18446744073709551615
-
发表您的评论作为答案,我将其标记为正确,因为我可以删除我要求的部分。质量不好的问题是其他问题
public HashMap<String,Integer> getImageResolutionSetting是主要问题。也许我正在为此打开一个新问题。谢谢你的帮助! @18446744073709551615
标签: android image android-intent bitmap onactivityresult