How to upscale an image without it becoming blurry

倾然丶 夕夏残阳落幕 提交于 2019-12-06 12:20:11

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.

This is how I got it working with the help of the other answer on this question:

This is the code:

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!