osx - Displaying a 500x500 pixel image in a 640x852 pixel NSImageView without any kind or blurriness (Swift on OS X) -
i have spent hours on google searching answer , trying pieces of code have not been able find one. recognise question has been asked lots of times, not know else now.
i have access 500x500 pixel rainfall radar images met offices' datapoint api, covering uk. must displayed in 640x852 pixel area (an nsimageview, have scaling property set axis independent) because correct size of map generated boundaries covered imagery. want display them @ enlarged size of 640x852 using nearest neighbour algorithm , in aliased format. can achieved in photoshop going image > image size... , setting resample nearest neighbour (hard edges). source images should remain @ 500x500 pixels, want display them in larger view.
i have tried setting magnificationfilter of nsimageview.layer 3 of different kcafilter... options has made no difference. have tried setting shouldrasterize property of nsimageview.layer true, had no effect. images end being smoothed or anti-aliased, not want.
having come c#, there have missed have not been programming in swift long. in c# (using wpf), able want setting bitmapscalingoptions of image element nearestneighbour.
to summarise, want display 500x500 pixel image in 640x852 pixel nsimageview in pixelated form, without kind of smoothing (irrespective of whether display retina or not) using swift. can give me.
below actual result (screenshot 5k imac): created setting image property on nsimagesource tableviewselectiondidchange event of nstableview used select times show image for, using:
let selected = times[timestable.selectedrow] let formatter = nsdateformatter() formatter.dateformat = "d/m/yyyy 'at' hh:mm" let date = formatter.datefromstring(selected) formatter.dateformat = "yyyymmdd't'hhmmss" imagedata.image = nsimage(contentsoffile: basepathstr + "rainobs_" + formatter.stringfromdate(date!) + ".png")
below want (ignoring background , cropped out parts). if save image see pixellated , aliased:
below map source displayed on (the source in nsimageview laid on top of nsimageview containing map):
try using custom subclass of nsview
instead of nsimageview
. need image
property didset
observer sets needsdisplay
. in drawrect()
method, either:
- use
drawinrect(_:fromrect:operation:fraction:respectflipped:hints:)
method ofnsimage
hints
dictionary of[nsimagehintinterpolation:nsimageinterpolation.none]
, or - save current value of
nsgraphicscontext.currentcontext.imageinterpolation
, change.none
, drawnsimage
ofdraw...(...)
methods, , restore context's originalimageinterpolation
value
Comments
Post a Comment