Solved

merging 2 images

Posted on 2002-07-16
7
273 Views
Last Modified: 2010-03-31
I have a background image and a foreground image.

I want to overlay the foreground image on top of the background image so that I can see parts of the background below.  I have drawn the foreground image with black where I want it to be transparent.  I need some code to show me how to merge the 2 images.

Thanks,
Mike.
0
Comment
Question by:MDarling
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:s_lavie
ID: 7157138
Can you send the code of what you did, so we'll speak the same "language"?
0
 
LVL 3

Author Comment

by:MDarling
ID: 7157145
I haven't got any code yet.  Just need to load an image, load another, then overlay one on top of the other with the top one being transparent wherever it is black.
0
 
LVL 2

Expert Comment

by:s_lavie
ID: 7157170
Can the background image be a transparent gif?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:MDarling
ID: 7157191
No the background image is totally opaque.
The foreground image is partially transparent.

All my images are png format, they are also in high colour format, which is beyound GIF capabilities.
0
 
LVL 16

Accepted Solution

by:
imladris earned 200 total points
ID: 7157271
One solution would be to process the foreground image as it is loaded, turning all the black pixels to transparent ones. To do this write an imagefilter something like:

class TransFilter extends RGBImageFilter
{     TransFilter()
     {     canFilterIndexColorModel=true;
          return;
     }

        // if rgb is black (red, green and blue components
        // all off) return a transparent pixel
        // (alpha component (top byte) off)

     public int filterRGB(int x,int y,int rgb)
     {     int i;

                return((rgb&0xffffff)==0?0:rgb);
     }
}


You use an imagefilter with something like:

Image buf=getImage(name);  // get the image
ImageFilter flt=new TransFilter();
ImageProducer p=new FilteredImageSource(buf.getSource(),flt);
Image pi=window.createImage(p);


Out of curiosity, what software are you using to load png images? I have done png's in the past, but the libraries I found all turned out to have substantive problems, though that was some years ago.
0
 
LVL 3

Author Comment

by:MDarling
ID: 7157325
Hi imladris

Im just using loadImage from the Java SDK.  Seems to work ok.  

I'll check out your code and get back to you.

Thanks,
Mike.
0
 
LVL 3

Author Comment

by:MDarling
ID: 7158156
Thanks - just the job!

Regards,
Mike.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Message handling in Service Layer 3 58
Securing Jmx Console and web console 2 65
MySQL  on Tomcat 8 29
expectj telnet failing 5 26
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now