Blurry Drawpicture

I’m not sure they made a mistake, Dave. The DrawPicture method doesn’t allow you to select a scaling algorithm, nor does it specify one. Additionally, Graphics.UseOldRenderer is deprecated. Previously, you depended on the different behaviors of the platform renderers to get that effect you wanted, not RealStudio’s spec for how the method should behave. By contrast, Christian’s MBS function allows you to specify one of many scaling algorithms, including one that would satisfy your specific need. One of my plugins has both bi-linear and pixelated scaling methods. Getting these right from scratch or grafting in a library will take anyone a very good chunk of time. But that’s par for the course when you eschew plugins for whatever reason.

Is this for Mac or Windows?

On Mac you can use to disable image interpolation.

declare sub CGContextSetInterpolationQuality lib "Cocoa" ( context as integer, quality as integer ) CGContextSetInterpolationQuality( g.handle( g.HandleTypeCGContextRef ), quality )

passing in 1 as Quality.

If you wanted to go your own route, I would recommend using creating a routine that reads every pixel and then uses fillRect to create the larger pixel.

[code] Dim x,y,w,h as single
dim rgbs as RGBSurface = p.rgbSurface
Dim pixelwidth as single = g.width / p.width

w = p.width-1
h = p.height-1

for y=0 to h
for x=0 to w
g.foreColor = rgbs.Pixel( x, y )
g.fillRect x * pixelWidth, y * pixelWidth, pixelWidth, pixelWidth
next
next[/code]

This is actually for the same app that I was asking about color reduction for :slight_smile:
The second method you propose is way to slow to support the requirement

Not sure how your first suggestion would be used.

You also seems to find the CAPSLOCK pretty easy. :wink: (please don’t)

Just use the declare of Sam, that will do the trickery.

The more time passes and the more I have the impression that Xojo becomes a shell…

a shell which you have to fill by yourself (or to expect to pay a third party who will do it for you)…

What ever are you complaining about… I have never used the Capslock… and only captialize words that require it … (IT as the abbreviation for Information Technology… and CARBON/COCOA because they are proper names of products)

  • CapsLock = Shouting. Better use bold or italics to emphasize words or parts of sentences.
  • Carbon/Cocoa is never written in all caps.

[quote=71761:@Sam Rowlands]declare sub CGContextSetInterpolationQuality lib “Cocoa” ( context as integer, quality as integer )
CGContextSetInterpolationQuality( g.handle( g.HandleTypeCGContextRef ), quality )[/quote]

Sam… thanks that works… question… it seems to work in a manner that provides the same results as USEOLDRENDERER (but I assume it uses Quartz not the deprecated QuickTime)… so does it set a state in the Graphic Image that needs to be turned OFF like USEOLDRENDERER can be?

Yes… I know that… and I type fast… not fancy… so in that regard I am NOT going to change.

Indeed, it’s all CoreGraphics/Quartz now (there is no other way, no other way).

It set’s it for that Paint operation, but it may overspill into other paint events too… In that case I would suggest the following.

[code] declare sub CGContextSaveGState lib “Cocoa” ( context as integer )
declare sub CGContextSetInterpolationQuality lib “Cocoa” ( context as integer, quality as integer )
declare Sub CGContextRestoreGState lib “Cocoa” ( context as integer )
Dim CGContextRef as integer = g.handle( g.HandleTypeCGContextRef )

CGContextSaveGState CGContextRef
CGContextSetInterpolationQuality CGContextRef, 1

// ---------------------- Do drawing stuff here

// ---------------------- Finished, then restore the previous state.
CGContextRestoreGState CGContextRef[/code]

We use the CoreGraphics’ functions to save the previous state, set our interpolation, do what you need to do and then restore it.

For what it’s worth, Handle returns NULL if drawing outside of the paint event. I doubt your code does that, but it’s worth pointing out.

Sorry, what I meant, is that changing the underlying CGContext, can sometimes overspill into other objects paint events.