Iphone 如何使用Objective C将.jpg图像转换为.bmp格式?
有人知道如何在iphone中使用objective-C将.jpg图像转换为.bmp格式吗? 我如何处理(或RGB颜色)IPhone设备上的每个像素的彩色图像?Iphone 如何使用Objective C将.jpg图像转换为.bmp格式?,iphone,objective-c,Iphone,Objective C,有人知道如何在iphone中使用objective-C将.jpg图像转换为.bmp格式吗? 我如何处理(或RGB颜色)IPhone设备上的每个像素的彩色图像? 是否需要转换图像类型 您将无法在iPhone上轻松获得bmp表示。在Mac上的Cocoa中,它由NSBitmapImageRep类管理,并且非常简单,如下所述 在较高级别上,您需要将.jpg转换为NSBitmapImageRep对象,然后让框架为您处理转换: a。将JPG图像转换为NSBitmapImageRep b。使用内置的NSBit
是否需要转换图像类型 您将无法在iPhone上轻松获得bmp表示。在Mac上的Cocoa中,它由NSBitmapImageRep类管理,并且非常简单,如下所述 在较高级别上,您需要将.jpg转换为NSBitmapImageRep对象,然后让框架为您处理转换: a。将JPG图像转换为NSBitmapImageRep b。使用内置的NSBitmapImageRep方法以所需格式保存
NSBitmapImageRep *origImage = [self documentAsBitmapImageRep:[NSURL fileURLWithPath:pathToJpgImage]];
NSBitmapImageRep *bmpImage = [origImage representationUsingType:NSBMPFileType properties:nil];
- (NSBitmapImageRep*)documentAsBitmapImageRep:(NSURL*)urlOfJpg;
{
CIImage *anImage = [CIImage imageWithContentsOfURL:urlOfJpg];
CGRect outputExtent = [anImage extent];
// Create a new NSBitmapImageRep.
NSBitmapImageRep *theBitMapToBeSaved = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL pixelsWide:outputExtent.size.width
pixelsHigh:outputExtent.size.height bitsPerSample:8 samplesPerPixel:4
hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0 bitsPerPixel:0];
// Create an NSGraphicsContext that draws into the NSBitmapImageRep.
NSGraphicsContext *nsContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:theBitMapToBeSaved];
// Save the previous graphics context and state, and make our bitmap context current.
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext: nsContext];
CGPoint p = CGPointMake(0.0, 0.0);
// Get a CIContext from the NSGraphicsContext, and use it to draw the CIImage into the NSBitmapImageRep.
[[nsContext CIContext] drawImage:anImage atPoint:p fromRect:outputExtent];
// Restore the previous graphics context and state.
[NSGraphicsContext restoreGraphicsState];
return [[theBitMapToBeSaved retain] autorelease];
}
在iPhone上,UIKit不直接支持BMP,因此您必须亲自访问并管理转换
逐像素处理要复杂得多。同样,如果对您来说这是一个硬要求,那么您应该非常熟悉设备上的核心图形功能
UIImage
cImageRef
李>
祝你好运。你坚持BMP吗?还是你想要原始的RGB数据?嗨,你的回答对我很有帮助,谢谢。我可以阅读或比较这些单词(位于图像上)与其他单词(也位于图像上)吗?如果可能的话,我是怎么做的?你是说图像中的实际渲染文本吗?如果是这样的话,那么从图像中识别文本是一个完整的研究领域(如果你指的是字节块中的单词,那就不同了)