2013-10-30 83 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);