PDA

View Full Version : copying the alpha channel



ugluk
19th June 2013, 15:26
What is the fastest way to copy the alpha values of pixels between 2 images of the same dimensions? That is:



copyAlphaChannel(image1, image2);


where image1.size() == image2.size().

wysota
19th June 2013, 16:26
It heavily depends on the image format. In a general case unfortunately you have to iterate over pixels, read their values, adjust the alpha of the other picture and store the modified value. Or you can probably use composition modes available for QPainter to draw one image on top of the other however I'm quite certain that operation is going to be slower than the former one.

ugluk
19th June 2013, 18:13
The docs seem to hint that composition modes are the preferred way to do it. Can you supply a sequence of composition modes I could apply to achieve the copy?

ugluk
19th June 2013, 20:21
Never mind, I've helped myself with CompositionMode_SourceIn, seems to work ok and fast.