Jump to content

Check if no Pixel Exist's

Recommended Posts

the title ^


but in all seriousness when ever i have done a if statment that is something like:

if (currentPixel.R != 0 && currentPixel.B != 0 && currentPixel.G != 0 && currentPixel.A != 0) {
	//do something

it doesn't work, and I know that the code isn't exactly correct(it was correct when I tried it in codelab)i was just showing you what i tried

basically I want to know if a pixels exists at all(the way i would determine that the code works would be new file ctrl + a then delete and then have it do something so i can know that it doesn't run even once(for instance have it write text that says "failed" inside the if block so that if the if statement is true even once then then ill know).

thank you

Link to comment
Share on other sites

When you delete a selection, it makes pixels in the selection White with zero opacity.

As in (255, 255, 255, 0)


Your code is looking for Black with zero opacity.

As in (0, 0, 0, 0)


You may just want to ignore the Color and just check the opacity. Or are the color channels important in your script?

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

If you want to test if a pixel is transparent, do what toe_head2001 suggests: only test if alpha is 0. It's the correct thing to do, and it's easier to boot.


I'll mention in passing that you can directly compare colors, such as:

if (CurrentPixel != ColorBgra.TransparentBlack)
   ....do something

That would be an easier way to do what you did above, but it's not what you should do to test for transparency.


EDIT: I should say it's an easier way to do what you seem to want to do. I think you mean to have:

if (currentPixel.R != 0 || currentPixel.B != 0 || currentPixel.G != 0 || currentPixel.A != 0)

The way it is, it will skip doing something if any of the color components is zero.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...