English 中文(简体)
利用CGBitmap制作的形象
原标题:Using image created with CGBitmapContextCreate as an opengl texture

I m generating an image using quartz2d and I want to use it as an opengl texture. The tricky part is that I want to use as few bits per pixel as possible, so I m creating cgContext as following:

int bitsPerComponent = 5;
int bytesPerPixel = 2;
int width = 1024;
int height = 1024;
void* imageData = malloc(width * height * bytesPerPixel);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageContext context = CGBitmapContextCreate(imageData, width, height, bitsPerComponent, width * bytesPerPixel, colorSpace, kCGImageAlphaNoneSkipFirst);
//draw things into context, release memory, etc.

As stated in the documentation here, this is the only supported RGB pixel format for CGBitmapContextCreate which uses 16 bits per pixel. So now I want to upload this imageData which looks like "1 bit skipped - 5 bits red - 5 bits green - 5 bits blue" into an opengl texture. So I should do something like this:

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, imageData); 

That won t work because in this call I ve specified pixel format as 5 red - 5 green - 5 blue - 1 alpha. That is wrong, but it appears that there is no format that would match core graphics output.
There are some other options like GL_UNSIGNED_SHORT_1_5_5_5_REV, but those wont work on the iphone.

我需要以某种方式使用这一<代码>imageData作为案文,但我确实不想通过人工使用薄膜或薄膜抽打,因为这似乎非常低效。

问题回答

你们确实需要绕行借方,以便把它变成像RGBA551或RGB565一样的更密集的形式,因为正如你指出的那样,CGBitmap 并没有支持这些提款形式(为了简便和高效)。

is,但<代码>Accelerate.framework有“fast”转换常规。

vImageConvert_ARGB88toRGB565(......)vImageConvert_ARGB88toARGB1555(......),可在OS 5上查阅,以后可查到。

内容提要

vImage_CGImageFormat fmt = {
    .bitsPerComponent = 5,
    .bitsPerPixel = 16,
    .colorSpace = NULL, // faster with CGImageGetColorSpace(cgImage) if known to be RGB
    .bitmapInfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Little // ARGB1555 little endian
};
vImage_Buffer buf;
vImageBuffer_InitWithCGImage( &buf, &fmt, NULL, cgImage, kvImageNoFlags );

......

free(buf.data);

数据是用制成的,同时还有图像高、宽度和生长精度。 我不记得,对于是否允许鞭.,GL的要求是什么。 你们可以通过预先分配制成像和制革来控制。 浏览器场和通过悬挂国旗的圆顶。

565_REV is kCGImageAlphaNone | kCGBitmapByteOrder16Little. 5551_REV is kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder16Little





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签