getting started ios - npedotnet/npe-image-library GitHub Wiki

Getting Started on iOS

Supports

  • BMP/GIF/JPEG/PNG/TIFF
  • DDS/PSD/TGA

Require

  • J2ObjC-0.9.7

Package

npe-image-library-ios-1.0/
+ include/
+ lib/libnpeimage.a
+ util/

libnpeimage.a is a fat library of i386, x86_64, armv7, armv7s, arm64.

Xcode Settings

BuildSettings > Search Paths > User Header Search Paths

j2objc-0.9.7/include npe-image-library-ios-1.0/include

BuildSettings > Linking > Other Linker Flags

-ObjC

Build Phases > Link Binary With Libraries

libnpeimage.a
libjre_emul.a
libicucore.dylib
Security.framework
libz.dylib

Coding

Please customize util/ImageReader.m for easy coding.

Initialization

#import "ImageReader.h"

call npeInitializeImageLibrary() once.

npeInitializeImageLibrary();

Create a UIImage with Main Bundle

NSString *path = [[NSBundle mainBundle] pathForResource:@"test.png" ofType:@""];
UIImage *image = [ImageReader createUIImage:path];

Create a CGImageRef with Main Bundle

NSString *path = [[NSBundle mainBundle] pathForResource:@"test.png" ofType:@""];
CGImageRef image = [ImageReader createCGImage:path];

Create a PixelImage with Main Bundle

support dds/psd/tga only

NSString *path = [[NSBundle mainBundle] pathForResource:@"test.tga" ofType:@""];
NetNpeImagePixelImage *image = [ImageReader read:path];

Create a UIImage from a PixelImage

NetNpeImagePixelImage *pixelImage = ...;
UIImage *image = [ImageReader createUIImageFromPixelImage:pixelImage];

Create a CGImageRef from a PixelImage

NetNpeImagePixelImage *pixelImage = ...;
CGImageRef image = [ImageReader createCGImageFromPixelImage:pixelImage];

Customize memory management

customize allocateMemory/freeMemory methods if needed.

+ (void *)allocateMemory:(size_t)size {
    return malloc(size);
}

+ (void)freeMemory:(void *)memory {
    free(memory);
}