我正在尝试创建一个 X 像素高和 Y 像素短的 .png 图像。我在 dlang.org 上找不到我要找的东西,并且正在努力通过 google 找到任何其他资源。
您能否提供一个如何在 D 中创建 .png 图像的示例?
例如,BufferedImage off_Image = new BufferedImage(100, 50, BufferedImage.TYPE_INT_ARGB);
来自 http://docs.oracle.com/javase/tutorial/2d/images/drawonimage.html是我正在寻找的(我认为),除了在 D 编程语言中。
最佳答案
我写了一个小库也可以做到这一点。从这里获取 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
}
关于image - 在 D 中创建新的 .png 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21197984/