UIImageview의 너비가 75이고 높이가 75 인 뷰가 있습니다. 카메라 또는 사진 라이브러리에서 이미지를 캡처하고 크기를 조정하고 이미지 뷰로 설정합니다.iphone 전체 화면 크기 조정 이미지 미리보기
캡처 한 이미지를 서버에 업로드했지만 크기가 조정 된 이미지가 업로드되고 이미지 품질이 손실됩니다. 서버에서 검색하는 동안 흐림 이미지가 표시됩니다.
지금, 내가, 내가 이미지 뷰에 탭 때마다 전체 화면 이미지 미리보기가 표시되어야하고, 나는 다음과 같은 코드
- (UIImage*)imageWithImage:(UIImage*)sourceImage scaledToSize:(CGSize)newSize;
{
CGFloat targetWidth = newSize.width;
CGFloat targetHeight = newSize.height;
NSLog(@"target Width:%f",targetWidth);
NSLog(@"target Height:%f",targetHeight);
CGImageRef imageRef = [sourceImage CGImage];
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);
if (bitmapInfo == kCGImageAlphaNone) {
bitmapInfo = kCGImageAlphaPremultipliedLast;
}
CGContextRef bitmap;
if (sourceImage.imageOrientation == UIImageOrientationUp || sourceImage.imageOrientation == UIImageOrientationDown) {
bitmap = CGBitmapContextCreate(NULL, targetWidth, targetHeight, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
NSLog(@"ImageOrientation UP/DOWN");
} else {
bitmap = CGBitmapContextCreate(NULL, targetHeight, targetWidth, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
}
if (sourceImage.imageOrientation == UIImageOrientationLeft) {
NSLog(@"ImageOrientation LEFT");
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -targetHeight);
} else if (sourceImage.imageOrientation == UIImageOrientationRight) {
NSLog(@"ImageOrientation RIGHT");
CGContextRotateCTM (bitmap, radians(-90));
CGContextTranslateCTM (bitmap, -targetWidth, 0);
} else if (sourceImage.imageOrientation == UIImageOrientationUp) {
NSLog(@"ImageOrientation UP/DOWN");
// NOTHING
} else if (sourceImage.imageOrientation == UIImageOrientationDown) {
CGContextTranslateCTM (bitmap, targetWidth, targetHeight);
CGContextRotateCTM (bitmap, radians(-180.));
}
// CGContextSetInterpolationQuality(bitmap, 1);
CGContextDrawImage(bitmap, CGRectMake(0, 0, targetWidth, targetHeight), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage* newImage = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return newImage;
}
를 사용하여 이미지 크기를 조정할
고품질 이미지 대신 크기가 조정 된 이미지 업로드해야 필요 복원되지 않습니다 다시 위쪽으로 크기를 조정 - 당신이 품질이 손실 75x75까지 이미지 크기를 조절하면
나에게
같은 축소 된 크기의 새로운 이미지를 생성하지 않는 콘텐츠 모드를 변경하면됩니다. 그것은 하나의 이미지에 대한 나쁜 생각은 아닐 것이다. – Robin
@robin : 이미지를 업데이트하면 이미지가 업데이트되면 앱이 다운됩니다. 메모리 경고 – duk