开发者

Image blur in android

I have taken thumbnail image from gallery which is smaller in size and resized into 300*300 size.

By doing that the image looking so blurred.

getting image from gallery

 @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

        switch (requestCode) {
        case 0:
            if (resultCode == RESULT_OK) {
                try {
                    flag = 1;
                    Uri selectedImage = imageReturnedIntent.getData();
                    String[] filePathColumn = { MediaStore.Images.Media.DATA };

                    Cursor cursor = getContentResolver().query(selectedImage,
                            filePathColumn, null, null, null);
                    cursor.moveToFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String filePath = cursor.getString(columnIndex); // file
                    // path
                    // of
                    // selected
                    // image
                    cursor.close();

                    // Convert file path into bitmap image using below line.

                    yourSelectedImage = download.getResizedBitmap(
                        image.decodeImage(filePath),270,228);

                    // put bitmapimage in your imageview
                    profile_image.setImageBitmap(
                            yourSelectedImage);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

Image resizing

public  Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) 
    {
        try
        {
            if(bm!=null)
            {
            int width = bm.getWidth();
            int height = bm.getHeight();
            float scaleWidth = ((float) newWidth) / width;
            float scaleHeight = ((float) newHeight) / height;
            // create a matrix for the manipulati开发者_StackOverflowon
            Matrix matrix = new Matrix();
            // resize the bit map
            matrix.postScale(scaleWidth, scaleHeight);
            // recreate the new Bitmap
            resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); 


            }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

        return resizedBitmap;
    } 


Images get blurred when you enlarge them (unless you are using an vector image and you are using a bitmap). Your getResizedBitmap method doesn't do anything much other than stretching the image to fit the new size. The only way you are going to solve your problem is by selecting larger images (but then eventually you will run into the aspect ratio problem, so you should really rethink your scaling algorithm).


Of course enlarging a bitmap image will be pixelated..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜