[英]no suitable conversion function from “Magick::Color” to “MagickCore::Quantum” exists
I know already why it gives that error code-wise.我已经知道为什么它会在代码方面给出错误。 Problem is, I started using the library itself today and following the tutorial I found this.
问题是,我今天开始使用库本身,并按照我发现的教程进行操作。
I installed the "ImageMagick-7.0.9-1-Q16-x64-dll" version of the library, and tried to find the shortest code that gave that error, which is:我安装了库的“ImageMagick-7.0.9-1-Q16-x64-dll”版本,并试图找到给出该错误的最短代码,即:
#include <Magick++.h>
int main(){
Magick::Quantum result = Magick::Color("black");
}
Given the tutorial(following one), a method that converts from Magick::Color to Magic::Quantum should exist鉴于教程(以下),应该存在从 Magick::Color 转换为 Magic::Quantum 的方法
// Example of using an image pixel cache
Image my_image("640x480", "white"); // we'll use the 'my_image' object in this example
my_image.modifyImage(); // Ensure that there is only one reference to
// underlying image; if this is not done, then the
// image pixels *may* remain unmodified. [???]
Pixels my_pixel_cache(my_image); // allocate an image pixel cache associated with my_image
Quantum* pixels; // 'pixels' is a pointer to a Quantum array
// define the view area that will be accessed via the image pixel cache
int start_x = 10, start_y = 20, size_x = 200, size_y = 100;
// return a pointer to the pixels of the defined pixel cache
pixels = my_pixel_cache.get(start_x, start_y, size_x, size_y);
// set the color of the first pixel from the pixel cache to black (x=10, y=20 on my_image)
*pixels = Color("black");
// set to green the pixel 200 from the pixel cache:
// this pixel is located at x=0, y=1 in the pixel cache (x=10, y=21 on my_image)
*(pixels+200) = Color("green");
// now that the operations on my_pixel_cache have been finalized
// ensure that the pixel cache is transferred back to my_image
my_pixel_cache.sync();
which gives that error ( no suitable conversion function from "Magick::Color" to "MagickCore::Quantum" exists ) at the following lines在以下行中给出了该错误(没有合适的转换 function 从“Magick::Color”到“MagickCore::Quantum”存在)
*pixels = Color("black");
*(pixels+200) = Color("green");
I believe you are confusing a data-type with a structure.我相信您将数据类型与结构混淆了。 The
pixels
represents a continuous list of Quantum
parts. pixels
代表Quantum
部件的连续列表。
Assuming that we're working with RGB colorspace.假设我们正在使用 RGB 颜色空间。 You would need to set each color part.
您需要设置每个颜色部分。
Color black("black");
*(pixels + 0) = black.quantumRed();
*(pixels + 1) = black.quantumGreen();
*(pixels + 2) = black.quantumBlue();
To set the 200th pixel, you would need to multiply the offset by the parts-per-pixel count.要设置第 200 个像素,您需要将偏移量乘以每像素部分数。
Color green("green");
int offset = 199 * 3; // First pixel starts at 0, and 3 parts (Red, Green, Blue)
*(pixels + offset + 0) = green.quantumRed();
*(pixels + offset + 1) = green.quantumGreen();
*(pixels + offset + 2) = green.quantumBlue();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.