Hello,
I used following code to save chart as JPEG file.
My chart''s background color should be white but the saved image''s backgroud color becomes dark.
I attached the image(resized to <2048) and the code here.
Any idea?
public void SaveAs()
{
SaveFileDialog pSaveFileDialog = new SaveFileDialog();
pSaveFileDialog.InitialDirectory=clsApp.NPMAPath+@"\Files\Export";
pSaveFileDialog.DefaultExt="*.bmp";
pSaveFileDialog.Filter = "BMP(*.bmp)|*.bmp|JPG(*.JPG)|*.JPG|WMF(*.WMF)|*.WMF|GIF(*.GIF)|*.Gif|Tiff(*.tif)|*.TIF|PNG(*.Png)|*.Png|Icon(*.ico)|*.ico";
pSaveFileDialog.Title = "Save As ";
pSaveFileDialog.FileName="Untitled";
if (pSaveFileDialog.ShowDialog()==DialogResult.OK)
{
Image bitmap = new Bitmap(chtReport.ClientSize.Width, chtReport.ClientSize.Height);
chtReport.Draw(bitmap);
string sExt=System.IO.Path.GetExtension(pSaveFileDialog.FileName).ToLower();
switch (sExt)
{
case ".jpg":
bitmap.Save(pSaveFileDialog.FileName, ImageFormat.Jpeg);
break;
case ".bmp":
bitmap.Save(pSaveFileDialog.FileName, ImageFormat.Bmp);
break;
case ".wmf":
bitmap.Save(pSaveFileDialog.FileName, ImageFormat.Wmf);
break;
case ".gif":
bitmap.Save(pSaveFileDialog.FileName, ImageFormat.Gif);
break;
case ".tif":
bitmap.Save(pSaveFileDialog.FileName, ImageFormat.Tiff);
break;
case ".png":
bitmap.Save(pSaveFileDialog.FileName, ImageFormat.Png);
break;
case ".ico":
bitmap.Save(pSaveFileDialog.FileName, ImageFormat.Icon);
break;
}
bitmap.Dispose();
string sMsg="The graph has been saved to the file " +pSaveFileDialog.FileName+clsConst.NEW_LINE+"Do you want to open it now?";
DialogResult pDialogResult=MessageBox.Show(sMsg,clsConst.APP_CAPTION,MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (pDialogResult==DialogResult.Yes)
{
clsComm.OpenFile(pSaveFileDialog.FileName);
}
}
}
Untitled_1329.zip