使用 magick++ 创建变暗的图标(图像魔术师)
我正在尝试使用 ImageMagick 来完成我认为是一项简单的任务。 我想在应用程序运行时生成图像/图标的暗淡版本。 我使用 magick++ c plus api。
我发现一些命令在从命令行运行时给出了良好的结果。 将命令转换为 c++ api 有点困难,结果并不如预期。
// Command example
convert -size 32x32 xc:"#999999" gray32.png
composite -dissolve 50% logo32.png gray32.png dim_logo32.png
这在 C++ 中看起来怎么样? 我想出了这个。
Magick::Image gray;
gray.size( Magick::Geometry(image.columns(), image.rows()));
gray.read( "xc:#999999");
gray.label( "gray" );
if(gray.isValid()) {
gray.opacity(QuantumRange/2);
image.composite(gray, Magick::Geometry(image.columns(),image.rows()), Magick::DissolveCompositeOp );
但图片的透明度丢失了。
关于制作暗淡图像的另一个建议是使整个图像半透明。
convert input.png -channel Alpha -evaluate Set 50% output.png
这可行。当我从命令行尝试此操作时,透明度被保留。 将其更改为 c++ api 让我很困惑。
我最终得到了这一行。
image.opacity(QuantumRange/ 2);
现在这个结果让我很困惑。图像是半透明的,但原来透明的背景现在是洋红色。
我不被允许发布图像来显示结果。 :(
I’m trying to use ImageMagick for what I believed would be a simple task.
I want to generate a dimmed version of an image/icon at runtime in the application.
I use the magick++ c plus api.
I have found some commands that give me an ok result when run from the command line.
Converting the commands to the c++ api was a bit challenging, and the result is then not as hoped.
// Command example
convert -size 32x32 xc:"#999999" gray32.png
composite -dissolve 50% logo32.png gray32.png dim_logo32.png
How would this look in c++?
I came up with this.
Magick::Image gray;
gray.size( Magick::Geometry(image.columns(), image.rows()));
gray.read( "xc:#999999");
gray.label( "gray" );
if(gray.isValid()) {
gray.opacity(QuantumRange/2);
image.composite(gray, Magick::Geometry(image.columns(),image.rows()), Magick::DissolveCompositeOp );
But the transparency in the picture is lost.
A other suggestion as to make a dimmed image, is to make the full image semi transparent.
convert input.png -channel Alpha -evaluate Set 50% output.png
This could work. The transparency is kept when I tried this from command line.
Changing this to c++ api confused me a lot.
I ended up with this single line.
image.opacity(QuantumRange/ 2);
Now the result from this confuses me. The image is semi transparent, but the background that was originally transparent is now magenta.
I was not allowed to post the images, to show the result. :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论