4

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.

androidqq6
  • 1,526
  • 2
  • 22
  • 47
  • You're going to lose image quality if you want a lower resolution or less size. – AHungerArtist Dec 06 '12 at 10:09
  • @AHungerArtist i kow but each image around 4 -5 mb size and using around 250 image this result in huge app size and lag of device so whats you suggest to solve that with please ,thanks – androidqq6 Dec 06 '12 at 10:16

4 Answers4

4

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.

Community
  • 1
  • 1
Andrew Alcock
  • 19,401
  • 4
  • 42
  • 60
  • i support your answer.... but you can use images 1024x1024... every android phone will support this large bitmaps! – silly Dec 12 '12 at 11:50
  • Sure - depending on available RAM, they will support *very* much larger images. The issue is the speed with which the CPU can rescale the image. The larger the image, the slower it will be, so pinch-to-zoom will be very jerky. with smaller images, and zoomed in on a small section, the CPU has to scale only ONE of the 1kx1k images. – Andrew Alcock Dec 12 '12 at 12:21
  • @AndrewAlcock thanks sir for your answer acually im still new to android and java development ,can you please explain to me more , my goal im have large pic of 3000*4000resolution i want to transform it to smaller size but keep same resolution , thanks again – androidqq6 Dec 16 '12 at 17:49
  • @Andrew Alcock thanks sir for your answer acually im still new to android and java development ,can you please explain to me more , my goal im have large pic of 3000*4000resolution i want to transform it to smaller size but keep same resolution , thanks again – androidqq6 Dec 16 '12 at 17:49
  • Added a discussion on images, displays and view ports – Andrew Alcock Dec 17 '12 at 01:25
1

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.

faylon
  • 7,360
  • 1
  • 30
  • 28
  • please can you write down more detailed code regarding 1-pick from sd , 2- resize , 3 - save it again in png format , thanks – androidqq6 Dec 06 '12 at 09:42
  • No, this method won't work. inSampleSize will change the resolution and aslo decrease the size. – Royston Pinto Dec 06 '12 at 09:42
  • @Royston Pinto im new to android i want to have the right solution without affect quality , thanks – androidqq6 Dec 06 '12 at 09:45
  • 1
    Sorry, i didn't notice that. But if you want to keep the resolution, the memory cost will not change no matter what you do. – faylon Dec 06 '12 at 09:59
  • Basically, inSampleSize = 2 will divide width/2 and height/2 and totalSize/4. So a 4MB image will become a 1MB image with halved width and height. – Royston Pinto Dec 06 '12 at 11:21
1

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.

Alon Bar David
  • 1,757
  • 14
  • 15
1

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 .

Android Stack
  • 4,314
  • 6
  • 31
  • 49