473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C#:APP: Tint Color

115 100+
How can I tint one color with another color? i.e. say i have a Color.LightSkyBlue
(135,206,250) i want to tint it with Color.Green(0,128, 0)

Whats the math behind it?
May 22 '08 #1
6 3144
Curtis Rutland
3,256 Expert 2GB
How can I tint one color with another color? i.e. say i have a Color.LightSkyBlue
(135,206,250) i want to tint it with Color.Green(0,128, 0)

Whats the math behind it?
Couldn't you just use some application (like Paint.NET) that has a color wheel or mixer, find the color you actually want and then use that RRGGBB value?

Why do you want the program to blend your colors?
May 22 '08 #2
Plater
7,872 Expert 4TB
Well I had really though I remember seeing something in the Color class about tinting but I can't find it anymore.
Have you read through this? http://www.inform.umd.edu/MCTP/Cours...son/index.html
May 23 '08 #3
ShadowLocke
115 100+
Well I had really though I remember seeing something in the Color class about tinting but I can't find it anymore.
Have you read through this? http://www.inform.umd.edu/MCTP/Cours...son/index.html
I was thinking the same. I have found a class that may do it for me.

System.Drawing.Imaging.ColorMatrix

I havent had a chane to tinker with it too much, but it looks like this is gonna work for me. (great reference btw.)
May 23 '08 #4
ShadowLocke
115 100+
This will do, heres what I came up with:

Expand|Select|Wrap|Line Numbers
  1.         private Bitmap TintBitmap(ref Bitmap b, Color tintColor)
  2.         {
  3.             ImageAttributes ia = new ImageAttributes();
  4.             float tR = (float)tintColor.R / 255;
  5.             float tG = (float)tintColor.G / 255;
  6.             float tB = (float)tintColor.B / 255;
  7.  
  8.             ColorMatrix cm = new ColorMatrix(new float[][]
  9.             {
  10.                 new float[] {1, 0, 0, 0, 0},
  11.                 new float[] {0, 1, 0, 0, 0},
  12.                 new float[] {0, 0, 1, 0, 0},
  13.                 new float[] {0, 0, 0, 1, 0},
  14.                 new float[] {tR, tG, tB, 0, 1}
  15.             });
  16.  
  17.             ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
  18.  
  19.             Bitmap result = new Bitmap(b.Width, b.Height);
  20.             Point[] pts = new Point[] { new Point(0, 0), new Point(b.Width, 0), new Point(0, b.Height) };
  21.             Rectangle rect = new Rectangle(0, 0, b.Width, b.Height);
  22.  
  23.             using (Graphics g = Graphics.FromImage((Image)result))
  24.             {
  25.                 g.DrawImage(b, pts, rect, GraphicsUnit.Pixel, ia);
  26.             }
  27.  
  28.             return result;
  29.         }
May 23 '08 #5
Plater
7,872 Expert 4TB
Do you need to pass bitmap b in by reference? (Is that just to keep memory usage down for very large bitmap objects?)
May 23 '08 #6
ShadowLocke
115 100+
Do you need to pass bitmap b in by reference? (Is that just to keep memory usage down for very large bitmap objects?)
Correct, one of my many feeble attempts at minimizing memory consumption.
May 26 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Patrick | last post by:
Hello all! I am using a BufferedImage object to build an image from scratch. I want it to be a grayscale image with only 8bits of color. I have the color information as a byte, saved in variable...
3
by: Brad Burke | last post by:
From a windows .Net app, I need to 1) check if MSAccess is already open to a certain Access application. If so, then open a form and find a certain record. 2) If not open, then open MSAccess and...
14
by: Salad | last post by:
On the computer side of the businees there is me, the developer. Another person's role is that of the idea man...the person that knows the business and requirements and issues for the business. ...
4
by: Dave Diehl | last post by:
Has anyone heard of a problem with a rebuild of one application causing a problem with another app on the same server? I have two asp.net applications on the same Win2000 server, each with it's...
3
by: John Dalberg | last post by:
I am setting the HttpContext.Current.User in the Application_AuthenticateRequest event in global.asax.cs. When I use the IsInRole function in a web page, it works fine. So far so good. (Note that...
22
by: Deano | last post by:
Hi, I have a finished Microsoft Access app that we are distributing using an Access runtime. This works fine (mostly) but I'm sold on the advantages of dot.NET and upgrading to vb.NET seems...
5
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. ...
9
by: Ron | last post by:
my application is throwing an exception error when closing if I run a procedure in the app. I can't even trap the error with try/catch ex As Exception. Is there a way to completely shut down the...
2
by: Dan Moskowitz | last post by:
Hi, I'm using PIL to tint and composite images together. Here's how I'm currently tinting images, it's really slow and I know there's got to be a better way: def TintImage( im, tintColor ):...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.