【发布时间】:2014-08-22 12:54:10
【问题描述】:
我有从用 Java 编写的图像中获取像素的功能。我正在将其转换为Objective C。 p1 是我的 Pixel 类的对象。在 getpixels 函数中,前两行显示了如何获取图像的宽度和高度并将其存储到 p1.width 和 p1.height 中。第三行旨在创建一系列等于图像像素数的整数并将它们存储到像素数组中。(即为图像的每个像素创建一个整数)
public void getpixels(Bitmap image, Effect temp)
{
p1.width=image.getWidth();
p1.height=image.getHeight();
p1.pixels=new int[p1.width*p1.height];
}
我已经转换了前两行,但我不知道如何转换第三行。
-(void) getpixels: (UIImage *) image :(Effect *) temp
{
p1.width= (int) image.size.width;
p1.height=(int) image.size.height;
int size= ([p1 width]*[p1 height]);
//array =(
}
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
如果数组创建后需要修改,请查看NSArray或NSMutableArray等子类。
-
数组有多种选择。对于简单的目标 c,请查看
NSArray。对于超低级(快速),请查看malloc和free。要最终获得 UIImage,您可能会通过使用 RGBA 像素值的分配数组的 CGImage(更底层)获得更快的结果。 -
我实际上需要知道我是否可以为数组分配大小,然后将其设置为等于 p1.pixels 吗? (用java代码完成)
标签: objective-c arrays code-conversion