c语言中如何将图片翻转,objective-c – 我将图像上下颠倒,但如何将图像水平翻转...

我从相机胶卷加载图像,但此图像是颠倒的.所以我写了旋转它的方法.

CGImageRef imageRef = [image CGImage];

float width = CGImageGetWidth(imageRef);

float height = CGImageGetHeight(imageRef);

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

Byte *rawData = malloc(height * width * 4);

Byte bytesPerPixel = 4;

int bytesPerRow = bytesPerPixel * width;

Byte bitsPerComponent = 8;

CGContextRef context = CGBitmapContextCreate(rawData,width,height,bitsPerComponent,bytesPerRow,colorSpace,kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGColorSpaceRelease(colorSpace);

int byteIndex = 0;

CGContextDrawImage(context,CGRectMake(0,height),imageRef);

Byte *rawData2 = malloc(height * width * 4);

for (int i = 0 ; i < width * height ; i++) {

int index = (width * height) * 4;

rawData2[byteIndex + 0] = rawData[index - byteIndex + 0];

rawData2[byteIndex + 1] = rawData[index - byteIndex + 1];

rawData2[byteIndex + 2] = rawData[index - byteIndex + 2];

rawData2[byteIndex + 3] = rawData[index - byteIndex + 3];

byteIndex += 4;

}

CGContextRef ctx = CGBitmapContextCreate(rawData2,CGImageGetWidth( imageRef ),CGImageGetHeight( imageRef ),8,CGImageGetBytesPerRow( imageRef ),CGImageGetColorSpace( imageRef ),kCGImageAlphaPremultipliedLast );

imageRef = CGBitmapContextCreateImage (ctx);

image = [UIImage imageWithCGImage:imageRef];

CGContextRelease(context);

return image;

没关系,但现在我必须水平翻转它,我不知道我该怎么做.我试着第二天这样做.

谢谢你的帮助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值