在android中缩放和旋转图像-图像赢得';不出现
我是android新手,在第一次活动中使用了相同的缩放和旋转代码后,我在第二次活动中出现了一些问题。 在第一个活动中,我当前正在从照片库检索图像。然后,我将在ImageView中显示此图像。在实际显示图像之前,我必须缩放位图,然后旋转它。这是工作-我从这个网站得到了大部分代码-谢谢!然后,我将此图像的详细信息保存到我的SQLite数据库(如sd卡上图像的路径名) 但是,在第二个活动中,我尝试立即检索图像以在imageview中显示(从它的路径名,我已将其保存到SQLite数据库),并且再次使用相同的代码缩放和旋转相同的图像以显示在此imageview中,但这一次,图像没有显示。。。。。?如果我只是执行用于缩放位图的代码,图像确实会出现,但只有当我尝试执行旋转代码时,图像才会出现。如上所述,在第一个活动中,缩放和旋转起作用,但在第二个活动中,只有缩放起作用。 下面是缩放和旋转的代码在android中缩放和旋转图像-图像赢得';不出现,android,Android,我是android新手,在第一次活动中使用了相同的缩放和旋转代码后,我在第二次活动中出现了一些问题。 在第一个活动中,我当前正在从照片库检索图像。然后,我将在ImageView中显示此图像。在实际显示图像之前,我必须缩放位图,然后旋转它。这是工作-我从这个网站得到了大部分代码-谢谢!然后,我将此图像的详细信息保存到我的SQLite数据库(如sd卡上图像的路径名) 但是,在第二个活动中,我尝试立即检索图像以在imageview中显示(从它的路径名,我已将其保存到SQLite数据库),并且再次使用相
public static void process (String filePath, ImageView imageView) {
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
int h = 250;
int w = 250;
Bitmap scaled = Bitmap.createScaledBitmap(yourSelectedImage, h, w, true);
Matrix matrix = new Matrix();
imageView.setScaleType(ScaleType.MATRIX);
imageView.setImageBitmap(scaled);
matrix.postRotate(90f, imageView.getDrawable().getBounds().width()/2,
imageView.getDrawable().getBounds().height()/2);
imageView.setImageMatrix(matrix);
}
第一个活动的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/result"
android:layout_width="250dip"
android:layout_height="250dip"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
android:contentDescription="@string/desc1"
android:scaleType="matrix" />
<Button
android:id="@+id/selectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/textView2"
android:layout_marginBottom="15dp"
android:text="Select Photo" />
<Button
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/selectButton"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="27dp"
android:text="Save" />
<LinearLayout
android:id="@+id/addbloglinkcontainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/result" >
<TextView
android:id="@+id/addbloglinktext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_blog_link" />
<EditText
android:id="@+id/blogLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:ems="10"
android:inputType="textUri" />
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/imageView"
android:layout_width="250dip"
android:layout_height="250dip"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
android:contentDescription="@string/desc1"
android:onClick="mthdtocall"
android:scaleType="matrix" />
</RelativeLayout
第二个活动的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/result"
android:layout_width="250dip"
android:layout_height="250dip"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
android:contentDescription="@string/desc1"
android:scaleType="matrix" />
<Button
android:id="@+id/selectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/textView2"
android:layout_marginBottom="15dp"
android:text="Select Photo" />
<Button
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/selectButton"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="27dp"
android:text="Save" />
<LinearLayout
android:id="@+id/addbloglinkcontainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/result" >
<TextView
android:id="@+id/addbloglinktext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_blog_link" />
<EditText
android:id="@+id/blogLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:ems="10"
android:inputType="textUri" />
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/imageView"
android:layout_width="250dip"
android:layout_height="250dip"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
android:contentDescription="@string/desc1"
android:onClick="mthdtocall"
android:scaleType="matrix" />
</RelativeLayout
不知道为什么图像没有出现,但是。。。您可以尝试使用LRU缓存在两个活动中重用相同的位图图像
developer.android.com/reference/android/util/LruCache.html发布第一个和第二个活动的xml文件