2012-02-19 23 views
0

好吧,我沒有找到它的任何地方。如果我想繪製每個像素的核心圖形,我應該怎麼做?像...我想畫一條線到像素(45,61)和比(46,63),而不是畫到點(23,31)或類似的東西。那麼在這種情況下我應該怎麼做?核心圖形拖動像素而不是點

我應該使用類似:

CGContextAddLineToPoint(context,22.5,30.5); 
CGContextAddLineToPoint(context,23,31.5); 

還是有一些更好的辦法?

我知道contentScaleFactor但(例如繪製一些功能時)我應該使用它作爲:

for(int x=bounds.origin.x; x<=bounds.origin.x+bounds.size.width*[self contentScaleFactor]; i++) 
    CGContextAddLineToPoint(context,x/[self contentScaleFactor],y(x/[self contentScaleFactor])); 

我知道的例子代碼不是一流的,但我認爲你會得到理念。

我會很感激的幫助,因爲我有點困惑這一切比例因子的東西。

回答

1

聽起來像你正在從iOS uTunes斯坦福大學課程做Assignment3? :)
我認爲你是在正確的軌道上,我的實現看起來很相似:

for(int x=self.bounds.origin.x; x<=self.bounds.origin.x + (self.bounds.size.width * self.contentScaleFactor); x++) { 
    // get the scaled X Value to ask dataSource 
    CGFloat axeX = (x/self.contentScaleFactor - self.origin.x)/self.scale; 

    // using axeX here for testing, which draws a x=y graph 
    // replace axeX with the dataSource Y-Point calculation 
    CGFloat axeY = -1 * ((axeX * self.scale) + self.origin.y); 

    if (x == self.bounds.origin.x) { 
     CGContextMoveToPoint(context, x/self.contentScaleFactor, axeY); 
    } else { 
     CGContextAddLineToPoint(context, x/self.contentScaleFactor, axeY);   
    } 
} 


測試iOS上,iPhone4的SIM卡(contentScaleFactor 1.0)+ iPhone4S的設備(contentScaleFactor 2.0)。
對於其他讀者可能的改進感到高興,因爲我仍在學習。

+0

我有完全相同的解決方案。接受第一個x的處理(但它不影響scalfactor的東西:)) – Uko 2012-02-25 07:18:46