c#实现amcharts图片导出
2010-05-22 14:04
411 查看
实现amcharts导出图片功能详解:
1、控件属性设置
至于控件如何加载到项目中我就不在多说了!baidu吧!
右键点击选控件属性,找到ExportAsImageEnabled设置成true,找到ExportAsImageMessageText设置成导出图片
2、XX_settings.xml设置
在amcharts目录下找到对应的xml文件,填写<file></file>和<target></target>完成设置
注意路径要写对
<export_as_image>
<file>ampie/export.aspx</file>
<target>_blank</target>
<x></x>
<y></y>
<color></color>
<alpha></alpha>
<text_color></text_color>
<text_size></text_size>
</export_as_image>
3、添加接收数据的文件
aspx文件
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="export.aspx.cs" Inherits="_export" %>
aspx.cs文件
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
namespace amCharts
{
public partial class _export : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["width"] != null && Request.Form["width"] != String.Empty)
{
// image dimensions
int width = Int32.Parse((Request.Form["width"].IndexOf('.') != -1) ? Request.Form["width"].Substring(0, Request.Form["width"].IndexOf('.')) : Request.Form["width"]);
int height = Int32.Parse((Request.Form["height"].IndexOf('.') != -1) ? Request.Form["height"].Substring(0, Request.Form["height"].IndexOf('.')) : Request.Form["height"]);
// image
Bitmap result = new Bitmap(width, height);
// set pixel colors
for (int y = 0; y < height; y++)
{
// column counter for the row
int x = 0;
// get current row data
string[] row = Request.Form["r" + y].Split(new char[] { ',' });
// set pixels in the row
for (int c = 0; c < row.Length; c++)
{
// get pixel color and repeat count
string[] pixel = row[c].Split(new char[] { ':' });
Color current_color = ColorTranslator.FromHtml("#" + pixel[0]);
int repeat = pixel.Length > 1 ? Int32.Parse(pixel[1]) : 1;
// set pixel(s)
for (int l = 0; l < repeat; l++)
{
result.SetPixel(x, y, current_color);
x++;
}
}
}
// output image
// image type
Response.ContentType = "image/jpeg";
Response.AddHeader("Content-Disposition", "attachment; filename=/"amchart.jpg/"");
// find image encoder for selected type
ImageCodecInfo[] encoders;
ImageCodecInfo img_encoder = null;
encoders = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo codec in encoders)
if (codec.MimeType == Response.ContentType)
{
img_encoder = codec;
break;
}
// image parameters
EncoderParameter jpeg_quality = new EncoderParameter(Encoder.Quality, 100L); // for jpeg images only
EncoderParameters enc_params = new EncoderParameters(1);
enc_params.Param[0] = jpeg_quality;
result.Save(Response.OutputStream, img_encoder, enc_params);
}
else
{
// invalid post
Response.Write("Invalid post");
}
}
}
}
至此项目就可以导出图片了!
在页面中点击右键就可以看到“导出图片”的选项,试一试 OK吗?
1、控件属性设置
至于控件如何加载到项目中我就不在多说了!baidu吧!
右键点击选控件属性,找到ExportAsImageEnabled设置成true,找到ExportAsImageMessageText设置成导出图片
2、XX_settings.xml设置
在amcharts目录下找到对应的xml文件,填写<file></file>和<target></target>完成设置
注意路径要写对
<export_as_image>
<file>ampie/export.aspx</file>
<target>_blank</target>
<x></x>
<y></y>
<color></color>
<alpha></alpha>
<text_color></text_color>
<text_size></text_size>
</export_as_image>
3、添加接收数据的文件
aspx文件
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="export.aspx.cs" Inherits="_export" %>
aspx.cs文件
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
namespace amCharts
{
public partial class _export : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["width"] != null && Request.Form["width"] != String.Empty)
{
// image dimensions
int width = Int32.Parse((Request.Form["width"].IndexOf('.') != -1) ? Request.Form["width"].Substring(0, Request.Form["width"].IndexOf('.')) : Request.Form["width"]);
int height = Int32.Parse((Request.Form["height"].IndexOf('.') != -1) ? Request.Form["height"].Substring(0, Request.Form["height"].IndexOf('.')) : Request.Form["height"]);
// image
Bitmap result = new Bitmap(width, height);
// set pixel colors
for (int y = 0; y < height; y++)
{
// column counter for the row
int x = 0;
// get current row data
string[] row = Request.Form["r" + y].Split(new char[] { ',' });
// set pixels in the row
for (int c = 0; c < row.Length; c++)
{
// get pixel color and repeat count
string[] pixel = row[c].Split(new char[] { ':' });
Color current_color = ColorTranslator.FromHtml("#" + pixel[0]);
int repeat = pixel.Length > 1 ? Int32.Parse(pixel[1]) : 1;
// set pixel(s)
for (int l = 0; l < repeat; l++)
{
result.SetPixel(x, y, current_color);
x++;
}
}
}
// output image
// image type
Response.ContentType = "image/jpeg";
Response.AddHeader("Content-Disposition", "attachment; filename=/"amchart.jpg/"");
// find image encoder for selected type
ImageCodecInfo[] encoders;
ImageCodecInfo img_encoder = null;
encoders = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo codec in encoders)
if (codec.MimeType == Response.ContentType)
{
img_encoder = codec;
break;
}
// image parameters
EncoderParameter jpeg_quality = new EncoderParameter(Encoder.Quality, 100L); // for jpeg images only
EncoderParameters enc_params = new EncoderParameters(1);
enc_params.Param[0] = jpeg_quality;
result.Save(Response.OutputStream, img_encoder, enc_params);
}
else
{
// invalid post
Response.Write("Invalid post");
}
}
}
}
至此项目就可以导出图片了!
在页面中点击右键就可以看到“导出图片”的选项,试一试 OK吗?
相关文章推荐
- C# 实现Excel导出图片
- C# 导出图片到Word (通过XML实现)
- C#图片压缩的实现方法
- 用GeoTools实现shp+sld导出图片
- CKEditor图片上传功能实现(C#)
- EasyFRMS.Image C# 实现图片剪切、缩放、旋转、水印操作
- atitit.GUI图片非规则按钮跟动态图片切换的实现模式总结java .net c# c++ web html js
- C#实现使用Excel COM组件向Excel文件中添加图片的Demo
- C#实现在图片上斜着写字
- C#简单实现office转pdf、pdf转图片
- asp.net(c#)实现从sqlserver存取二进制图片的代码
- C#实现将文本转换为图片
- C#实现打开画图的同时载入图片、最大化显示画图窗体的方法
- asp.net +C# +sql2000 实现仿csdn的图片轮换代码
- c#实现网页图片提取工具代码分享
- ASP.NET(C#)实现一次性动态上传多张图片的代码(多个文件)
- 【C#/WPF】WPF应用程序,另一类Button按钮(图片)的实现方法。
- C#实现的图片缩放与剪切功能
- C# 实现ComboBox显示图片
- ASP.NET实现写入和读取图片(C#+SQL Server)