简体   繁体   English

Objective-C中的Java的setFilterBitmap等效项

[英]Java's setFilterBitmap equivalent in Objective-C

I've a NSBitmapImageRep and trying to set pixel with something like: 我有一个NSBitmapImageRep,并尝试设置像这样的像素:

[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). 它绘制得很好,但是我想设置颜色,使其与相邻像素融合(C#默认情况下具有此颜色,在Java中,可以通过setFilterBitmap(true)进行设置。

setFilterBitmap sets a bitmap to be filtered when it is scaled or rotated. setFilterBitmap设置缩放或旋转位图时要过滤的位图。 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. 如果以原始分辨率且不旋转显示受影响的可绘制对象,则每个像素将与您最初设置的颜色1:1对应。

The Cocoa equivalent would be to use a layer-backed view (see especially setWantsLayer: , I forget what Interface Builder does by default nowadays). Cocoa的等效项是使用层支持的视图(特别是参见setWantsLayer:我忘记了如今Interface Builder的默认功能)。 That'll give your view an associated CALayer object accessible via the layer property. 这将为您的视图提供一个关联的CALayer对象,该对象可通过layer属性访问。 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. 它们具有放大和缩小过滤器,您会注意到magnificationFilter的默认值为kCAFilterLinear ,它的作用应与您提到的Java属性相同。

You should directly manipulate the layer's transform property to adjust how the layer is composited separately from the view. 您应该直接操纵图层的transform属性,以调整如何从视图中单独合成图层。

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 . 看看Core Image Filters

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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