0
iPad 시뮬레이터 및 장치에서 iOS 4.3을 사용하는 이유는 무엇입니까? 스크린 샷을보십시오. 동일한 이미지가 iOS 5.1 시뮬레이터 및 장치에 정상적으로 표시됩니다. 두 번째 스크린 샷을보세요 ... 어떻게 관리해야합니까? JPEG를 표시하기 전에 일부 코드를 작성할 수 있습니까? 불행히도, 필자는 애플리케이션을 iOS 4.3에서 작동해야한다고 생각합니다. 여전히 부정적이다, 나는 내 이미지를 준비하려면이 옵션을 사용하지 않는 경우,iOS 4.3에서 이미지 네거티브 왜곡
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
{
UIImage *sourceImage = self;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
if (CGSizeEqualToSize(imageSize, targetSize) == NO)
{
CGFloat widthFactor = targetWidth/width;
CGFloat heightFactor = targetHeight/height;
if (widthFactor > heightFactor)
scaleFactor = widthFactor; // scale to fit height
else
scaleFactor = heightFactor; // scale to fit width
scaledWidth = width * scaleFactor;
scaledHeight = height * scaleFactor;
// center the image
if (widthFactor > heightFactor)
{
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
}
else
if (widthFactor < heightFactor)
{
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
}
}
UIGraphicsBeginImageContext(targetSize); // this will crop
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width = scaledWidth;
thumbnailRect.size.height = scaledHeight;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil)
NSLog(@"could not scale image");
//pop the context to get back to the default
UIGraphicsEndImageContext();
return newImage;
}
그러나 때문이 아니라, 더 느리게 작동합니다
이
는이 엄지 손가락의 생성에 사용하는 방법 이미지 크기가 자동으로 조정됩니다. 이 사람들이보기 컨트롤러의 단지 지정 단추는 것을,[current setImage:thumb forState:UIControlStateNormal];
그래, 내가 얘기를 깜빡 했네요 :
-(void) setImage:(UIImage*)image forState:(UIControlState) state
{
[self.buttonView setImage:image forState:state];
}
이 방법 :
이 방법은 이미지를 표시하는 데 사용됩니다.
아마도 .jpg를 .png로 변환하면 작동합니다. – Garoal
질문을 편집해야합니다. 이미지 파일을 만드는 방법을 알려주고 이미지 파일을로드하고 화면에 표시하는 코드를 보여줍니다. –
완료, 메서드를 추가했습니다. 크기를 조정하는 데 사용합니다. – wzbozon