2

我有一个 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;
            }
        }
    }

如果你能帮助我,那就太好了!谢谢!

4

2 回答 2

3

使用Bitmap#createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter). 其中一个参数是用于过滤的布尔值:确保将其设置为 false。

于 2014-03-04T21:32:37.813 回答
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);
于 2014-03-04T21:39:51.383 回答