在D中创建新的.png图像

Evo*_*lor 4 d image

我正在尝试创建一个高X像素,Y像素短的.png图像.我没有找到我在dlang.org上寻找的东西,并且很难通过谷歌找到任何其他资源.

您能否提供一个如何在D中创建.png图像的示例?

例如,BufferedImage off_Image = new BufferedImage(100, 50, BufferedImage.TYPE_INT_ARGB);来自http://docs.oracle.com/javase/tutorial/2d/images/drawonimage.html是我正在寻找的(我认为),除了D编程语言.

Ada*_*ppe 7

我写了一个可以做到这一点的小lib.从这里获取png.d和color.d:

https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff

import arsd.png;

void main() {
    // width * height
    TrueColorImage image = new TrueColorImage(100, 50);

    // fill it in with a gradient
    auto colorData = image.imageData.colors; // get a ref to the color array
    foreach(y; 0 .. image.height)
        foreach(x; 0 .. image.width)
        colorData[y * image.width + x] = Color(x * 2, 0, 0); // fill in (r,g,b,a=255)
    writePng("test.png", image); // save it to a file
}
Run Code Online (Sandbox Code Playgroud)


eco*_*eco 5

标准库中没有任何图像工作,但您应该能够使用DevIL或FreeImage来执行您想要的操作.他们都有废弃的绑定.

只需使用其中任何一个的C API文档.