How to scale image from range 50%~200%

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

Improve company productivity with a Business Account.Sign Up

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

modulo
Community Support Moderator
0
 
weedCommented:
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.
0
 
TKDAuthor Commented:
Program language: C
Platform: Win XP
I know I will lose QUALITY if I resize a raster image.
0
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'.

 
Jason210Commented:
May be you should try the programming discussions.
0
 
mikelimaCommented:
The best way is to use the freeware IrfanView.
http://www.tucows.com/preview/194967.html
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.

0
 
TKDAuthor Commented:
Thanks...
I would like to write the method by using C source code.
Is there any articles or source codes referenced?
Thanks again.
0
 
Jason210Commented:
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.
0
 
grg99Commented:
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!






0
 
mokuleCommented:
Hi,
Maybe You will find it interesting:
Quick image scaling by 2

http://www.compuphase.com/graphic/scale2.htm

And this

[1] Riemersma, Thiadmer; "Quick and smooth image scaling with Bresenham"; Dr. Dobb's Journal; May 2002.
0
 
TKDAuthor Commented:
Oh,it seems look like difficultly to implement.
I already read :
http://www.compuphase.com/graphic/scale2.htm
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!
0
 
TKDAuthor Commented:
I would like to resize the raster image,and save it!
0
 
TKDAuthor Commented:
I use statement following to display the RGB raster image:
StretchDIBits(hdc,0,0,OUTPUT_WIDTH,OUTPUT_HEIGHT,0,0,SOURCE_WIDTH,SOURCE_HEIGHT,(LPVOID)RGB,  &bm,  DIB_RGB_COLORS,  SRCCOPY);
Could I save the output raster image produced by StretchDIBits???
0
 
stefan73Commented:
Get an image processing program, such as paintshop pro (http://www.jasc.com) or photoshop (http://www.adobe.com).

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

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

http://developer.gimp.org/api/2.0/libgimp/index.html

There you have the full functionality of GIMP within reach from your C program. Resize, zillions of other things, file formats, etc.
0
 
ThePCNerdCommented:
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.
0
 
michaelbuddyCommented:
YOu could check out imagemagick.org  > open source image editing library.

all your desires are in there probably.
0
 
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

 
0
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.