Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is (rather inefficient and ugly) Vala application that removes transparency from an image and saves it in the format specified. NOTE: There is a small bug in vala binding for gdk_pixbuf_new_from_data() that causes corruption of the resulting image. I'm going to fix that soon but this is meanly for demonstration purposes for now (besides the question was about C++):</p> <pre><code> public static int main (string[] args) { if (args.length &lt; 4) { print ("Usage: %s SOURCE DESTINATION FORMAT\n", args[0]); return -1; } var src_path = args[1]; var destination_path = args[2]; var dest_type = args[3]; var pixbuf = new Gdk.Pixbuf.from_file_at_scale (src_path, 48, 48, false); // Remove alpha channel if (pixbuf.get_has_alpha () &amp;&amp; pixbuf.get_n_channels () == 4 &amp;&amp; pixbuf.get_bits_per_sample () == 8) { var width = pixbuf.get_width (); var height = pixbuf.get_height (); var rowstride = pixbuf.get_rowstride (); unowned uint8[] orig_pixels = pixbuf.get_pixels (); var pixels = new uint8[rowstride * height]; for (var i = 0; i &lt; height; i++) { for (var j = 0, k = 0; j &lt; width * 4; j += 4, k += 3) { var orig_index = rowstride * i + j; var index = rowstride * i + k; if (orig_pixels[orig_index] == 0 &amp;&amp; orig_pixels[orig_index + 1] == 0 &amp;&amp; orig_pixels[orig_index + 2] == 0 &amp;&amp; orig_pixels[orig_index + 3] == 0) { pixels[index] = 0xFF; pixels[index + 1] = 0xFF; pixels[index + 2] = 0xFF; } else { pixels[index] = orig_pixels[orig_index]; pixels[index + 1] = orig_pixels[orig_index + 1]; pixels[index + 2] = orig_pixels[orig_index + 2]; } } } pixbuf = new Gdk.Pixbuf.from_data (pixels, pixbuf.get_colorspace (), false, 8, width, height, rowstride, null); } pixbuf.save (destination_path, dest_type); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload