【发布时间】:2013-11-15 05:18:30
【问题描述】:
我在重新缩放位图后遇到质量问题 我从资产中加载图像,因此解码它们必须由 Stream 完成
这是我的方法
InputStream is = getAssets().open(lol.get(zpositions));
Bitmap bm = BitmapFactory.decodeStream(is);
Bitmap mBitmap = Bitmap.createScaledBitmap(bm,width,hight, false);
我试过了
Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inPreferredConfig = Config.ARGB_8888;
Bitmap bitmapsrc = BitmapFactory.decodeStream(is, null, options);
Bitmap mBitmap = Bitmap.createScaledBitmap(bitmapsrc,width,hight, false);
但还是同样的问题
知道如何绕过这个问题吗?谢谢
这里是代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip"
android:background="@android:color/black" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
/>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullimage);
Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
height = display.getHeight();
AdView adView = (AdView)findViewById(R.id.ad);
adView.loadAd(new AdRequest());
Intent i = getIntent();
List<String> lol = i.getStringArrayListExtra("lol");
this.lol = lol;
pagerPosition = i.getExtras().getInt("id");
{
public Bitmap getbitBitmap() throws IOException{
positions = MyPageChangeListener.getCurrentPage();
if (positions == 0) {
zpositions = pagerPosition;
}
InputStream is = getAssets().open(lol.get(zpositions));
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap bitmapsrc = BitmapFactory.decodeStream(is, null, options);
return bitmapsrc;
}
private void CropWallpaper() throws IOException {
Bitmap mBitmap = Bitmap.createScaledBitmap(bitmapsrc,width, height, false);
try {
setWallpaper(mBitmap);
Toast.makeText(this,"Cropped successfully" , Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this,"Failed to Crop" , Toast.LENGTH_SHORT).show();
// TODO: handle exception
}
}
【问题讨论】:
-
你是想增加还是减少?增加必然会对质量产生负面影响。在某种程度上,减少也会,但这些通常可以通过使用混叠来解决。
-
我们需要知道您“assets”文件夹中资源图片的宽度和高度,以及您发送给
Bitmap.createScaledBitmap()的宽度和高度。 -
我正在尝试调整图像大小以适应屏幕大小我知道位图宽度/高度也屏幕宽度/大小,但使用 Bitmap.createScaledBitmap() 在调整大小后降低质量是我的问题跨度>