简体   繁体   中英

Java's setFilterBitmap equivalent in Objective-C

I've a NSBitmapImageRep and trying to set pixel with something like:

[imageRep setColor:color atX:point y:val]

It draws fine but I want to set the color such that it blends with the neighboring pixels (C# has it by default, and in Java it can be done by setFilterBitmap(true).

setFilterBitmap sets a bitmap to be filtered when it is scaled or rotated. It does not inherently have any effect on the pixels. If you displayed an affected drawable at its native resolution and with no rotation, each pixel would correspond 1:1 with the colours you had set originally.

The Cocoa equivalent would be to use a layer-backed view (see especially setWantsLayer: , I forget what Interface Builder does by default nowadays). That'll give your view an associated CALayer object accessible via the layer property. Those have magnification and minification filters and you'll notice that the default for magnificationFilter is kCAFilterLinear , which should give the same effect as the Java property you mention.

You should directly manipulate the layer's transform property to adjust how the layer is composited separately from the view.

Pixels are the basic unit of an image -- you can't really blend them together. You can either manually choose your colors so that adjacent pixels are similar or apply a filter afterwards. Have a look at Core Image Filters .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM