//***************************************************************************** // TGA 処理 //***************************************************************************** #import "../chlibs.h" //***************************************************************************** // UIImage を TGA で保存 //***************************************************************************** void ImageSaveTag(const string filename,const UIImage *image) { string fullpath = [NSHomeDirectory() UTF8String] ; fullpath += filename ; #ifdef DEBUG NSLog(@"save = %@",[NSString stringWithUTF8String:fullpath.c_str()]) ; #endif CGImageRef ImgRef = image.CGImage ; size_t linebyte = CGImageGetBytesPerRow(ImgRef) ; CFDataRef DataRef = CGDataProviderCopyData(CGImageGetDataProvider(ImgRef)) ; const char *data = (const char *)CFDataGetBytePtr(DataRef) ; TGA_HEADER header ; memset(&header,0,sizeof(header)) ; header.ImageType = 2 ; // フルカラー画像 header.Width = CGImageGetWidth(ImgRef) ; header.Height = CGImageGetHeight(ImgRef) ; header.PixelDepth = 32 ; // 色深度 header.ImageDescriptor = 0x20 ; // 上から下 ofstream ofs(fullpath.c_str(),ios::out | ios::trunc | ios::binary) ; ofs.write((char *)&header,sizeof(header)) ; ofs.write(data,linebyte * header.Height) ; ofs.close() ; CFRelease(DataRef) ; }