我用指定图片填充柱状图中的柱子后,图片一点都不清晰,上面有一层网格的线条。就像我填充用颜色填充柱子,颜色不是很纯,有一格一格的样子。我要怎么把那些网格去掉呢?完全显示我的图片的效果.
有查到资料说把背景色设置为透明的,但是我g.Clear(Color.Transparent);颜色却是黑色的。
下面是我调用图片的代码:
newImage = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("../images/bar_chart_yellow.png"));
g.DrawImage(newImage, barOrigin.X - 2, barOrigin.Y, barWidth + 5, barHeight);
你的柱状图用的啥控件?
测试用绘制代码:
protected void Page_Load(object sender, EventArgs e)
{
Bitmap bm = new Bitmap(500, 300);
Graphics g = Graphics.FromImage(bm);
g.Clear(Color.Black);
g.DrawString(string.Format("Background PixelFormat:{0}", Enum.GetName(typeof(PixelFormat), bm.PixelFormat)), new Font("宋体", 9), Brushes.White, new Point(5, 5));
g.DrawString(string.Format("Graphics InterpolationMode:{0}", Enum.GetName(typeof(InterpolationMode), g.InterpolationMode)), new Font("宋体", 9), Brushes.White, new Point(5, 20));
g.DrawString(string.Format("Graphics CompositingMode:{0}", Enum.GetName(typeof(CompositingMode), g.CompositingMode)), new Font("宋体", 9), Brushes.White, new Point(5, 35));
g.DrawString(string.Format("Graphics CompositingQuality:{0}", Enum.GetName(typeof(CompositingQuality), g.CompositingQuality)), new Font("宋体", 9), Brushes.White, new Point(5, 50));
g.DrawString(string.Format("Graphics PageUnit:{0}", Enum.GetName(typeof(GraphicsUnit), g.PageUnit)), new Font("宋体", 9), Brushes.White, new Point(5, 65));
g.DrawString(string.Format("Graphics SmoothingMode:{0}", Enum.GetName(typeof(SmoothingMode), g.SmoothingMode)), new Font("宋体", 9), Brushes.White, new Point(5, 80));
g.DrawLine(new Pen(Color.White, 1), 250, 250, 450, 250); //绘制横向
g.DrawLine(new Pen(Color.White, 1), 250, 50, 250, 250); //绘制纵向
using (System.Drawing.Image newImage = System.Drawing.Image.FromFile("E:\\AspNetDrawing\\2010083110444572.png"))
{
g.DrawString(string.Format("Image PixelFormat:{0}", Enum.GetName(typeof(PixelFormat), newImage.PixelFormat)), new Font("宋体", 9), Brushes.White, new Point(5, 95));
// 绘制柱状图
g.DrawImage(newImage, 260, 149, 36, 100);
g.DrawImage(newImage, 300, 199, 36, 50);
g.DrawImage(newImage, 400, 49, 41, 200);
}
bm.Save(Response.OutputStream, ImageFormat.Jpeg);
bm.Dispose();
g.Dispose();
}
绘制的图片:
你可以试试用MSChart 来自动生成 柱状图形啊,