任何人都知道如何将.jpg图像转换为.bmp格式在iphone中使用Objective-C? 以及我如何处理(或RGB颜色)iPhone设备caputured图像的每个像素? 是否需要转换图像类型?如何使用Objective C将.jpg图像转换为.bmp格式?
回答
您将无法轻松在iPhone上获得bmp表示。在Mac上的Cocoa中,它由NSBitmapImageRep类管理,并且非常简单,如下所述。
在高层次上,你需要让.JPG成NSBitmapImageRep对象,然后让框架处理转换为您提供:
一个。将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上,BMP不直接支持的UIKit,所以你必须向下拖放到Quartz/Core Graphics和管理改造自己。
像素逐像素处理涉及更多。同样,如果这对您来说很难满足,您应该非常熟悉设备上的核心图形功能。
- 将JPG图像载入
UIImage
,它可以在本机处理。 - 然后,您可以从UIImage对象中获取
CGImageRef
。 - 创建一个新的位图CG图像上下文,它具有您已拥有的图像的相同属性,并提供您自己的数据缓冲区以保存位图上下文的字节。
- 将原始图像绘制到新的位图上下文中:您提供的缓冲区中的字节现在是图像的像素。
- 现在您需要对实际的BMP文件进行编码,这不是UIKit或CoreGraphics(据我所知)框架中存在的功能。幸运的是,这是一个有意无意的格式 - 我在一小时或更短的时间内为BMP编写了快速和不干净的编码器。这里的规范:http://www.fileformat.info/format/bmp/egff.htm(版本3应该没问题,除非你需要支持alpha,但来自JPEG你可能不需要)。
祝你好运。
嗨,你的回答对我真的很有帮助,谢谢。 我可以阅读或比较单词(这是谎言的图像)与其他单词(这也是谎言的形象)?如果可能我该怎么做? – Tirth 2010-07-22 13:51:13
你是指图像中的实际呈现文字?如果是这样,并不平凡 - 图像中的文本识别是整个研究领域。 :)(如果你指的是字节块,那就不一样了) – 2010-07-22 14:37:35
- 1. 在BMP中将BMP转换为JPG
- 2. 如何将jpeg或bmp图像转换为原始格式
- 3. 如何将任何类型(BMP,JPG等)图像转换为DICOM图像
- 4. 如何将.Jpeg图像转换为.Bmp
- 5. c#将所有图像格式转换为JPG
- 6. 使用PHP将PDF转换为JPG格式图像
- 7. 如何将rtf转换为图像格式(jpg/png ..)
- 8. 以编程方式将BMP(或JPG)转换为DDS转换器
- 9. 在java中将bmp转换为jpg
- 10. C#转换图片格式为JPG
- 11. PHP - 将图像从.jpg解压并转换为.bmp
- 12. 将.bmp中的图像格式转换为vb.net中的其他图像格式
- 13. Android NDK:将.jpg转换为.bmp文件
- 14. 将WMF转换为PNG/BMP/JPG
- 15. 如何在ASP.Net中将图像从任何格式转换为JPG格式?
- 16. 如何在Windows上使用Perl将WMF图像转换为PNG或JPG格式?
- 17. 如何将IplImage opencv转换为字节数组(bmp格式)C++?
- 18. 转换.jpg图像以.png格式
- 19. 将BMP图像转换为GRF格式C#/ VB.NET(用于ZPL打印机)
- 20. 将pgm图像转换为bmp
- 21. 如何JPG,位图格式的图像转换成矢量格式在C#
- 22. 将JPG图像转换为tiff文件格式
- 23. 如何在iPhone SDK中将栅格图像(.bmp,.png,.jpg)转换为矢量图像(.svg)
- 24. Android:是否可以将TIFF图像转换为JPG,PNG格式?
- 25. 将EPS转换为JPG格式
- 26. 如何将BMP转换为AVI C#
- 27. 转换图像格式WBMP至BMP/PNG在C#
- 28. 如何使用dcm4che-3.2.1将JPG图像转换为DICOM文件?
- 29. 如何使用GStreamer 1.0将原始BGRA图像转换为JPG?
- 30. 如何用GDI +将图像保存为BMP/PNG/JPG?
你坚持BMP吗?或者你在原始RGB数据之后? – zoul 2010-03-03 10:34:17