Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Merging an image with a color?  (Read 1258 times)
0 Members and 1 Guest are viewing this topic.
Offline Renoria

Junior Member




...


« Posted 2008-12-11 23:51:42 »

How could I merge an image with a color, so that I can make frozen looking sprites while I don't need another image?
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2008-12-12 00:16:28 »

Yup. You can do this one of two ways.

1) Create a new BufferedImage as you load it which is icy (recommend).
2) On-the-fly overlay some color on the top of your image.

To do 1, it's something like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
BufferedImage tintedImage = new BufferedImage(oldImage.getWidth(), oldImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
for (int i = 0; i < tintedImage.getRaster().getWidth(); i++)
{
     for (int j = 0; j < tintedImage.getRaster().getHeight(); j++)
     {
          int[] data = new int[4];
          data = oldImage.getRaster().getPixel(i,j,data);
          //Adds a blue tint, but make sure it doesn't go over 255.
         data[2] = Math.min(255,data[2]+50);
          tintedImage.getRaster().setPixel(i,j,data);
     }
}


To do 2:
1  
2  
3  
g.drawImage(oldImage,x,y,width,height,null);
g.setColor(new Color(0,0,50,100));
g.fillRect(x,y,width,height);


#2 will unfortunately leave a haze around the transparent area. You can also just do #1 every single time you draw, but that's slow.

See my work:
OTC Software
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #2 - Posted 2008-12-12 00:33:58 »

1  
          data[2] = Math.min(255,data[2]+50);


I'm not sure that's a good way to tint something - firstly it'll only work if you want to tint towards a primary colour and secondly because you're adding to the blue colour channel the result is going to be brighter than the original, not just blue-er. A better way would be to do a weighted average between the base colour and the tint colour. Better still would be to convert to a different colour space which makes the operation trivial (like <a href="http://en.wikipedia.org/wiki/HSL_and_HSV">HSL</a>) then convert back to RGB to update your image.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Renoria

Junior Member




...


« Reply #3 - Posted 2008-12-12 01:32:37 »

What about using RBGFilter?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (10 views)
2014-10-02 14:36:20

Pippogeek (41 views)
2014-09-24 16:13:29

Pippogeek (32 views)
2014-09-24 16:12:22

Pippogeek (22 views)
2014-09-24 16:12:06

Grunnt (48 views)
2014-09-23 14:38:19

radar3301 (30 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!