Hi Nathan,
Yes, you posted that code to my earlier message. Your code is excellent! However, because I'm new to graphics programming, I found it difficult to extract what I needed from your cool code.
I bought the "Java 2D API" book, but have found it (***VERY***) slow going.
What I'm trying to do (which may actually be in your code)is the following:
1. Open a JPEG file that has a background image.l
2. Open another JPEG file that has a "watermark" image.
3. Write the watermark image onto the background iamge (using some kind of "transparency setting")
If you could take a quick look at the code I've come up with so far and make some suggestions, I would REALLY appreciate it. <s>
I really appreciate your replies.
-- Mike
package combinetwojpegimages;
import java.io.*;
import javax.imageio.*;
import java.awt.image.BufferedImage;
import java.awt.geom.AffineTransform;
import java.awt.*;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageDecoder;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class combine
{
public static void main (
String args[])
{
File f1 = new File(args[0]);
BufferedImage biOne;
BufferedImage biTwo;
BufferedImage bOutput=null;
Graphics goutPut = null;
// create JPEG image encoder to write to the output file to.
OutputStream outStream = new FileOutputStream("outFile.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outStream);
// Define background image which we'll put the foreground image on top of
InputStream backGroundImage = new FileInputStream(new File(args[0]));
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(backGroundImage);
BufferedImage imageBack = new BufferedImage(40,30,BufferedImage.
TYPE_INT_RGB);
// Define foreground image -- will be partially transparent.
InputStream foreGroundImage = new FileInputStream(new File(args[1]));
JPEGImageDecoder decoder2 = JPEGCodec.createJPEGDecoder(foreGroundImage);
BufferedImage imageFore = new BufferedImage(40,30,BufferedImage.
TYPE_INT_ARGB);
try
{
// getGraphics() creates an offscreen (only) graphics workarea.
Graphics inputBackground = imageBack.getGraphics();
Graphics inputForeground = imageFore.getGraphics();
// create a temp buffered image workspace
BufferedImage tmp = new BufferedImage(50,50,BufferedImage.TYPE_INT_RGB);
Graphics gOut = tmp.createGraphics();
// start of writing imageFore onto imageBack using temp file tmp
// making the imageFore semi-transparent.
// End of writing mageFore onto imageBack using temp file tmp
// making the imageFore semi-transparent.
encoder.encode(tmp);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
// Do output of image below.
try
{
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(encoder);
param.setQuality((float)1.0, true);
encoder.encode(encoder, param);
InStream.close();
outStream.flush();
outStream.close();
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}