• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1644
  • Last Modified:

How do I zoom into a picture by a percentage without loosing its quality?

Hello,
I am implementing an MFC static library module in C language with Visual Studio 6.0 and i want to implement a function that makes zoom into a picture by a percent given. (For 0< percent < 1 make it smaller and for percent > 1 make it bigger. ) The picture is of a face and is grayscale and I dont want to miss any information out of it.
The reason why i want to do this, is because i have a bounding box of random pixel dimensions (eg 300x300 or 350x162 or 400x400 or 100x110 or what ever smaller than 500x500) and i want it to be resized to (100x150).
Thank you
0
nroussis
Asked:
nroussis
2 Solutions
 
Infinity08Commented:
>> The picture is of a face and is grayscale and I dont want to miss any information out of it.

What do you mean by "not missing any information" ? If you make the image smaller, certain pixels will be lost ... If you make it bigger, you'll have to fill in (guess, extrapolate) ceryain pixels. In any case, the data will not be exactly the same.
0
 
evilrixSenior Software Engineer (Avast)Commented:
You'll find a number of image manipulation libraries at the site below
http://www.efg2.com/Lab/Library/ImageProcessing/SoftwarePackages.htm

Specifically, try looking at ImageMagick
http://www.imagemagick.org/script/index.php

"ImageMagick┬« is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and B├ęzier curves.

The functionality of ImageMagick is typically utilized from the command line or you can use the features from programs written in your favorite programming language. Choose from these interfaces: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++), JMagick (Java), L-Magick (Lisp), NMagick (Neko/haXe), MagickNet (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), IMagick (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images dynamically and automagically.

ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you may freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems."
0
 
DanRollinsCommented:
The fundamental procedire is:

1) Create a new bitmap that has the desired size
2) Use this GDI function to copy the data, stretching or shrinking as needed:
    StretchBlt
    http://msdn2.microsoft.com/en-us/library/ms532355.aspx

I must also echo what Infinity08 said:  If you make an image larger (to "zoom in" on it) then you do not get more detail... you just get bigger pixels (unlike what you see in crime-drama TV shows where they magnify a blurry image of somebody's wristwatch to get the reflection of somebody's eyeglasses in order to view the words on a scrap of paper across the street).  All you get is bigger dots.  Likewise, if you shrink an image, you *must* lose detail by thowing out some pixels.  Images shrunk that way usually look fine, but data is inevitably lost (so you must always keep a copy of the original image).

Do you need help in figuring out how to apply a percentage growth or shrinkage in order to calcuate the new size?
0
 
alb66Commented:
You can use IPicture interface:

http://msdn.microsoft.com/msdnmag/issues/01/10/c/
0
 
itsmeandnobodyelseCommented:
>>>> The picture is of a face and is grayscale and I dont want to miss any information out of it.
The only way to 'miss' no information is to provide a own picture for each resolution you want to display. All other methods will give poor to bad results, especially if the 'source' you operate on already is *reduced* to screen resolutions. If you have photo resolution your picture may have a hundred times more pixels than with the desired 300 x 300 screen resolution. With the photo as source you may get acceptable images on screen when using professional tools. But if you already have reduced information you were lost, especially if there is any text inside.

You easily can see what I mean if you would call the StretchBlt function (which actually would do what you were requesting). If the new resolution was smaller, the StretchBlt simply cuts some columns or rows what rarely gives accepable results.
0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now