我有一个32x32的图像视图。基本上是雪碧。但当我把图像放大时,它会模糊成这样:
但我希望它在应用程序中按如下方式扩展:
这是我试过的代码,但不起作用。我想把最后的图像放在图像视图上。
@Override
public View getView(int i, View view, ViewGroup viewGroup)
{
View v = view;
ImageView picture;
TextView name;
if(v == null)
{
v = inflater.inflate(R.layout.gridview_item, viewGroup, false);
v.setTag(R.id.picture, v.findViewById(R.id.picture));
v.setTag(R.id.text, v.findViewById(R.id.text));
}
picture = (ImageView)v.getTag(R.id.picture);
name = (TextView)v.getTag(R.id.text);
Item item = (Item)getItem(i);
Options options = new BitmapFactory.Options();
options.inDither = false; //I THOUGHT THAT TURNING THIS TO FALSE WOULD MAKE IT NOT BLUR, BUT IT STILL BLURRED
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(getResources(), item.drawableId, options); //THIS IS THE BITMAP. THE RESOURCE IS THE ID OF THE DRAWABLE WHICH IS IN AN ARRAY IN ANOTHER PLACE IN THIS FILE
picture.setImageBitmap(source); //THIS SETS THE IMAGEVIEW AS THE BITMAP DEFINED ABOVE
name.setText(item.name);
return v;
}
private class Item
{
final String name;
final int drawableId;
Item(String name, int drawableId)
{
this.name = name;
this.drawableId = drawableId;
}
}
}
如果你能帮助我,那就太好了!谢谢!
最佳答案
使用Bitmap#createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
。其中一个参数是用于筛选的布尔值:确保将其设置为false。