0
에서있는 UIImage 자르기 나는 다음과 같은 코드를 가지고 : 나는 photoData을 사용하고있는 UIImage으로 바꿀 때는 저장 및 아이폰 카메라
float photoWidth = photo.size.width;
float photoHeight = photo.size.height;
UIImage *picture = nil;
if (photoWidth < photoHeight)
{
// Portrait
// Scale the photo down
CGRect rect = CGRectMake(0.0, 0.0, 450.0, 600.0);
UIGraphicsBeginImageContext(rect.size);
[photo drawInRect:rect];
picture = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else
{
// Landscape
// Crop off the edges
float scale = photoHeight/photoWidth;
float newWidth = photoHeight * scale;
float newHeight = photoHeight;
float newX = (newHeight - newWidth)/2.0;
float newY = 0.0;
CGRect cropped = CGRectMake(newX, newY, newWidth, newHeight);
CGImageRef imageRef = CGImageCreateWithImageInRect ([photo CGImage], cropped);
UIImage * croppedPhoto = [UIImage imageWithCGImage: imageRef];
CGImageRelease (imageRef);
// Scale the photo down
CGRect rect = CGRectMake(0.0, 0.0, 450.0, 600.0);
UIGraphicsBeginImageContext(rect.size);
[croppedPhoto drawInRect:rect];
picture = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
NSData *photoData = UIImagePNGRepresentation(picture);
는 세로 모드는 잘 작동합니다. 하지만 가로 모드에 문제가 있습니다.
사진의 왼쪽 및 오른쪽 가장자리에서 자른 것이 내 풍경과 동일한 크기로 풍경을 만들려고합니다.
또한 사진 찍을 때 가로 카메라를 뒤집어 놓으면 방향이 내 사진을 뒤집어 엎었습니다.
내가 잘못하고있는 것입니까?
감사합니다.
에
을 변경하려고합니다. 풍경 카메라를 잡는 방법에 따라 사진은 거꾸로되어 있고 두 번째 rect는 꺼져 있습니다. – cdub