C# 怎么将chart生成的图插入数据库?

chart1.SaveImage(imgStream,System.Drawing.Imaging.ImageFormat.Bmp);ImageoldImg=newBit... chart1.SaveImage(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);
Image oldImg = new Bitmap(imgStream);
Image newImg = new Bitmap(oldImg.Width, oldImg.Height - 189);
Graphics g = Graphics.FromImage(newImg);
g.Clear(Color.WhiteSmoke);
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(oldImg, new Point(0, 0));
g.Dispose();
在这里怎么将 图片不生成文件 直接插入到数据库中?
展开
 我来答
你是谁LCqTt
2011-02-15 · TA获得超过602个赞
知道小有建树答主
回答量:604
采纳率:0%
帮助的人:858万
展开全部
你可以把图片存入一个流里面再读到一个字节数组,然后再存入数据库:
Image img = Image.FromFile("pic1.gif");
MemoryStream ms = new MemoryStream();

img.Save(ms, ImageFormat.Gif);

ms.Position = 0;
var buffer = new byte[ms.Length];

var readCount = 0;
while (readCount < ms.Length)
{
var readed = ms.Read(buffer, readCount, (int)Math.Min(1024, ms.Length - readCount ));
readCount += readed;
}
这样buffer就包含改图片了。至于存数据库我想你肯定会吧。
ftfix23
2011-02-16 · TA获得超过117个赞
知道答主
回答量:212
采纳率:0%
帮助的人:0
展开全部
没有什么好的详细教程,给你简单点的,
简单示例,
<asp:Chart ID="Chart1" runat="server" Height="400px" Width="500px">
<Series>
<asp:Series Name="Series1" ChartType="Column" ChartArea="ChartArea1">
</asp:Series>
<asp:Series Name="Series2" ChartType="Column" ChartArea="ChartArea1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>

后台代码:

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = default(DataTable);
dt = CreateDataTable();

//设置图表的数据源
Chart1.DataSource = dt;

//设置图表Y轴对应项
Chart1.Series[0].YValueMembers = "Volume1";
Chart1.Series[1].YValueMembers = "Volume2";

//设置图表X轴对应项
Chart1.Series[0].XValueMember = "Date";

//绑定数据
Chart1.DataBind();
}
private DataTable CreateDataTable()
{
//Create a DataTable as the data source of the Chart control
DataTable dt = new DataTable();

//Add three columns to the DataTable
dt.Columns.Add("Date");
dt.Columns.Add("Volume1");
dt.Columns.Add("Volume2");

DataRow dr;

//Add rows to the table which contains some random data for demonstration
dr = dt.NewRow();
dr["Date"] = "Jan";
dr["Volume1"] = 3731;
dr["Volume2"] = 4101;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "Feb";
dr["Volume1"] = 6024;
dr["Volume2"] = 4324;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "Mar";
dr["Volume1"] = 4935;
dr["Volume2"] = 2935;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "Apr";
dr["Volume1"] = 4466;
dr["Volume2"] = 5644;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "May";
dr["Volume1"] = 5117;
dr["Volume2"] = 5671;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Date"] = "Jun";
dr["Volume1"] = 3546;
dr["Volume2"] = 4646;
dt.Rows.Add(dr);

return dt;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
easysoft_bj
2011-02-16 · TA获得超过378个赞
知道大有可为答主
回答量:7349
采纳率:0%
帮助的人:2237万
展开全部
图表->网页->WebBrowser截图->处理截图->流->数据库 搞定
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式