0
我有1 &的數組0 1是黑色的,0是白色的。我想要最快的方法繪製/渲染,顛倒像素顏色,並在iOS中調整圖形大小。我寫了這個代碼,但它似乎慢:iOS中繪製像素陣列
for (int yCoordinate = 0; yCoordinate < height; yCoordinate++)
{
for (int xCoordinate = 0; xCoordinate < width; xCoordinate++)
{
int byteIndex = (bytesPerRow * yCoordinate) + xCoordinate * bytesPerPixel;
int pixel = jbig2_image_get_pixel(imgData, xCoordinate, yCoordinate);
float pixelRGB[]={0,0,0,0};
if(pixel==0)
{
pixelRGB[0] = backRGB[0]; //255.f;
pixelRGB[1] = backRGB[1];
pixelRGB[2] = backRGB[2];
pixelRGB[3] = backRGB[3];
}
else
{
pixelRGB[0] = textRGB[0]; //0.f
pixelRGB[1] = textRGB[1];
pixelRGB[2] = textRGB[2];
pixelRGB[3] = textRGB[3];
}
//Assigning new color components
rawData[byteIndex] = (unsigned char) pixelRGB[0];
rawData[byteIndex + 1] = (unsigned char) pixelRGB[1];
rawData[byteIndex + 2] = (unsigned char) pixelRGB[2];
rawData[byteIndex + 3] = (unsigned char) pixelRGB[3];
}
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext = CGBitmapContextCreate(rawData,
width,
height,
8,
bytesPerRow,
colorSpace,
(CGBitmapInfo)kCGImageAlphaNoneSkipLast);
CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
newUIImage = [UIImage imageWithCGImage:cgImage];
有沒有像CGLayer,UIKit的,等什麼更好的方法,我會很感激,如果有人給我提供一個示例代碼和更好的&更快的方法