How to scale image from range 50%~200%

Posted on 2004-09-24
Last Modified: 2012-06-27
I would like to scale image.
The scale factor will lie within the range 50%~200%.
What shall I do???
Thanks a lot!
Question by:TKD
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +8
LVL 30

Expert Comment

ID: 12149321
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.

Author Comment

ID: 12149338
Program language: C
Platform: Win XP
I know I will lose QUALITY if I resize a raster image.
LVL 11

Expert Comment

ID: 12154597
May be you should try the programming discussions.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

ID: 12208111
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.


Author Comment

ID: 12209968
I would like to write the method by using C source code.
Is there any articles or source codes referenced?
Thanks again.
LVL 11

Expert Comment

ID: 12210892
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.
LVL 22

Expert Comment

ID: 12212211
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!

LVL 17

Expert Comment

ID: 12212932
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.

Author Comment

ID: 12213918
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!

Author Comment

ID: 12213922
I would like to resize the raster image,and save it!

Author Comment

ID: 12214348
I use statement following to display the RGB raster image:
Could I save the output raster image produced by StretchDIBits???
LVL 12

Expert Comment

ID: 12258384
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.
LVL 12

Expert Comment

ID: 12258449
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.

Expert Comment

ID: 12292311
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.

Expert Comment

ID: 12589496
YOu could check out  > open source image editing library.

all your desires are in there probably.
LVL 18

Expert Comment

by:Jose Parrot
ID: 12600197
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


Accepted Solution

modulo earned 0 total points
ID: 12637708
PAQed with points refunded (200)

Community Support Moderator

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…

726 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