我有一个 32x32 的 ImageView。它基本上是一个 Sprite 。但是当我放大图像时,它会像这样模糊:
但我希望它在应用程序中扩展,如下所示:
这是我尝试过的代码,但它不起作用。我希望将最终图像放在 ImageView 上。
@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)
。其中一个参数是用于过滤的 bool 值:确保将其设置为 false。
关于android - 如何在不变得模糊的情况下放大图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22183432/