First create get BGR array from jpeg image. create Bitmap image header(all bmp image have same header). Append Header to byte array and then append BGR array like B byte then G byte then r byte like wise. Then finally convert byte array to NSDATA. You will get data for BMP image. This code works for Image having 512 X 512 pixel and in BMP image is converted into 24bit bmp image. In code SIDE=512.
imgpath will be like "users/admin" and destimgpath will be like "users/admin/bmpfolder". Filename will be like 1.jpg
-(void) convertJpegToBmp: (NSString *)imgDirPath :(NSString *)destImgPath :(NSString *)fileName
{
NSString *jpegimagepath = [imgDirPath stringByAppendingPathComponent:fileName];
NSString *fileNameWithoutExtension=[[fileName lastPathComponent] stringByDeletingPathExtension];
NSString *bmpFileName=[fileNameWithoutExtension stringByAppendingString:@".bmp"];
NSString *bmpfilepath=[destImgPath stringByAppendingPathComponent:bmpFileName];
int totalbytesinbitmap=(int) (SIDE * SIDE * 3)+54;
Byte bytes[totalbytesinbitmap];
[self writeBitmapHeader:bytes];
UIImage *sourceImage1=[UIImage imageWithContentsOfFile:jpegimagepath];
if(sourceImage1==nil)
return;
CGImageRef sourceImage = sourceImage1.CGImage;
CFDataRef theData;
theData = CGDataProviderCopyData(CGImageGetDataProvider(sourceImage));
UInt8 *pixelDataS = (UInt8 *) CFDataGetBytePtr(theData);
int dataLength = (int)CFDataGetLength(theData);
int k=54;
int row=(int) SIDE -1 ;
int col=0;
int totalbytesinrow=(int) SIDE * 3;
for(int i=0;i> 8) & 0x00ff);
return count;
}
-(int) intToDWord :(int) parValue :(Byte *) pixelData :(int) count{
pixelData[count++]= (Byte) (parValue & 0x000000FF);
pixelData[count++]= (Byte) ((parValue >> 8) & 0x000000FF);
pixelData[count++]= (Byte) ((parValue >> 16) & 0x000000FF);
pixelData[count++]= (Byte) ((parValue >> 24) & 0x000000FF);
return count;
}