Create a new .png Image in D

I am trying to create a .png image with a high resolution of X pixels and Y pixels. I do not find what I am looking for on dlang.org, and I am struggling to find any other resources through google.

Can you give an example of creating a .png image in D?

For example, BufferedImage off_Image = new BufferedImage(100, 50, BufferedImage.TYPE_INT_ARGB);from http://docs.oracle.com/javase/tutorial/2d/images/drawonimage.html - this is what I am looking for (I think), except for the programming language D.

+4
source share
4 answers

I wrote a small library that can do this too. Take png.d and color.d from here:

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
}
+7

, DevIL FreeImage, , . .

API C .

+5

Phobos 2D 3D- API-, API- ImageIO Java. , D, , C/++, , . , , , GtkD.

+3

- dlib , , - - , , , -, , XML . - ( 2014 ), .

dlib :

import dlib.image;

// width * height
auto image = new Image!(PixelFormat.RGB8)(100, 50);

// fill it in with a gradient
foreach(y; 0 .. image.height)
    foreach(x; 0 .. image.width)
        image[x, y] = Color4f(x * 2 / 255.0f, 0, 0);

savePNG(image, "test.png");

, , ? ..

If you build an application using dub(which you probably should) using the last and best of dlib is as easy as adding "dlib": "~master"to yours dependencies.

+2
source

All Articles