【发布时间】:2011-03-04 09:53:07
【问题描述】:
我是 android 新手,我正在开发一个使用图库和从图库中挑选图片的应用程序,但我遇到了一个错误,我试图以不同的方式解决,因为
当我选择水平图像(宽度大于高度)时,我正在使用位于 SD 卡上的图库,它在图像视图中加载图像非常好,但问题在于垂直图像(高度大于宽度)它显示图像在左侧旋转的图像视图中(或从原始位置说 -90 度)。我已经打印了两个图像的宽度和高度(水平和垂直),两个图像的显示宽度 = 2592 和高度 = 1936,
我真的很震惊,大约 3 周都无法解决它,请任何人帮助我。
提前致谢
这是我的代码:
用于启动画廊意图
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
选择图片后:
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent)
{
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
try{ switch(requestCode) { case REQ_CODE_PICK_IMAGE: if(resultCode == RESULT_OK)
{
Uri selectedImage = imageReturnedIntent.getData(); String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
filePath = cursor.getString(columnIndex);
cursor.close();
File img = new File(filePath); Bitmap yourSelectedImage = BitmapFactory.decodeStream(new FileInputStream(img));
int imgHeight = yourSelectedImage.getHeight(); int imgWidth = yourSelectedImage.getWidth();
Toast.makeText(getApplicationContext(), "Original size: Width ="+imgWidth+" Height="+imgHeight, Toast.LENGTH_LONG).show();
float myScalingFactor = MyScaleFactor(imgHeight,imgWidth);
int destW = (int)(imgWidth*myScalingFactor);
int destH = (int)(imgHeight*myScalingFactor);
Toast.makeText(getApplicationContext(), "Scaled size: Width ="+destW+" Height="+destH + "Scale" +myScalingFactor, Toast.LENGTH_LONG).show();
yourSelectedImage = Bitmap.createScaledBitmap(yourSelectedImage, destW, destH, true);
picUpload.setImageBitmap(yourSelectedImage);
}
【问题讨论】:
-
请考虑格式化您的源代码。它现在不是真的可读。见stackoverflow.com/editing-help
-
没错。同样的问题............
标签: android