为什么在不同的移动设备上改变imageview的图片,会有不同的结果?
Why change the image of imageview on different mobile devices , have different results?
我想在我的项目中按下按钮 imageview 图像更改。
相机拍摄的照片存储在sdcard.The中的结果在不同的手机上是不同的。
在三星 s4 等手机中 phone 可以正确显示。 Imageview 填满屏幕。但是,在一些具有低分辨率屏幕的手机中 较小的显示器。
为了改变imageview图像,我使用了这个方法。
请指教
private void change_image_of_imageView() {
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/nabege" + File.separator + "images"
+ File.separator + imageFileName);
try {
if (file.exists()) {
Bitmap bmp1 = BitmapFactory.decodeFile(file.getAbsolutePath());
Matrix matrix = new Matrix();
float angle = 90;
matrix.postRotate(angle);
Bitmap bmp2 = Bitmap.createBitmap(bmp1, 0, 0, bmp1.getWidth(), bmp1.getHeight(), matrix, true);
Bitmap bmp3 = Bitmap.createScaledBitmap(bmp2, bmp2.getWidth(), bmp2.getHeight(), true);
btn_showImage.setImageBitmap(bmp3);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btn_pre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/button_success"
android:shadowColor="#592B2B"
android:shadowDx="9"
android:shadowDy="0"
android:shadowRadius="15"
android:text="@string/pre"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:id="@+id/btn_next"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/button_success"
android:shadowColor="#592B2B"
android:shadowDx="9"
android:shadowDy="0"
android:shadowRadius="15"
android:text="@string/next"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:isIndicator="true"
android:numStars="6" />
<TextView
android:id="@+id/txt_name_subject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/txt_text_subject"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iv_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iv_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<ImageView
android:id="@+id/iv_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
错误更有可能出在您的布局中。您为 ImageView 使用什么 ScaleType?
您可能想阅读 android 中有关 ScaleType 的这篇文章以获得您想要的结果。
这个问题的一个原因是在横向模式和纵向模式下拍照。
如果您曾经在风景模式下拍照,这个问题就解决了。但是在 imageview 和它的顶部之间创建了空 space。
我想在我的项目中按下按钮 imageview 图像更改。 相机拍摄的照片存储在sdcard.The中的结果在不同的手机上是不同的。 在三星 s4 等手机中 phone 可以正确显示。 Imageview 填满屏幕。但是,在一些具有低分辨率屏幕的手机中 较小的显示器。
为了改变imageview图像,我使用了这个方法。 请指教
private void change_image_of_imageView() {
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/nabege" + File.separator + "images"
+ File.separator + imageFileName);
try {
if (file.exists()) {
Bitmap bmp1 = BitmapFactory.decodeFile(file.getAbsolutePath());
Matrix matrix = new Matrix();
float angle = 90;
matrix.postRotate(angle);
Bitmap bmp2 = Bitmap.createBitmap(bmp1, 0, 0, bmp1.getWidth(), bmp1.getHeight(), matrix, true);
Bitmap bmp3 = Bitmap.createScaledBitmap(bmp2, bmp2.getWidth(), bmp2.getHeight(), true);
btn_showImage.setImageBitmap(bmp3);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btn_pre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/button_success"
android:shadowColor="#592B2B"
android:shadowDx="9"
android:shadowDy="0"
android:shadowRadius="15"
android:text="@string/pre"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:id="@+id/btn_next"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/button_success"
android:shadowColor="#592B2B"
android:shadowDx="9"
android:shadowDy="0"
android:shadowRadius="15"
android:text="@string/next"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:isIndicator="true"
android:numStars="6" />
<TextView
android:id="@+id/txt_name_subject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/txt_text_subject"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iv_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iv_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<ImageView
android:id="@+id/iv_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
错误更有可能出在您的布局中。您为 ImageView 使用什么 ScaleType?
您可能想阅读 android 中有关 ScaleType 的这篇文章以获得您想要的结果。
这个问题的一个原因是在横向模式和纵向模式下拍照。 如果您曾经在风景模式下拍照,这个问题就解决了。但是在 imageview 和它的顶部之间创建了空 space。