Converting JPEG to PNG Image With Alpha transparency
Hi guys, I'm trying to convert image from jpeg format to png format. I'm also trying to apply Alpha on image so png save imag must be with alpha channel. I am not able to execute this(result.push_back<mat>(mask);) line in the code successfully.
Mat jpegImageMat = Highgui.imread("mnt/sdcard/aaawatermark/bird.jpg");
Mat gray_image = new Mat(), mask = new Mat(), rgba_image = new Mat();
List<Mat> result = new ArrayList<Mat>();
Core.split(jpegImageMat, result);
Imgproc.cvtColor(jpegImageMat, gray_image, Imgproc.COLOR_BGR2RGBA);
Imgproc.threshold(gray_image, mask, 128, 255, Imgproc.THRESH_BINARY);
result.push_back<Mat>(mask);
Core.merge(result, rgba_image);
Highgui.imwrite("mnt/sdcard/aaawatermark1/rgba.png", rgba_image);
Anybody help me will be appreciated.
you want a grayscale image as input to threshold:
and then there's no push_back() ,
(apart from that, using a thresholded version of the image as alpha-mask will look very weird)
@berak Thanks, Let me try with this.
I dont want to convert to gray scale, I want png format image, If we simply save jpg image to png format it is saved but without alpha channel. I need alpha channel in it. Can you tell me how to do that?
here's the main problem: you seem to have no idea, what should be in your alpha channel in the 1st place. no use bothering with code, unless you solve that.
I want png image with alpha channel that is very simple question. PNG is saved as RGB channels. Where is Alpha like in format RGBA?
please answer: what should be transparent, and what not ?
again, split -> add your channel, -> merge -> save as png. it just works here.