我在重新缩放位图后遇到质量问题我从资产中加载图像,因此解码它们必须由 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
}
}