2013-02-14 20 views
0

我没有那么深入的c#知识。我正在使用TeeChart绘制图表。我可以将图表的图像保存为.jpg,.bmp e.t.c.我需要做的是在保存之前我要剪切图像的一部分,然后保存原样,而不改变像素信息或其他任何东西。 enter image description here如何剪辑一些部分TeeChart图片

我想要在块盒子部分内部剪辑。剩下的图应该保持原样。以同样的方式,如果我想要的话,我也可以剪辑结束部分图。图像的像素或高度应该没有变化。以及其余的图像应该覆盖整个图表。可能吗。任何人都可以帮助我请怎么做。

回答

0

您可以从tChart1.Chart.ChartRect中获取图表绘制区域坐标。下面是将图表图例剪切成图像的示例:

public Form1() 
{ 
    InitializeComponent(); 
    InitializeChart(); 
} 

private Bitmap chartBmp; 

private void InitializeChart() 
{ 
    tChart1.Series.Add(new Steema.TeeChart.Styles.Bar()).FillSampleValues(); 

    chartBmp = tChart1.Bitmap; 

    tChart1.GetLegendRect += tChart1_GetLegendRect; 
} 

void tChart1_GetLegendRect(object sender, Steema.TeeChart.GetLegendRectEventArgs e) 
{ 
    Rectangle cropRect = e.Rectangle; 
    Bitmap legendImg = new Bitmap(cropRect.Width, cropRect.Height); 

    using (Graphics g = Graphics.FromImage(legendImg)) 
    { 
    g.DrawImage(chartBmp, new Rectangle(0, 0, legendImg.Width, legendImg.Height), 
        cropRect, 
        GraphicsUnit.Pixel); 
    } 

    legendImg.Save(@"c:\temp\legend.png"); 
} 
+0

非常感谢您的示例代码,我会尝试。 – PRV 2013-02-14 15:15:09

0
var destBitmap = sourceBitmap.Clone(new Rect(0, 0, 100, 200), sourceBitmap.PixelFormat); 
+0

请您能解释一下我背后的一点概念。因为现在我要使用按钮单击并保存图像“mainTChart.Export.Image.Bitmap.Save(Application.StartupPath +”\\ chart.bmp“);”。我想在点击保存按钮之前剪切图片。 – PRV 2013-02-14 13:06:08

+0

@ramjaya只是试一下吗?在我的代码中,'sourceBitmap'是你的'mainTChart.Export.Image.Bitmap'。 – CodeCaster 2013-02-14 13:28:01

+0

不行不行。我对这个概念感到困惑。 – PRV 2013-02-14 14:05:28