图像处理

Tig*_*yan 1 c# image-manipulation image-processing

我需要易于学习和快速的方法从背景图像,文本生成图像,然后保存为JPEG格式.

你能建议什么?有关此的任何图书馆或教程吗?重要的标准是简单.

Sim*_*ens 6

在.Net 3.5/4中,您还可以使用WPF/Media.Imaging作为GDI +的替代方案

首先创建一个DrawingVisual和一个DrawingContext:

DrawingVisual visual = new DrawingVisual();
DrawingContext dc = visual.RenderOpen();
Run Code Online (Sandbox Code Playgroud)

然后在上面画东西:

dc.DrawRectangle(...);
dc.DrawText(...);
etc...
Run Code Online (Sandbox Code Playgroud)

确保你关闭它:

 dc.Close();
Run Code Online (Sandbox Code Playgroud)

关于WPF的好处是GUI中的所有东西实际上也是一个视觉效果,所以如果你喜欢你不必使用上面的代码以编程方式绘制,你实际上可以在窗口上的xaml中构建你的视觉然后只是渲染直接到RenderTargetBitmap.

一旦构建了视觉效果,就可以使用编码器将其渲染到文件中(.Net具有Jpeg,Png,Bmp,Gif,TiffWmp编码器).

// Create a render target to render your visual onto. The '96' values are the dpi's, you can set this as required.
RenderTargetBitmap frame = new RenderTargetBitmap((int)visual.ContentBounds.Width, (int)visual.ContentBounds.Height, 96, 96, PixelFormats.Pbgra32);
frame.Render(visual);

// Now encode the rendered target into Jpeg and output to a file.
JpegBitmapEncoder jpeg = new JpegBitmapEncoder();
jpeg.Frames.Add(BitmapFrame.Create(frame));
using (Stream fs = File.Create(@"c:\filename.jpg"))
{
    jpeg.Save(fs);
}
Run Code Online (Sandbox Code Playgroud)

关于绘图对象WPF图形渲染有一些很好的MS教程.