tags:

views:

65

answers:

1

hi, i m getting problem with the rotation of image.I want to create a new image with height equals to width because rotating by 90 degrees.but new image created change dimentions but do not place data in image accurately.

CGImageRef imageRef = OriginalImage.CGImage; /////////////new height equals to width of origunal image size_t newHeight = CGImageGetWidth(imageRef); size_t newWidth = CGImageGetHeight(imageRef); size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef); size_t bitsPerPixel = CGImageGetBitsPerPixel(imageRef);

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
CFDataRef argbData = CFDataCreate(NULL,rotatedPixelData,originalImageDataLength);
CGDataProviderRef provider = CGDataProviderCreateWithCFData(argbData);

CGImageRef nimage = CGImageCreate(NewWidth,NewHeight,bitsPerComponent, bitsPerPixel,bytesPerRow,colorspace,bitmapInfo,provider, NULL, true, kCGRenderingIntentDefault);

What should i change in parameters of CGImageCreate?

A: 

You probably need to calculate a newBytesPerRow.

This means that the size of the new image may not be the same
as the original, so recalculate originalImageDataLength too.

Rhythmic Fistman