views:

41

answers:

2

Hi all,

I want a functionality in my iPhone application which will convert the image to its mirror like way.

Like if there is an image of man with his left hand up Then the converted image must have the same man with his right hand up.

Any code or link will be really appreciated

Thanks in advance for any help.

A: 

You might try this

myView.transform = CGAffineTransformMake(-1,0,0,1,0,0);

Sorry I can't be more help. It was a while ago that I used this horizontally flip a UIView, so I am bit rusty on specifics.

westsider
Hello westsider,Thanks for reply But I dont want to transform my view but I want to transform the image saved in documents directory. Any Idea?
Suriya
You might take a look at <http://stackoverflow.com/questions/2653241/uigraphicsgetimagefromcurrentimagecontext-gives-poor-quality-low-resolution-ima>. This is not something that I've done - but the 'answer' and the followup comments seem helpful.
westsider
A: 

// convert CIImage to unsigned char*
NSBitmapImageRep * bitRep = [[NSBitmapImageRep alloc] initWithCIImage:sourceImage];
unsigned char * pixels = (unsigned char *)[bitRep bitmapData];

// find mirrored pixel, for 1D pixels array
// for 2D array it will be something like:
// pixels2D[x,y] = pixels2D[Image.width-1-x,y]

// convert modified unsigned char* back to CIImage
CGColorSpaceRef colorSpaceToUse = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
NSData *_pixelsData = [NSData dataWithBytesNoCopy:pixels length:(sizeof(unsigned char)*4*Image.Width*Image.Height) freeWhenDone:YES ];
CIImage *_dataCIImage = [[[CIImage alloc] initWithBitmapData:_pixelsData bytesPerRow:(Image.Width*4*sizeof(unsigned char)) size:CGSizeMake(Image.Width,Image.Height) format:kCIFormatARGB8 colorSpace:colorSpaceToUse] autorelease];
0x69
hey 0x69 I need the code for objective C not any other language
Suriya
ObjC example code added, I just skipped mirrored pixel lookup in 1D pixel array. I think you are smart enough to manage it yourself :)
0x69