- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我花了几个小时在谷歌上搜索这个问题的答案并尝试了一些代码,但我就是找不到。我也知道这是一个被问过很多次的问题,但是我不知道现在还能做什么。
我可以从 Met Offices 的 DataPoint API 访问覆盖英国的 500x500 像素降雨雷达图像。它们必须显示在 640x852 像素区域(一个 NSImageView,我目前将其缩放属性设置为与轴无关),因为这是为图像覆盖的边界生成的 map 的正确大小。我想使用最近邻算法以别名格式以 640x852 的放大尺寸显示它们。这可以在 Photoshop 中通过转到“图像”>“图像大小...”并将重新采样设置为最近的邻居(硬边)来实现。源图像应保持 500x500 像素,我只想在更大的 View 中显示它们。
我已经尝试将 NSImageView.layer 的 magnificationFilter 设置为所有三个不同的 kCAFilter... 选项,但这没有任何区别。我还尝试将 NSImageView.layer 的 shouldRasterize 属性设置为 true,这也没有效果。图像总是最终被平滑或消除锯齿,这是我不想要的。
最近刚从 C# 转过来,可能有一些我遗漏的东西,因为我已经很长时间没有使用 Swift 编程了。在 C# 中(使用 WPF),我能够通过将图像元素的 BitmapScalingOptions 设置为 NearestNeighbour 来获得我想要的内容。
总而言之,我想使用 Swift 在像素化形式的 640x852 像素 NSImageView 中显示 500x500 像素的图像,而不进行任何类型的平滑处理(无论显示器是否为视网膜)。感谢您能给我的任何帮助。
下面是实际结果(截图来自 5K iMac): 这是通过使用我的 NSTableView 的 tableViewSelectionDidChange 事件简单地设置 NSImageSource 上的图像属性来创建的,该事件用于选择显示图像的时间,使用:
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")
下面是我想要的样子(忽略背景和裁剪部分)。如果你自己保存图像,你会看到它是像素化的和别名的:
下面是显示源的 map (源只是位于位于另一个包含 map 的 NSImageView 之上的 NSImageView 中):
最佳答案
尝试使用 NSView
的自定义子类代替 NSImageView
。它需要一个 image
属性和一个设置 needsDisplay
的 didSet
观察器。在 drawRect()
方法中,要么:
NSImage
的 drawInRect(_:fromRect:operation:fraction:respectFlipped:hints:)
方法和 hints
字典[NSImageHintInterpolation:NSImageInterpolation.None]
,或者NSGraphicsContext.currentContext.imageInterpolation
的当前值,将其更改为.None
,使用任意绘制NSImage
>draw...(...)
方法,然后恢复上下文的原始 imageInterpolation
值关于swift - 在 640x852 像素的 NSImageView 中显示 500x500 像素的图像,没有任何种类或模糊(OS X 上的 Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35241869/
我有一个 NSTableView,它包含所有 NSImageView 的名称,并且根据 NSImageView 的添加顺序,最后一个将位于前面。 但是如果我希望用户能够将 NSImageViews 放
我有一个 NSImageView 可以很好地作为图像运行。它也是通过绑定(bind)的。使用值路径属性显示每个记录的已保存图像的值转换器(值转换器只是附加文件路径——我只是将图像的文件名存储在数据库中
我想在 NSImageView 中捕捉图像变化的事件,我该怎么做? 最佳答案 您可以尝试使用 KVO监视image键。如果这不起作用,您可能必须继承 NSImageView 并将逻辑插入到 setIm
我创建了 NSImageView 的子类,因为我想自定义一些 mouseClick 事件。但是,我还没开始,就出了问题。我创建了 NSImageView 子类: (文件/新建/文件.../Cocoa(
所以,我的 Cocoa 应用程序中遇到了这个奇怪的问题。一个工具栏项,和一些 NSImageViews 只是渲染他们的图像颠倒,没有明显的原因。当我出于某种原因启动应用程序时,工具栏项目实际上是这样的
我是Mac开发新手,我们有类似的方法吗 imagev = [NSArray arrayWithObjects 我需要一些类似于我们在 iOS 中所做的事情想要在 mac 中做的事情, imageVie
任何人都可以给我推荐一个在 NSImageView 中缩放图像的好示例代码吗?谢谢。 最佳答案 如果你看the documentation ,你会发现 NSImageView 不支持这一点。使用Ima
我有一个 Cocoa 应用程序。在窗口 View 中我放置了一个 NSImageView。使用自动布局,我添加了前导和尾随空格,使得 NSImageView 锚定到 View (以及窗口)。 NSIm
目前我想创建一个圆角NSImageView,我是新手,怎么做? 最佳答案 我不知道这是否有效,所以请尝试一下,我们会祈祷的。在 iPhone 上,您可以使用任何 UIView(iOS 中的 NSVie
所以我习惯了UIImageView ,并能够设置其图像在其中显示的不同方式。例如 AspectFill模式等... 我想使用 NSImageView 完成同样的事情在 Mac 应用程序上。是否NSIm
我有一个使用以下代码的 iOS 应用程序。我现在正在为 Mac OS X 创建应用程序并希望获得相同的效果,但是我似乎无法使用 clipsToBounds .我应该使用什么? 我有其余的代码在 Mac
我正在玩 AppKit 和 NSDocument,但我不知道为什么这不起作用?: 我刚刚写了这个,图像不是零,但从不加载任何图像,它的大小始终为零。 这是我必须实现的正确方法才能将文件读入我的文档吗?
我的 Mac 应用程序中有一些 NSImageView,用户可以在其中拖放 .png 或 .pdf 等对象,将它们存储到用户共享默认值中,这很好用。 我现在想在用户双击这些 NSImageView 时
我是 OS X 编程的初学者,在设置 NSImageView 透明度时遇到问题。 在 iOS 中这很简单,在 UIImageView 中有一个名为 alpha 的属性,我可以更改它并为其设置动画。 (
我如何能够在 Objective C 中屏蔽 nsimageview?例如,有一个带圆角的 nsimageview。 最佳答案 你不知道。如果你想以 NSImageView 不支持的方式绘制图像,则需
出于某种原因,分配两个 NSImageView 会造成巨大的内存泄漏。 尽管 dealloc 方法在两个 NSImageView 中都会被调用。 我正在使用ARC。 使用NSImageViews 一旦
我正在尝试制作一个简单的双骰子游戏。在过去的一年里,我完成了大量的 C 编程,并且正在尝试转换为 GUI 和 Obj C。我的窗口内有一个按钮和两个图像单元。图像被视为输出(染料、染料2),按钮保持
我有多个不同尺寸和比例的 NSImageView,它们垂直堆叠在水平空间有限的 View 中。 由于图像尺寸可能大于父 View 的尺寸,我想使用 NSImageScaleProportionally
我已经 Hook 了 NSTableView 的选择更改事件。我需要在 ImageView 中显示所选图像 func tableViewSelectionDidChange(_ notificatio
我创建了一个 NSView 的自定义子类来控制 2 个 NSImageView。创建图像的代码如下: - (id)initWithFrame:(NSRect)frameRect AndMap:(NSI
我是一名优秀的程序员,十分优秀!