简体   繁体   中英

How to load 16 bits images with UIImage?

I am going to optimize the memory usage of my app. My app has many UIs with graphics which consume much of the device memory.

I tried to use 16 bits images instead of those of 32 bits. The memory consumption of my OpenGL textures is reduced. However, I found that the images held by UIImage consume the same amount of memory as 32 bits images.

Is that UIImage use 8bits per pixel to store the images no matter the pixel format is 16 or 32 bits? Or wt can I do to reduce the memory consumption by 16 bits images??

Thanks a lot.

You can use the the cgdata provider

CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)[NSData dataWithContentsOfFile:@"some_file.png"]);

and then use the

CGImageRef CGImageCreate (
   size_t width,
   size_t height,
   size_t bitsPerComponent,
   size_t bitsPerPixel,
   size_t bytesPerRow,
   CGColorSpaceRef colorspace,
   CGBitmapInfo bitmapInfo,
   CGDataProviderRef provider,
   const CGFloat decode[],
   bool shouldInterpolate,
   CGColorRenderingIntent intent
);

function, setting all the appropriate values for dimensions, bits per pixel and using the data provider created in the first step.

Then get UIImage out of CGImageRefs by [UIImage imageWithCGImage:] method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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