簡體   English   中英

這是將大圖像繪制到UIView的最佳方法嗎?

[英]Is this the best way to draw large images to a UIView?

我正在使用的應用程序需要我將圖像繪制到UIView 這些圖像很大(有些是1024x768),我想確保我的繪圖代碼不是次優的。 我的UIView drawRect方法如下所示:

- (void)drawRect:(CGRect)rect {
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextClearRect(context, rect);

  CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, 550);
  CGContextConcatCTM(context, flipVertical);
  CGImageRef shadowImage = [[UIImage imageNamed:@"someimage.png"] CGImage];
  CGContextDrawImage(context, CGRectMake(162, -174, 700, 700), shadowImage);
  CGContextConcatCTM(context, flipVertical);
}

這里也完成了其他繪制,但是我只是想確保圖像繪制代碼不會引起問題,並且我也沒有忽略調用重要方法或錯誤地實現此方法。

我發現此方法由於使用

[UIImage imageNamed:@"someimage.png"]

此方法將圖像加載到內存中,然后將其緩存以備后用。 因為我正在使用的圖像很大,並且有很多圖像,所以使用此方法可能會導致過多的內存使用。

我寫了一篇簡短的文章 ,內容更詳細。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM