Skip to content

Newbie Question: How to apply a Pixel by Pixel mask, where the alpha channel is what I need to set? #4570

Discussion options

You must be logged in to vote

Ah, Got it.
Also, I am working with a BW 2channel PNG image.
I think I was having trouble because because I couldn't actually find the alpha channel.

Doing the following:

var nvImage = NetVips.Image.NewFromFile(origFile);
if (!nvImage.HasAlpha())
    nvImage = nvImage.Bandjoin(128); // Add a 50% opaque alpha channel

condition always returned false - indicating the image had an alpha, but

using var alpha = nvImage[nvImage.Bands - 1];

was not returning the alpha channel.

What got me to a better place was

var alpha = nvImage.AddAlpha();
nvImage = nvImage.ExtractBand(0, nvImage.Bands - 1).Bandjoin(alpha);

then working with that.

I will try out the ifthenelse as you suggest, That looks pro…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@timeichfeld-msa
Comment options

@jcupitt
Comment options

@jcupitt
Comment options

@timeichfeld-msa
Comment options

Answer selected by timeichfeld-msa
@jcupitt
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #4569 on June 12, 2025 16:03.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy