I am looking for the best (read: fastest) way to display 120x120px images loaded from a Web URL as 60x60px Retina Image, within the CellTextPaint Event of a Listbox.
Currently i am loading such Images (PNGs) into a NSImageMBS Object and use setSize to scale the Pictures down to 60x60. Then i display them by using the CopyAsPictureWithMask function of the NSImageMBS Class.
Everything is working very well, but the downscaled Pictures are not as sharp as they should be.
I assume the Retina Kit will not help here, or?
How badly ‘not sharp’ are they?
And are you resizing an exact half, or perhaps you may be ‘off by 1’ giving 119 pixels going down to 59?
That would cause some fuzziness.
You can either reduce the size using interpolation
- (which is what you are seeing… its meant to make photos look OK at changed sizes)
Or you can throw away pixels
But if you throw away pixels, then single pixel lines such as outlines get lost in the result.
The best solution is to have 2 sets of pictures, deliberately designed to look right at these sizes… just as we have been doing for icons for years.
I usually find that scaling a small image up looks horrible in OSX.
If it helps, this is the method I use now, to keep small images sharp when upscaled.
The process should work for downscaling, and uses the ‘lost pixels’ method.
[code]Function ResizeTheHardWay(oldpic as picture ,newwid as integer,newheight as integer) As picture
dim x as integer
dim y as integer
dim newpic as picture
dim newrgb as RGBSurface
dim oldrgb as RGBSurface
dim factor as double
newpic = new picture (newwid,newheight,32)
newrgb = newpic.RGBSurface
oldrgb = oldpic.RGBSurface
dim xfact as double
xfact = oldpic.width/newwid
dim yfact as double
yfact = oldpic.height/newheight
for x = 0 to newwid
for y = 0 to newheight
'get the pixel from the source and place it here
newrgb.pixel(x,y) = oldrgb.Pixel(x * xfact,y * yfact)
Thank you Jeff. I will try your solution tonight (CET here).
The images are from a website and are only avail. in 120x120, so i have to downscale.
Everything looks pretty good on standard displays, but on Retina displays the images are really just a little bit, unsharp. And i hope to achive a “perfect” Retina image for my users.