2010-12-23 97 views
1

我需要在iphone中縮小圖像大小。在iphone應用程序的圖像視圖中縮小圖像大小

我發現以編程方式發送電子郵件在谷歌,但沒有找到關於減少圖像視圖大小的明確信息。

任何人都可以發佈一些示例代碼。

謝謝你提前。

+0

我已附上代碼..檢查出來 – 2010-12-30 12:57:31

回答

0

,你可以不喜歡它:

UIImage* newImage = nil; 
    UIGraphicsBeginImageContext(newFrame); // this will crop  
    [sourceImage drawInRect:newFrame]; 
    newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

這將引起在您指定的幀的圖像。現在如果你想保持縱橫比,你也可以看看Maintain the aspect ratio of an image?

正如我看到你正在使用圖像視圖,所以不要使用我提到的代碼的第一部分。現在,你只有做到:

[imageView setContentMode:UIViewContentModeScaleAspectFit]; 
0

您的意思是縮放圖像所包含的視圖,還是意味着您要重新採樣圖像數據以製作具有較小文件大小的圖像?在谷歌

第一對夫婦的結果提出這個...... Resize Image

+0

嗨,u能plz向代碼如何在iphone – user549767 2011-01-05 05:24:23

0

而是採取的UIButton並設置圖片作爲backgroundImage屬性...這將圖像自動調整大小以按鈕的大小。

-(UIImage*)createThumbNailImage:(UIImage*)myThumbNail:(float)width:(float)height 
{ 

// begin an image context that will essentially "hold" our new image 

UIGraphicsBeginImageContext(CGSizeMake(width,height)); 

// now redraw our image in a smaller rectangle. 
[myThumbNail drawInRect:CGRectMake(0.0, 0.0, width, height)]; 


// make a "copy" of the image from the current context 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 



return [newImage autorelease]; 

} 

幸福iCODING ...

+0

即時顯示圖像的按鈕圖像調整中的ImageView – user549767 2010-12-23 07:25:54

+1

好再轉換該圖像的大小,你要顯示它英寸我已附加代碼創建縮略圖在我的代碼.... :) – 2010-12-24 11:13:18