.NET图像库 [英] .NET Image Libraries

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

问题描述

C#有哪些好的图像库?主要用于诸如层层绘画之类的事物。或者可能是一个可以描述类似任务的资源?

What are some good image libraries for C#? Mainly for things such as painting in layers. Or maybe a resource that can describe similar tasks?

推荐答案

使用 System.Drawing

Image GetLayeredImage(int width, int height, params Image[] layers)
 {  Point layerPosition = new Point(0,0);
    Bitmap bm = new Bitmap(width,height);
    using(Graphics g = Graphics.FromImage(bm))
     { foreach(Image layer in layers) g.DrawImage(layer, layerPosition);
     }
    return bm;
 }

在上面的例子中,一个方法 GetLayeredImage()被定义为接受合成图像的宽度/高度,以及 Image 对象的数组,每个图层对应一个。 (0,0)处的点被定义为每个层的左上角位置。创建一个位图对象,然后创建一个 Graphics 对象以绘制到位图上。然后,数组中的每个图像都被绘制到点(0,0)处的位图上 - 您可能希望通过为每个图层创建不同的 Point 值来更改此值。然后返回结果位图。返回值是绘制了所有图层的图像。

In the above example, a method, GetLayeredImage() is defined that accepts the width/height of the composite image, along with an array of Image objects, one for each layer. A point at (0,0) is defined as the top-left position for each layer. A Bitmap object is created and from that a Graphics object is created for drawing onto the bitmap. Each image in the array is then drawn onto the bitmap at the point (0,0)—you may want to change this by creating a different Point value for each layer. The resulting bitmap is then returned. The return value is an image with all the layers drawn.

以下是如何调用此方法的示例:

Here's an example on how to call this method:

Image layer1 = Image.FromFile("layer1.jpg");
Image layer2 = Image.FromFile("layer2.jpg");
Image layeredImg = GetLayeredImage(width,height,layer1,layer2);
pictureBox.Image = layeredImg;

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

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