0

I am in the process of outputting images after working with OpenCV in Print.

I found out that the PCL driver supports transparency but the PS driver does not.

Therefore, the PS driver inquires about the operation.

I print the image on the EndPage of the print. Therefore, the transparency is adjusted using the alpha channel so that the letters are not covered. This is very effective. It makes the image less dark and transparent. Therefore, we use the method of embedding a PNG into the HDC of the print.

However, it seems to be different from the transparency of PCL. If you print a transparent image in PCL, the text becomes transparent so that you can see it in front, but in PS, even if it is transparent, when you print the image, all the text behind it is covered. Therefore, it seems that there is a problem with working with transparent images in PS. Please check the code below and tell me why it looks transparent but hides the text

cv::Mat inputImage = cv::imread(szMulti, cv::IMREAD_UNCHANGED);

cv::Mat bgra[4];
cv::split(inputImage, bgra);

double alpha = 1.0 - ((100 - LogoDensity) * 0.01);

cv::Mat alpha_channel = bgra[3] * alpha; // create a new alpha channel by multiplying the original alpha channel by the transparency level

bgra[3] = alpha_channel; // replace the original alpha channel with the new one
cv::merge(bgra, 4, inputImage); // merge the channels back together

cv::imwrite(szoutputImageName, inputImage, { cv::IMWRITE_PNG_COMPRESSION, 7 });

The image below is printed by dividing one file into PS and PCL.

[PCL]

enter image description here

[PS] enter image description here

  • `cv::imwrite` should work with opencv as expected, but `cv::imshow` won't handle transparency at all. Neither do matrix operations like `.setTo` or `+` or `putText`or ... . What is PS? – Micka Feb 22 '23 at 08:58
  • Here is an example that uses full transparency (alpha channel 0) and full opacity (alpha channel 255). https://stackoverflow.com/a/36226434/2393191 – Micka Feb 22 '23 at 09:00
  • Does this answer your question? [Using openCV to overlay transparent image onto another image](https://stackoverflow.com/questions/40895785/using-opencv-to-overlay-transparent-image-onto-another-image) – Christoph Rackwitz Feb 22 '23 at 14:49
  • PS is the postscript drive. What I said is to add to the image the HDC used by Window when printing. The code that controls transparency is familiar to me from the code I wrote above, and it works well. The behavior I want is the same as what Christoph Rackwitz said. However, this is a combination of two png files, and I want to adjust the transparency when inserting the image into HDC. – Seongtaek OH Feb 23 '23 at 04:12

0 Answers0