Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to shrink image in high quaulity?

Posted on 2003-02-25
Medium Priority
Last Modified: 2013-11-20
I want to shrink monochrome images in high quality. I have tried to use StretchBlt and set stretch mode to HALFTONE. The effect is very good but the HALFTONE mode doesn't support WIN9x. And I also tried to apply convolution algorithm to smooth images before shrinking, when the shrinking rate is not very high, say 0.4, the effect is acceptable, but if the rate is high, less than 0.3, the effect is bad. To improve the shrinking quality, I have convert the monochrome images from 1 bit to 8 bit format. Is there anyone know how do I shrink images in high quality?
Question by:PearlChen

Accepted Solution

Answers2000 earned 200 total points
ID: 8024895
Convert them to gray scale when scaling down.

Algorithm is:-

For every pixel in destination bitmap
  Work out a square/rectangle of pixels in source bitmap
  X = The average color (black = 0, white=255) of pixels in this source square. Simply loop over this square, add up a running total, and at end divide by how many pixels in this square.
  Set destination pixel color to RGB(X,X,X)


Assume scaling down by half: 2X2 square in monochrome, has 0, 1, 2 or 3 pixels set to white. If it's  This can means destination pixel is RGB(0,0,0), RGB(64,64,64), RGB(128,128,128),RGB(192,192,192) or RGB(255,255,255)

If you scale down by 1/3 or more, you're going to start losing data, but will work. You probably need to go 24 bit color at this point to get it to look really good.

Author Comment

ID: 8031827
Thank you very much, anwser2000. I have tried your algorithm in my program and the result turned out to be what I exactly want. I converted the bilevel bitmaps into gray scale bitmaps(8 bits per pixel), then selected a pallete created by myself which including 256 steps of gray scale.

I have thought my desired result must be gained through some complicated algorithm. I didn't expect it is so easy. The truth is always simple.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question