Silverlight我使用Visifire的Charts控件,设置Chart的ToolBarEnabled属性为True 5

我使用Visifire的Charts控件,设置Chart的ToolBarEnabled属性为True,画图后在左上角出现保存按钮,保存后,打开图片却无法预览。请问是我少设... 我使用Visifire的Charts控件,设置Chart的ToolBarEnabled属性为True,画图后在左上角出现保存按钮,保存后,打开图片却无法预览。请问是我少设置了什么属性吗?求解。 展开
 我来答
真的还可以吧
2014-03-31 · TA获得超过112个赞
知道答主
回答量:197
采纳率:0%
帮助的人:137万
展开全部
这个必须要写代码的。
给你参考一下
#region 导出chart图片
/// <summary>
/// Save Visifire chart as Image
/// </summary>
/// <param name="visifire_Chart">Visifire.Charts.Chart</param>
public static void SaveToImage(Chart chart)
{
try
{
WriteableBitmap bitmap = new WriteableBitmap(chart, null);

if (bitmap != null)
{
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.Filter = "JPG Files (*.jpg)|*.jpg";
saveDlg.DefaultExt = ".jpg";

if ((bool)saveDlg.ShowDialog())
{
using (Stream fs = saveDlg.OpenFile())
{
MemoryStream stream = GetImageStream(bitmap);

//Get Bytes from memory stream and write into IO stream
byte[] binaryData = new Byte[stream.Length];
long bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
fs.Write(binaryData, 0, binaryData.Length);
}
}
}
}
catch (Exception ex)
{
//System.Diagnostics.Debug.WriteLine("Note: Please make sure that Height and Width of the chart is set properly.");
//System.Diagnostics.Debug.WriteLine(ex.Message);
}
}

/// <summary>
/// Get image MemoryStream from WriteableBitmap
/// </summary>
/// <param name="bitmap">WriteableBitmap</param>
/// <returns>MemoryStream</returns>
public static MemoryStream GetImageStream(WriteableBitmap bitmap)
{
byte[][,] raster = ReadRasterInformation(bitmap);
return EncodeRasterInformationToStream(raster, ColorSpace.RGB);
}

/// <summary>
/// Reads raster information from WriteableBitmap
/// </summary>
/// <param name="bitmap">WriteableBitmap</param>
/// <returns>Array of bytes</returns>
public static byte[][,] ReadRasterInformation(WriteableBitmap bitmap)
{
int width = bitmap.PixelWidth;
int height = bitmap.PixelHeight;
int bands = 3;
byte[][,] raster = new byte[bands][,];

for (int i = 0; i < bands; i++)
{
raster[i] = new byte[width, height];
}
for (int row = 0; row < height; row++)
{
for (int column = 0; column < width; column++)
{
int pixel = bitmap.Pixels[width * row + column];
raster[0][column, row] = (byte)(pixel >> 16);
raster[1][column, row] = (byte)(pixel >> 8);
raster[2][column, row] = (byte)pixel;
}
}

return raster;
}

/// <summary>
/// Encode raster information to MemoryStream
/// </summary>
/// <param name="raster">Raster information (Array of bytes)</param>
/// <param name="colorSpace">ColorSpace used</param>
/// <returns>MemoryStream</returns>
public static MemoryStream EncodeRasterInformationToStream(byte[][,] raster, ColorSpace colorSpace)
{
ColorModel model = new ColorModel { colorspace = ColorSpace.RGB };
FluxJpeg.Core.Image img = new FluxJpeg.Core.Image(model, raster);

//Encode the Image as a JPEG
MemoryStream stream = new MemoryStream();
FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, 100, stream);
encoder.Encode();

// Back to the start
stream.Seek(0, SeekOrigin.Begin);
return stream;
}
#endregion
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式