我尝试从 sdcard 相机文件夹加载图像,加载后我使用缩放位图创建位图,因为我只想显示图像的某些部分,所以我尝试使用 createBitmap() 创建一个新位图,但它仍然变得模糊,我怎么解决这个问题?
File[] files = targetDirector.listFiles();
for (File file : files) {
String path = file.getAbsolutePath();
itemList.add(path);
if (myBitmap != null) {
myBitmap = null;
}
myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
System.out.println("thumbnails1 width: " + myBitmap.getWidth());
System.out.println("thumbnails1 height: " + myBitmap.getHeight());
myBitmap = Bitmap.createScaledBitmap(myBitmap, 150, 150, false);
ExifInterface exif;
try {
exif = new ExifInterface(file.getAbsolutePath());
String orientString = exif
.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientString != null ? Integer
.parseInt(orientString)
: ExifInterface.ORIENTATION_NORMAL;
int rotationAngle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
System.out.println("photopotart");
rotationAngle = 90;
System.out.println("myBitmap" + myBitmap.getWidth());
System.out.println("myBitmap" + myBitmap.getHeight());
myBitmap = Bitmap.createScaledBitmap(myBitmap, 150, 150,
false);
Matrix matrix = new Matrix();
matrix.postRotate(90);
myBitmap = Bitmap.createBitmap(myBitmap, 0, 0,
150, 150, matrix,
true);
myBitmap = Bitmap.createBitmap(myBitmap, 0, 0, 150, 100 );
myBitmap = highlightImage(myBitmap);
photsList.add(myBitmap);
}
else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
System.out.println("180 angle");
rotationAngle = 180;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
System.out.println("other 270");
rotationAngle = 270;
} else {
System.out.println("photolandscape");
myBitmap = Bitmap.createScaledBitmap(myBitmap, 150, 150,
false);
myBitmap = Bitmap.createBitmap(myBitmap, 30, 0, 120, 150);
photsList.add(myBitmap);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我的xml文件是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/img"
android:layout_width="150dip"
android:layout_height="150dip" />
</LinearLayout>