objective-c - 将 NSBitmapImageRep 转换为 NSImage
问题描述
我在NSImage
and之间切换NSBitmapImageRep
(因为只NSBitmapImageRep
允许我查找-替换每个像素的颜色,但只有sNSImage
可以在NSImageView
/中使用)。我知道如何将 a 转换为(使用),但我不能做相反的事情,因为它是只读的。那么,如何将 a 转换为 a ?NSImageCell
setImage
NSImage
NSBitmapImageRep
bitmap = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]]
TIFFRepresentation
NSBitmapRep
NSImage
带着希望,
拉佐73
解决方案
从修改后的 NSBitmapImageRep 中取回 NSImage 所要做的就是调用一种方法:
NSImage *image = [[NSImage alloc] initWithSize:someSize];
[...]
NSBitmapImageRep *rawImage = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
[code that gets and sets pixels]
[image initWithCGImage:[rawImage CGImage] size:image.size]; // overwrite original NSImage with modified one
推荐阅读
- python - 将坐标循环成重复 len(x) 次的字符串
- python - 大文本编辑,粘贴替换
- sublimetext3 - 自定义 JSX 的 Emmet 缩写
- c++ - 解决错误:operator[] 不匹配
- aws-lambda - 无法在 AWS Lambda 中初始化 Dialogflow Fulfillment WebhookClient
- android - Gradle 同步失败:原因:未指定 compileSdkVersion
- python - 如何动态查询一个mongoDB文档
- haskell - 组合不同类型的流
- react-native - react-native iOS 生产 JS 包
- sql - 使用 sql 从交易明细中获取贷方和借方