2012-02-22 44 views
3

我使用這個代碼Coreplot圖書館 - 提取整個圖形圖像

UIImage *newImage=[graph imageOfLayer] 
NSData *newPNG= UIImageJPEGRepresentation(newImage, 1.0); 
NSString *filePath=[NSString stringWithFormat:@"%@/graph.jpg",  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];   
if([newPNG writeToFile:filePath atomically:YES]) 
NSLog(@"Created new file successfully"); 

創建圖形圖像,但我得到的圖像纔可見區域(320 * 460),我怎樣才能得到整個圖形圖像與軸。 請提供一些代碼片段,我如何使用coreplot來做到這一點。

在此先感謝...

回答

4

製作一個新的圖表所需的輸出圖像的大小。它不必添加到託管視圖中 - 僅在屏幕上顯示時才需要。

CPTXYGraph *graph = [(CPTXYGraph *)[CPTXYGraph alloc] initWithFrame:desiredFrame]; 
// set up the graph as usual 
UIImage *newImage=[graph imageOfLayer]; 
// process output image 
+0

我不想只有可見區域圖..我也想要看不見的圖..也就是在滾動...即,我得到了320×460的圖形,我在屏幕上看到,但我想要整個圖形,我看到的滾動...不只是增加框架,但整個圖形.........例如,我想要Xaxis 10到200 ..我看屏幕上只有10至100 ...另一個101至200是滾動..所以如何獲得10至200的整個圖像.. – 2012-02-23 05:44:12

+0

非常感謝您的時間和幫助.. – 2012-02-23 05:44:54

+1

當您設置大屏幕外屏時,請設置繪圖範圍以顯示您想要查看的所有數據。 – 2012-02-23 12:04:30

0

我對這個問題的方法是創建一個方法來提取圖像。

在該方法中,我暫時使託管視圖,滾動視圖,圖邊界和繪製區域框架邊界暫時更大。然後我將圖轉換爲圖像。

然後,我從其容器中刪除託管視圖以將其從屏幕中移除。然後我調用doPlot方法,通過DoPlot方法重新初始化繪圖和數據。我的代碼如下。

在執行此操作時可能會出現視覺抖動。但是,您可以通過使用提示輸入電子郵件進行導出,或者只是一個簡單的提醒說出口圖像來掩飾這一點。

//============================================================================= 
/** 
Gets the image of the chart to export via email. 
*/ 
//============================================================================= 
-(UIImage *) getImage 
{ 

    //Temprorarilty make plot bigger. 
    // CGRect rect = self.hostingView.bounds; 
    CGRect rect = self.scroller.bounds; 
    rect.size.height = rect.size.height -100; 

    rect.origin.x = 0; 
    rect.size.width = rect.size.width + [fields count] * 100.0; 
    [self.hostingView setBounds:rect]; 
    [scroller setContentSize: hostingView.frame.size]; 
    graph.plotAreaFrame.bounds = rect; 
    graph.bounds = rect; 


    UIImage * image =[graph imageOfLayer];//get image of plot. 


    //Redraw the plot back at its normal size; 
    [self.hostingView removeFromSuperview]; 
    self.hostingView = nil; 
    [self doPlot]; 

    return image; 
}//============================================================================