0

Possible Duplicate:
Is there a Java library for steganography?

public void  myfunction()
{
  try
  {

   BufferedImage image = ImageIO.read(new File("first.jpg"));//first image
   BufferedImage overlay = ImageIO.read(new File("second.jpg"));//second image

   int w = Math.max(image.getWidth(), overlay.getWidth());
   int h = Math.max(image.getHeight(), overlay.getHeight());
   BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

   Graphics g = combined.getGraphics();
   g.drawImage(image, 0, 0, null);
   g.drawImage(overlay, 0, 0, null);

   //here i combined 2 images in combined.jpg
   ImageIO.write(combined, "jpg", new File("DestinationPath", "combined.jpg"));//combined image

  } 
 catch (Exception e) 
 {
 e.printStackTrace();
 }
}

//i want to extract this combined.jpg into my previous first.jpg and second.jpg ? // How to extract 2 images that i combined with this code ?

Community
  • 1
  • 1
Yogesh
  • 91
  • 1
  • 2
  • 7
  • i don't understand what is your goal and what you are trying to achive – Nikolay Kuznetsov Jan 07 '13 at 10:34
  • I combined 2 images in 1 image file using given code but now i want to extract that 2 images separate again.. – Yogesh Jan 07 '13 at 10:40
  • what for? If you can use them directly? – Nikolay Kuznetsov Jan 07 '13 at 10:47
  • i want to do this for my task, i am new to Java and this is my assignment task... – Yogesh Jan 07 '13 at 10:52
  • you draw one on the top of another. how do you expect to be able to separate them? – Nikolay Kuznetsov Jan 07 '13 at 10:56
  • Actually i don't know How to do that or is this possible... – Yogesh Jan 07 '13 at 11:11
  • What is your assignment exactly? – Nikolay Kuznetsov Jan 07 '13 at 11:17
  • This is like asking how to separate the milk from your coffee. You've basically you've merged two images into one, the pixels of the overlay image have replaced the pixels of the base image...there's nothing you can do to recover them. – MadProgrammer Jan 07 '13 at 11:26
  • :( My assignment is to combine two images and separate them as previous...Is there any way in java to combine 2 images and then extract them as first ?? i think it wrong my combining logic is wrong....Is there any other way in that we combine 2 images and then extract them as previous images..?? – Yogesh Jan 07 '13 at 11:31
  • Is there any other way to combine 2 images and then extract them as previous in Java ? – Yogesh Jan 07 '13 at 11:46
  • if you have two half empty (or full :) glasses of water and but them both into a new glass of water. you no longer can't seperate the "SAME" water back into their glasses. – Rufinus Jan 08 '13 at 01:33
  • right Rufinus, my image merging logic is wromg this way, but i have to merge 2 images such a way that i can separate them to original images...is this possible ?? – Yogesh Jan 08 '13 at 04:49

1 Answers1

0

After drawing the first image, you could set some transparency when drawing the overlay.

float alpha = 0.75f;
int type = AlphaComposite.SRC_OVER; 
AlphaComposite composite = AlphaComposite.getInstance(type, alpha);
g.setComposite(composite);
Andy Till
  • 3,371
  • 2
  • 18
  • 23
  • Thanks Andy Till...but i don't know how to extract those images from merged image ? – Yogesh Jan 07 '13 at 13:15
  • No it would be impossible to extract those images once merged. – Andy Till Jan 07 '13 at 13:24
  • yes sir that is right but can you tell me how to combined and then extract two images ? Is this possible using stegnography to hide one image inside other and then please tell me..how ? – Yogesh Jan 07 '13 at 13:28
  • I thought that was a dinosaur. If you controlled the image format and brought down the number of colours you wanted to represent say 128bit, you could store one image in the top half of every byte and and the other in the bottom half but it really won't be recognisable. – Andy Till Jan 07 '13 at 19:53
  • Thanks to all giving attention !! – Yogesh Jan 08 '13 at 04:45