3

I am working on some image processing tasks.

I have made low resolution Bitmap using getDrawingCache() and createScalledBitmap()

But when I resize this image to high resolution say 612 X 612 my image is getting blurred. And it looks so bad.

Is there any way to resize images to high resolutions without losing pixels ? Does openCV has this kind of classes ?

Baz
  • 36,440
  • 11
  • 68
  • 94
Mady Cool
  • 109
  • 2
  • 10
  • 5
    You can't scale up an image without it looking blurry without some very advanced image processing, not the kind that you're going to find available for free. You aren't losing pixels, you need to magically create them out of thin air to fill in the gaps between the pixels you already have. – cjk Oct 09 '12 at 07:47

3 Answers3

5

You can't. If your image is 200x200, then that is how many pixels of information it contains. If you scale it up, it's still the same amount of information only you have to spread it over a wider area.

Think of it like this - say you have an image that is one pixel and that pixel is blue. Now you want to scale that image up to two pixels. What color should the second pixel be? Answer: it can be anything. There is no information in the first pixel that can authoritatively decide what the second pixel should look like, there is no information available.

So, it's not a matter of "loosing pixels" as you put it, it's a matter of adding new pixels with no information on what they should look like. So the resizing uses the information it has, which basically says "make inserted/new pixels same color as closest adjacent pre-existing pixel".

There are algorithms and techniques for interpolation (guessing) what the inserted pixels should look like to avoid jagged edges and such. Wikipedia has some good info on various interpolation-based scaling techniques and supersampling as a starting point. Note though none of these techniques create new information, they only smooth out edges and make the scaled image look less jagged.

pap
  • 27,064
  • 6
  • 41
  • 46
  • But how can i get sample code for this ? I am working on Android environment SDK version 2.2 . Please provide me some links from where i can get nice sample code for resizing Images in Android. Tell me is any API or jars available. – Mady Cool Oct 09 '12 at 08:52
  • Lots available on the net if you search for it. You can also look here http://stackoverflow.com/questions/816548/what-is-the-best-way-to-scale-images-in-java, for instance. – pap Oct 09 '12 at 10:23
1

What you should do is create an original image of size 612 X 612 and then reduced the size and save it as something else so you have an original large image and a small image. Its easy to go from large to small size image than going from small to large.

Yogesh Nath
  • 121
  • 1
  • 11
  • Thanks for your reply. But i already mentioned that i have used getDrawingCache() and it gives me particular view size Bitmap. My View is not high sized. It is arround 200 X 200. So my generated Bitmap is having the same size and i want high resolution Bitmap. – Mady Cool Oct 09 '12 at 08:01
  • Thank you so much for your reply. I have found sample demo and it works like exactly what i want. http://www.wiseandroid.com/post/2010/09/16/Porting-C-code-HQ4X-pixel-scaling-algorithm-on-Android.aspx here it is. – Mady Cool Oct 09 '12 at 10:13
1

I have solved this using Assets..

(1) Put my all images in asset folder

(2) Read images using inputstream

now i dont need to resize it and it works fine as i want. like this:

private void setThemeBackgroundImage(String imageName, Button themeButton) {

        try {
            InputStream backgroundBitmap = getAssets().open(imageName);
            Bitmap immutableBitmap = BitmapFactory
                    .decodeStream(backgroundBitmap);

            themeButton.setBackgroundDrawable(new BitmapDrawable(
                    getResources(), immutableBitmap));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
Mady Cool
  • 109
  • 2
  • 10