画布到WPF的图像问题 [英] Canvas to image problem WPF

查看:116
本文介绍了画布到WPF的图像问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的问题是。如果宽度小于6000没问题,一切都没问题,但如果更大,那么出现我的问题。图像失真。某些形状未显示,白色形状变为黑色等(如 [ ^ ])



我试图分成子图像,但它没有用。



提前致谢。



  public   void  ExportToPng(Canvas canvas,字符串路径,大小)
{
if (path == null return ;
canvas.Measure(size);
var rect = new Rect(size);
canvas.Arrange(rect);
渲染(画布,大小,路径);
}


私有 void 渲染(视觉visual,size size, string path)
{
double dpi = 128 ;
double scale = dpi / 96 ;
RenderTargetBitmap renderBitmap =
new RenderTargetBitmap(
int )( size.Width * scale),
int )(size.Height * scale),
dpi,
dpi,
PixelFormats.Pbgra32);
renderBitmap.Render(visual);
BitmapEncoder encoder = new JpegBitmapEncoder();
使用(FileStream outStream = new FileStream(path,FileMode.Create))
{
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
encoder.Save(outStream);
}
}

解决方案

有很多不同的方法可以尝试这个:

http://stackoverflow.com/questions/5851168/save-canvas-to -bitmap [ ^ ]



最简单的解决方案当然是将imaqge保存为某种矢量格式,但是你必须按原样构建函数,或者看起来似乎是:

http:// social。 msdn.microsoft.com/Forums/en-US/wpf/thread/10ceacdb-1d42-4248-8413-9de6e9034774/ [ ^ ]



你可以使用绘图visu al calass打印它虽然:

http://stackoverflow.com/questions/10160740/how-to-render-a-visualelement-to-a-vector-based-image [ ^ ]



编辑:

这也许值得一试:

http://xamltoys.codeplex.com/ [ ^

Hi people,
My problem is that. If width is less than 6000 not problem, everything is okay, but if greater, then appears my problem. Image is distorted. Some shapes are not shown, white shape turn into black etc. (like this[^])

I tried to separate into subimages, but it didn''t work.

Thanks in advance.

public void ExportToPng(Canvas canvas, string path, Size size)
{
    if (path == null) return;
    canvas.Measure(size);
    var rect = new Rect(size);
    canvas.Arrange(rect);
    Render(canvas, size, path);
}


private void Render(Visual visual, Size size, string path)
{    
    double dpi = 128;
    double scale = dpi / 96;
    RenderTargetBitmap renderBitmap =
        new RenderTargetBitmap(
        (int)(size.Width * scale),
        (int)(size.Height * scale),
        dpi,
        dpi,
        PixelFormats.Pbgra32);
    renderBitmap.Render(visual);
    BitmapEncoder encoder = new JpegBitmapEncoder();
    using (FileStream outStream = new FileStream(path, FileMode.Create))
    {
        encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
        encoder.Save(outStream);
    }
}

解决方案

There are lots of different ways of doing this, you might try this:
http://stackoverflow.com/questions/5851168/save-canvas-to-bitmap[^]

The easiest solution would ofcourse be to save the imaqge in some vector format, but you would have to build the function by had, or so it seems:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/10ceacdb-1d42-4248-8413-9de6e9034774/[^]

You could use the drawing visual calass to print it though:
http://stackoverflow.com/questions/10160740/how-to-render-a-visualelement-to-a-vector-based-image[^]

Edit:
This might also be worth a go:
http://xamltoys.codeplex.com/[^]


这篇关于画布到WPF的图像问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆