Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Converting RGBA values to a uint-color


  • Please log in to reply
No replies to this topic

#1 Ryan 3000

Ryan 3000

  • Members
  • 834 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Maryland
  • Local time:05:34 PM

Posted 05 July 2010 - 07:25 PM

C#/XNA
I have a code segment, shown below, that's supposed to take in a uint-color and output a uint with reduced alpha. So what I do is uint-to-RGBA, modify A, put RGBA into Color, use Color's PackedValue (uint) to get final value.
I want to go straight from RGBA to uint, without Color and Color.PackedValue. How do I do this?
public static uint Fade(uint num, int amount)
		{
			byte a = (byte)(num >> 24);
			byte r = (byte)(num >> 16);
			byte g = (byte)(num >> 8);
			byte b = (byte)(num >> 0);
			if (a > amount)
				a -= (byte)amount;
			else
				a = 0;
			return new Color(r, g, b, a).PackedValue;//want to get rid of the Color here.
		}

Edited by Ryan 3000, 05 July 2010 - 07:31 PM.

No pessimist ever discovered the secrets of the stars, or sailed to an uncharted land.

BC AdBot (Login to Remove)

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users