Shrink JPG images, reduce size and bpp

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

I am currently designing a slideshow application that will loop
through all the images under a specific directory. I.E. a storage
card directory. With the variable number of images that could be
displayed, I have chosen to create a doubly linked list with the
physical path as an property and a place holder for the actual image
itself. The idea is that on load the program recursively spins
through the given directory and all sub directories and loads the
filename into the linked list.

At this point a simple loop loads the first 5 images from the memory
card into their respective position in the linked list. I then fire
off two threads. One thread monitors the current position in the list
and keeps 2 images on each side loaded. The other thread does just
the opposite. It monitors all locations greater than two positions
away from the current position and disposes of any images that it
finds there.

The idea is that when put on a timer, the next images will always be
cached in memory.

Ok, the problem is that the images that I am loading are fairly high
quality. Jpeg images that are 2080x1544 and 24 bpp. These images
store in approx 700k. What I am wanting to do is load the image into
memory, convert it to the size of the pictureBox that the image will
be displayed in and reduce the bits per pixel. I have the code that
reduces the size by the correct percentage and that speeds things up,
but I also need to reduce the bpp. Does anyone have any suggestions
about how to do this?

Thanks.

Andy Steinmann
(e-mail address removed)
 
Hi Andy!!!

Definitelly 700K for a jpeg image is too much. What I would do is to
increase the compression of the jpeg to something more workable. Here is the
trick:

When you save a jpeg image, there is a quality vs compression factor.
Typically, this is a scale from 1 to 10. If your pictures are NOT company
loggos, a rate of 5 or 6 will have a nice quality and a size of 150k give or
take.

Now, there are some software application that can do this trick. Adobe
Photoshop is the best of the best (and I love it). Paint Shop Pro is a cheap
and cool application. Now, Microsoft Office comes with Photo Editor, but I
wouldn't recommend it unless it is the last option to use.

Open your pictures with any of the previous applications, and do a "save
as". There must be a button somewhere that gives you more options, and then
play with the compression vs quality rate. Do NOT overwrite the original file
so you can do this operation many times until you find the best compression
vs quality rate.

Hope this helps!

Tarh ik
 
Yeah I know that those images are quite large. I know I can reduce the
size by physically reducing the images. However, what I am looking for
is a way to do it programmatically because I want to be able to read the
images off of a storage card right out of a digital camera.

Does this make sense?

Thanks.

Andy Steinmann
 
Makes good sense, but it's not going to be simple. This is how I'd attack
it:

Use a memory-mapped file to open the file on the storage media to limit the
memory required. Read the image header info to determine current format,
size, etc and determine how you need to "shrink" it. Write a new header
based on that data to another in-RAM file. Next step through the original
file's data blocks and transform them into the in-RAM file's data block.
This will be tough if you want to prevent pixelation of the new image
becasue typically you need to look at all surrounding pixels to determine
what to do, so you'll have to read in 3 scan lines at a time for the
transforms.

The header and data stuff changes based on file type, but all of them are
available in open-source libraries, so you should be able to work it out
(maybe not GIF since it's licensed).

In any case, it's going to be a hell of a lot of work, but when you're done
you'll probably be an expert at image processing.
 
Back
Top