androidqq6
androidqq6

Reputation: 1526

Small Size , High Resolution Images

I create app called it ( app A ) which need to store large No. of high resolution images in res drawable folder , ( i know that i can downloaded remotely , but i need to keep it in drawable res folder ) , its:

3000 x 4000 JPEG images taken by digital camera , as this will lead to unacceptable increase app size and lead to rise memory exception when run it on device ,so can we create another app called
( app B ) , just for resizing the images , which will pick this images that will be stored on SD ( just for purpose of resizing ), then resize it to smaller sized images but without loss image quality and keep high image resolution , then save it again to SD either with PNG or JPEG format , so then i can take images from SD card then save it to ( app A ) resource file and use it , with reasonable size and high resolution ,

hope if any one can supply tutorial or link explaining that or an full code answer applying this ,

Note : i tried using computer software as : photoshop or format factory but all affect the resolution.

your help will be highly appreciated and thanks.

Upvotes: 4

Views: 5265

Answers (4)

Andrew Alcock
Andrew Alcock

Reputation: 19651

This is best solved using image tiling. You break your image into a number of smaller 'tiles', say 500x500px which are then laid out on a grid - pick your favorite layout. For rendering zoomed in, only those tiles that are on-screen will be drawn.

Here is a reference for more details: How to tile and scroll a large image (10000x10000) in android

To split the image, follow the instructions here: Android - Split Drawable

For really smooth behaviour, you can additionally create a scaled down image from the original and use the downscaled tiles when the grid is zoomed out. Switch back to the original resolution as the user zooms in.

EDIT

my goal im have large pic of 3000*4000resolution i want to transform it to smaller size but keep same resolution

There are a few concepts to keep in mind:

  1. The original resolution of the picture (In your case 3000x4000 pixels)
  2. The resolution of the display. For example, a Nexus 4 has a display of 768x1,280 pixels. Displays have an important property: DPI or dots per inch. This is the number of pixels that together measure 1 inch (25.4mm) on the physical screen. Apple's 'retina' displays on the iPhone have a DPI of 326 - this is the benchmark of sharpness; pixels on this screen are too small for the human eye to see individually/sharply at typical holding distance. Old monotone LCD displays have a DPI somewhere in the 30-60 range - you can easily see the square shape of individual pixels.
  3. The portion of the picture to be shown on the display - the view port. There are two different extremes:

    1. Zoom out: You want the complete picture shown on the display. In your case, the picture has more pixels than the display (the display has a physical limitation that there are not enough pixels to show the original picture at the original resolution), so one pixel on the display will render a group of pixels from the picture, averaging the colour and brightness, or
    2. Natural resolution: Natural resolution is where one pixel from the original image is displayed on precisely one pixel on the screen. In you case you would only get to see about than a quarter of the image. This scaling has the greatest sharpness, but some details of the image may be too small to see, because the eye cannot actually see the individual display pixels.
    3. Zoom in: You want to display an even smaller portion of the picture on the display, where the original pixels from the picture are actually larger than the display. Here one pixel from the picture will be displayed on several or many pixels on the display.

Now, the Android image libraries will help. When you render an image on the display, the libraries will scale the picture to "fit" the pixels on the display - your actual picture will be unaltered.

I hope with this new language that you can see the fundamental constraints and can therefore decide how to proceed.

Upvotes: 4

Android Stack
Android Stack

Reputation: 4314

As you said you already try photoshop and gain unacceptable result concerning the resolution ,

there is simple trick found in Photoshop CS and CS2 only :

When you want to reduce an image go to the Image> Image Size menu. Click on 
Resample Image and choose Bicubic Sharper from the drop-down menu. This is the 
best setting for making sure that an image doesn't blur. The example photo of the
flower started at 2,000 pixels across. I stepped it down to 250, and then again 
to 125 with almost no loss of sharpness. 

Another thing to keep in mind

when resizing is to try to do it only once on an image.
Many people will resize repeatedly as they search for the perfect fit for 
a design element, and then end up with an image with a lot of blur. It's always
better to experiment on a duplicate of the image. Then, when you've settled on 
the final dimensions, you can go back to the original and resize it just once.

I already try it my self and have a nice resulted image resolution with small size .

Adapted from this link : http://www.photoshopsupport.com/tutorials/jennifer/bicubic.html

Hope thats help .

Upvotes: 1

Alon Bar David
Alon Bar David

Reputation: 1727

There are basically 3 ways in which you can reduce the size of an image:

  • Reduce it's size and or quality (for instance by reducing the amount of pixels, or the size of each pixel) - Jpeg does something very similar to this.
  • Compress the file - which is what GIF and PNG does.
  • Use vector graphics.

Since you are talking about further compressing a digital camera jpeg image, there's not much you can do to reduce the image itself further without losing more quality (JPEG already both reduces quality and compresses the file, which is why it is the most used type on the web). Any attempt to compress the file without further reducing quality won't give you much ground (though you can try several different compressing schemes, and theres a rare chance you'll hit just the right scheme to gain some substantial reduction).

In theory if you can add all the images together into a single image, and compress it as a single image, it's possible that you can gain some ground, but when talking about such sizes, it's unlikely you'll ever be able to process such a huge file.

Upvotes: 1

faylon
faylon

Reputation: 7450

Use BitmapFactory.Options.inSampleSize to read a subsampled bitmap.

BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 2;
Bitmap bitmap = BitmapFactory.decodeFile(pathName, opts);

And use Bitmap.compress() to save the bitmap to sdcard.

EDIT: If you still want to keep the resolution, you can try to set BitmapFactory.Options.inPreferredConfig = Bitmap.Config.RGB_565; to decode bitmap, this could reduce by half the memory cost since most default config is RGB_8888.

Upvotes: 1

Related Questions