Hi,
I'm trying to display a
thumbnail of a bitmap I'm using, but I can't see any
obvious way of
'scaling', 'zooming' or 'stretching' the bitmap to fit my required
thumbnail
space.
Any suggestions gratefully received.
Regards
Steve
SC> I'm trying to display a thumbnail of a bitmap I'm using, but I can't
SC> see any obvious way of 'scaling', 'zooming' or 'stretching' the bitmap
SC> to fit my required thumbnail space.
You need to convert your wxBitmap to wxImage, call Scale() and then
convert back. In 2.9 you can also use wxDC::StretchBlit().
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
That's great, thanks very much.
Regards
Steve
> I'm trying to display a thumbnail of a bitmap I'm using, but I can't see
> any obvious way of 'scaling', 'zooming' or 'stretching' the bitmap to fit
> my required thumbnail space.
Others have already answered the howto question. The jargon you want is
"resampling":
<http://en.wikipedia.org/wiki/Resampling_%28bitmap%29>
Scaling, zooming, and stretching can be ambiguous terms that might refer to
optical effects. Resampling is the strictly digital effect of operating on
an array of pixels.
Here's a nice page that shows some example images and how different
resampling algorithms affect the quality of the resulting image:
<http://www.jiscdigitalmedia.ac.uk/stillimages/advice/resampling-raster-images/>
Regards,
Julian
> On a related subject, I've been using .jpg files for storing images. And
> I saw (while looking up 'scaling', 'zooming', etc etc in the wx Book)
> that jpegs are not lossless. I didn't know this before, although I have
> noticed them degrading when editing. What preferences do you have for
> storing images for applications, do you always use PNG? What about GIF?
Lossy encoding is an option of JPEG, frequently chosen because you usually
get better compression. But you can choose a zero-loss encoding at the time
you save, if the application allows it.
<http://en.wikipedia.org/wiki/JPEG#Lossless_editing>
JPEG is best for storing photograph-like images with continous changes in
colors. I generally use PNG for artificial images with sharp edges and
large areas of a single color, like screen captures and cartoon art.
I don't know if GIF has any advantage anymore. At one time PNG was created
to replace GIF due to a license issue, and I don't know if there are any
features of GIF that it doesn't support.
<http://en.wikipedia.org/wiki/Portable_Network_Graphics>
Screen captures in Windows often default to saving in uncompressed BMP
format, and I hate getting those in email, as they're huge and I archive my
mail. You can save these as PNG in Windows Paint since XP came out.
If you're working with vector art, consider using Scalable Vector Graphic
format (SVG). You can edit this with the free Inkscape program. This
combination is similar in capability to the old Corel Draw program. SVG is
an XML format (which can be delivered gzipped for compression). Inkscape
adds its own XML nodes to describe high-level objects like layers and other
edit-time organization.
Steve Cookson skrev:
> Hi Kenneth,
>
> Thanks for this. I guess I'm going to use JPG for photos then and
> PNG for icons. I've noticed the icons have been degrading over time
> as I "improve" them.
>
> But back to the thread, does the format make any difference to "resampling".
>
> Regards
>
> Steve
The resampling has nothing to do with the filetype whatsoever. You
only resample raw image data. Any lossy compression will degrade your
image quality *every time you save*, not while resampling. Try opening
a JPEG file in your favorite editor, choosing to save a copy as JPEG
using quality 95 or so, reopen the newly saved file, save again using
same options, etc. Even though you don't make any edits to the picture
the quality will steadily degrade. This is a feature! Not a bug. It's
intrinsic to the way JPEG works. The 'P' in JPEG is for 'Photographic'
and it really says it all: The format is intended for photographs
where the slight omissions made by the compression algorithm don't matter.
You want to maintain your quality? Choose another format. PNG springs
to mind. :-)
On another note (and off-topic really, I guess) if you want to make
several edits to photographs you've shot or downloaded you may want to
save them in a lossless format, at least while you're doing your
edits, and only use JPEG for the final save...
/Brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkqlhOAACgkQk1tAOprY6QHpFwCgtt1sJeSHr7sOEKR3l/HQJ0P6
NCMAn3zFr3eS+vashFwi4hYgG4fVDf4N
=sbYL
-----END PGP SIGNATURE-----
This isn't necessarily true. Typically the same quantization tables
will get used for a given quality level, and the degradation will
taper off, the files reaching a stable state. This is because
once a DCT coefficient has been quantized to a certain level, it will
be re-quantized to the same level. (Yes I've done the above
exercise to confirm this.) Of course if you alter the file, new losses
will occur.
Graeme Gill.
> You want to maintain your quality? Choose another format. PNG springs
> to mind. :-)
Ah, further reading of the wiki article I referenced earlier indicates that
the file format is always lossy from computing coefficients, so the only
time one doesn't get loss is when one re-saves data with the same
coefficients. I think. The math is on the edge of my understanding, and I
defer to JPEG experts here.