Printing / saving a plot as a png file with an alpha channel issue in Octave

前端 未结 2 1933
失恋的感觉
失恋的感觉 2021-01-27 00:36

How can I print / save a plot as a png file with an alpha channel?

I tried Saving a plot in Octave with transparent background

I\'m using Octave 4.2.2, Ubu

2条回答
  •  攒了一身酷
    2021-01-27 01:07

    It is not clear if you want to simply generate a file with a transparent background, or you want to handle the more general case of an arbitrary alpha channel for your image file.

    Fortunately, it seems Octave can handle the second case as well. As pointed out here, transparency is not implemented for image or axes objects, but writing images to file with an alpha channel seems to work fine, at least in version 5.1.0.

    So this would produce a transparent alpha channel for white (tcolor = [255 255 255])

    im = print(gcf, '-RGBImage');
    tcolor = [255 255 255];
    alpha(:,:) = 255 * ( 1 - (im(:,:,1) == tcolor(1)) .* (im(:,:,2) == tcolor(2)) .* (im(:,:,3) == tcolor(3)) );
    imwrite(im, 'myplot.png', 'Alpha', alpha);
    

提交回复
热议问题