Ich lade Bild von der Kamera roll, aber dieses Bild ist auf dem Kopf. Also habe ich eine Methode geschrieben, um es zu drehen.Ich dreh das Bild auf den Kopf, aber wie man es horizontal dreht
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, 0, width, 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;
es ist ok, aber jetzt muss ich es horizontal spiegeln, und ich weiß nicht, wie ich das tun kann. Ich versuche, diesen zweiten Tag zu machen.
danke für die Hilfe
Ich muss UIImage transformieren und es auf CGContextRef zeichnen, daher ist '.transform' nicht verfügbar. Ich versuche, UIImage zu UIImageView hinzuzufügen, es zu drehen und 'image = imageView.image' zu machen, aber es funktioniert nicht. –
Bitte sehen Sie meine Bearbeitung, wie Sie den Bildinhalt in ein Bild "konvertieren" können. – sergio
es funktioniert, aber ich setze 'imageview.frame = CGRectMake (111,122,768,1024)' und es rendern Kontext bei '0,0,768,1024'. irgendein Vorschlag? –