我有一个32x32的ImageView。它基本上是一个精灵。但是当我去升级图像时,它会像这样模糊:
但我希望它在这样的应用程序中扩展:
这是我尝试的代码,但它不起作用。我希望将最终图像放在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;
}
}
}
如果你能帮助我,那就太好了!谢谢!
答案 0 :(得分:3)
使用Bitmap#createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
。其中一个参数是用于过滤的布尔值:确保将其设置为false。
答案 1 :(得分:1)
这就是我在这个问题的另一个答案的帮助下得到它的方法:
这是代码:
Options options = new BitmapFactory.Options();
options.inDither = false;
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(getResources(), R.drawable.your_image, options);
final int maxSize = 960; //set this to the size you want in pixels
int outWidth;
int outHeight;
int inWidth = source.getWidth();
int inHeight = source.getHeight();
if(inWidth > inHeight){
outWidth = maxSize;
outHeight = (inHeight * maxSize) / inWidth;
} else {
outHeight = maxSize;
outWidth = (inWidth * maxSize) / inHeight;
}
Bitmap resizedBitmap = Bitmap.createScaledBitmap(source, outWidth, outHeight, false);
picture = (ImageView)v.getTag(R.id.picture);
picture.setImageBitmap(resizedBitmap);