2013-10-30 3 views
0

내 iPhone 앱에서 이미지 편집을해야합니다. 사용자는 이미지에 자막을 추가 한 다음 해당 이미지를 캡션과 함께 저장하고 해당 이미지를 공유 할 수 있습니다. 우리가 갤러리에서 사진을 선택하면 처음에는 내 이미지보기 위해 이미지의 크기를 조절하는 방법을 아래에 사용했다 :이미지 크기 조정시 이미지 해상도 문제

UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0f); 
float hfactor = img.size.width/screenRect.size.width; 
float vfactor = img.size.height/screenRect.size.height; 

float factor = MAX(hfactor, vfactor); 

float newWidth = img.size.width/factor; 
float newHeight = img.size.height/factor; 

float leftOffset = (screenRect.size.width - newWidth)/2; 
float topOffset = (screenRect.size.height - newHeight)/2; 

if (leftOffset>0) { 
    mainImgView.frame=CGRectMake(leftOffset+10, screenRect.origin.y, newWidth, newHeight); 
} 
else if(topOffset>0) 
{ 
    mainImgView.frame=CGRectMake(screenRect.origin.x, topOffset+10, newWidth, newHeight); 
} 

CGRect newRect = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height); 

[img drawInRect:newRect blendMode:kCGBlendModePlusDarker alpha:1]; 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

return newImage; 

}

캡션과 함께 이미지를 저장을 위해 내가보기의 스크린 샷을 촬영 한 이는 모두에서 이미지보기 및

UIGraphicsBeginImageContextWithOptions(mainImgView.frame.size,NO,0.0f); 
[mainImgView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *newImage=[[UIImage alloc]init]; 
newImage=UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

을하지만 짧은 화면을 복용하여 구원받을 이미지는 매우 낮은 해상도를 가지고 있으며, 우리가 그 이미지를 확대하면 픽셀 화 얻을 : 캡션 레이블 코드 아래 사용하여 촬영하고 있습니다. 실제 해상도로 이미지를 저장하는 방법이 없으므로 그림과 캡션이 모두 이미지로 저장됩니다.

답변

0

이유는 망막 디스플레이를위한 scaleFactor에 있습니다. 망막 장치 이미지는 컨테이너 크기보다 두 배 커야합니다. 사용해보기 :

 UIGraphicsBeginImageContextWithOptions(mainImgView.frame.size,NO, [UIScreen  mainScreen].scale);