How to scale image from range 50%~200%

I would like to scale image.
The scale factor will lie within the range 50%~200%.
What shall I do???
Thanks a lot!
Who is Participating?

Improve company productivity with a Business Account.Sign Up

moduloConnect With a Mentor Commented:
PAQed with points refunded (200)

Community Support Moderator
What program? What platform? Gotta give us some info here.

You do realize that ANY time you resize a raster image, you WILL lose quality...right? The more you change the size, the more you lose.
TKDAuthor Commented:
Program language: C
Platform: Win XP
I know I will lose QUALITY if I resize a raster image.
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

May be you should try the programming discussions.
The best way is to use the freeware IrfanView.
this freeware program has the best interpolation method ever create "Lanczos". Not even Photoshop CS can increase the size of images with that quality.

Test for yourself. I have tested all know methods and plugins for Photoshop for a magazine article and Irfanview beat them all (genuine fractals, PhotoZoom, etc.).

Open the program and the image, go to menu
Image > Resize/Resample
image filther method = Lanczos
set new size and voila.

TKDAuthor Commented:
I would like to write the method by using C source code.
Is there any articles or source codes referenced?
Thanks again.
Well, if you're using C then you're going to have to first figure out how to analyse a raster file so that you can access individual pixels of know co-ordinates. Then, you need to figure out some plain old maths for rescaling and interpolation, and write a routine to do this. Finally, you need to put it all back into a new file.

But I still think you're barking up the wrong tree asking in this forum. Try putting a link pointing to this question in the programming discussion here at EE, and try other sites outside EE like Tek-tips. There are plenty of them around.
LIke Jason said, you need to follow a few steps:

(1)  Get the imageinto memory as an array of pixels.  If you're reading a GIF or JPEG file, you need some library routine to do the reading and decoding into pixels.  It's too hard to do this yourself.  See any big graphics library, they allhave this ability.

(2)  If your scale factor is less than 100%, you need a loop that steps along and generates the required number of pixels.  There are many ways of mapping the intermediate pixel locations to the new pixel, the most obvious ways are:  (a) Take the nearest pixel, (b)  Take the average of the two nearest pixels, (c) Better: take the weighted average of the two pixels.  Example: You want to shirink a 100 pixel wide picture to 66%. So you want to step 1.0 / 0.66 pixels each time.  The first pixel position is 1/0.66 or 1.515.  So take 51% of the second pixel and 49% of the first pixel, that's your  output pixel.  Continue on for all 66 output pixels.  Kinda time consuming but good results.   And oh, you should really be doing this in TWO dimensions, so you shoul dnot only go across 1.515 pixels, but DOWN 1.515 pixels also, and do the average of the four or more surrounding pixels.

(3)  If you're expanding the image, you do the same as (2) except turned inside out.  Each output pixel is going to get its info from less than one pixel.   Even tricier to do right..

(4)  Ideally when you do this kind of "resampling", you should run the input and output pictures thru a spatial frequency-domain filter to filter out all kinds of beats and moire patterns that the resampling tends to produce.  This is waaaaay beyond what we can describe in this tiny little box.

Good luck!


OH, BY THE WAY, IF YOURE DOING THIS ON A NICE OPERATING SYSTEM, many HAVE API calls like StretchBits(), or CopyBits(), or BitBlt() or something similar THAT DOES ALL THIS FOR YOU!
If you're not required to do it all yourself, do think about using an existing routine to do this.  it will save you months of work!

Maybe You will find it interesting:
Quick image scaling by 2

And this

[1] Riemersma, Thiadmer; "Quick and smooth image scaling with Bresenham"; Dr. Dobb's Journal; May 2002.
TKDAuthor Commented:
Oh,it seems look like difficultly to implement.
I already read :
Quick and smooth image scaling with Bresenham
But I still don't know how to start.
Could any source code be referenced?
Thanks a lot!
TKDAuthor Commented:
I would like to resize the raster image,and save it!
TKDAuthor Commented:
I use statement following to display the RGB raster image:
Could I save the output raster image produced by StretchDIBits???
Get an image processing program, such as paintshop pro ( or photoshop (

StretchDIBits will not achieve the same quality as a bicubic resize.

If you want to resize as a CGI, have a look at GIMP.
Speaking of GIMP, why don't you use libgimp?

There you have the full functionality of GIMP within reach from your C program. Resize, zillions of other things, file formats, etc.
This man is not wanting to permanently change the image he wants to change it at runtime using C.

I would write this up in the programming portion of this website for the answer, I dont know enough about C or window's api to tell you.
YOu could check out  > open source image editing library.

all your desires are in there probably.
Jose ParrotGraphics ExpertCommented:
I understand that TKD answered its own question, when told us about StretchDIBits. That's right: that API call does what he wants. Probably DrawDib does it better, because is capable of dithering, when the device has less bits per pixel than the bitmap.

The complete answer, for both scaling and storing, is found in the Win32 Programmer's Reference, at the chapter "Using Bitmaps" and its parts: Capturing an image,       Scaling an image and Storing an image. The samples there have all the code TKD is looking for.

Hope it helps...
Jose Parrot

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.