繁体   English   中英

需要如何使用iPhone SDK创建/操作图像像素数据的示例

[英]Need example of how to create/manipulate image pixel data with iPhone SDK

寻找一个简单的示例或指向教程的链接。

假设我有一堆存储在数组中的值。 我想创建一个图像并更新我的数组中的图像数据。 假设数组值是强度数据并且将更新灰度图像。 假设数组值在0到255之间 - 或者我将它转换为该范围。

这不是用于动画的目的。 而是基于用户交互来更新图像。 这是我知道如何在Java中做得很好,但对于iPhone编程来说却是一个新手。 我已经搜索了一些有关CGImage和UIImage的信息 - 但我对从何处开始感到困惑。

任何帮助,将不胜感激。

我有一个来自我的应用程序的示例代码,它将数据存储为unsigned char数组并将其转换为UIImage:

// unsigned char *bitmap; // This is the bitmap data you already have.
// int width, height; // bitmap length should equal width * height

// Create a bitmap context with the image data
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate(bitmap, width, height, 8, width, colorspace, kCGImageAlphaNone);
CGImageRef cgImage = nil;
if (context != nil) {
    cgImage = CGBitmapContextCreateImage (context);
    CGContextRelease(context);
}
CGColorSpaceRelease(colorspace);

// Release the cgImage when done
CGImageRelease(cgImage);

如果你的颜色空间是RGB,你需要帐号alpha值传递kCGImageAlphaPremultipliedLast作为CGBitmapContextCreate函数的最后一个参数。

不要使用kCGImageAlphaLast ,这不起作用,因为位图上下文不支持未预乘的alpha。

我在这个SO答案中引用的书籍都包含示例代码以及通过用户交互进行图像处理和更新的演示。

暂无
暂无

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

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