问题描述
我有一个ImageView的是32×32。它是一种基本的精灵。但是,当我去高档的形象,它模糊是这样的:
I have an ImageView that is 32x32. Its a sprite basically. But when I go to upscale the image, it blurs like this:
但我想它在这样的应用程序扩展:
But I want it to scale up in the application like this:
这是code我都试过了,但它不工作。我想被上的ImageView把最终的图像。
This is the code I have tried, but it doesn't work. I want the final image to be put on an 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;
}
}
}
如果你能帮助我,那将是伟大的!谢谢!
If you can help me, that would be great! Thanks!
推荐答案
使用 位图#createScaledBitmap(位图SRC,诠释dstWidth,诠释dstHeight,布尔型过滤器)
。其中一个参数是过滤一个布尔值:请确保您设置为false
Use Bitmap#createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
. One of the parameters is a boolean for filtering: make sure you set that to false.
这篇关于如何高档的图像没有它变得模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!