D
dogBrown
Gast
Hi, weiss einer wie man ein Wasserzeichen in Bildern bekommt?
ByteArrayOutputStream baos= new ByteArrayOutputStream();
Image image = ImageIO.read(file);
BufferedImage bImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = outImage.createGraphics();
g.drawImage(image, 0, 0, null);
stampWatermark(outImage);
ImageIO.write(bImage, "jpg", baos);
public static void stampWatermark(BufferedImage image)
{
try
{
watermarkImage = ImageIO.read(watermark);
Graphics2D graphics2D = image.createGraphics();
float nx = image.getWidth(null) * 1f / modelDimentions.width;
float ny = image.getHeight(null) * 1f / modelDimentions.height;
int x2 = (int) (watermarkImage.getWidth(null) * nx);
int y2 = (int) (watermarkImage.getHeight(null) * nx); //ny?
int x1 = (int) ((image.getWidth(null) - x2));
int y1 = (int) ((image.getHeight(null) - y2));
graphics2D.drawImage(watermarkImage, x1, y1, x2, y2, null);
graphics2D.dispose();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void stampWatermark(BufferedImage image)
{
try
{
watermarkImage = ImageIO.read([b]watermark[/b]);
Graphics2D graphics2D = image.createGraphics();
float nx = image.getWidth(null) * 1f / modelDimentions.width;
float ny = image.getHeight(null) * 1f / modelDimentions.height;
int x2 = (int) (watermarkImage.getWidth(null) * nx);
int y2 = (int) (watermarkImage.getHeight(null) * nx); //ny?
int x1 = (int) ((image.getWidth(null) - x2));
int y1 = (int) ((image.getHeight(null) - y2));
graphics2D.drawImage(watermarkImage, x1, y1, x2, y2, null);
graphics2D.dispose();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private static File watermark = new File("c:\\test.png");
ByteArrayOutputStream baos= new ByteArrayOutputStream();
Image image = ImageIO.read(file);
BufferedImage bImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = outImage.createGraphics();
g.drawImage(image, 0, 0, null);
stampWatermark(outImage);
ImageIO.write(bImage, "jpg", baos);
public static void setWatermark(String image, String watermark)
{
try
{
File imageToWatermark = new File(image);
BufferedImage bufImg = ImageIO.read(imageToWatermark);
Graphics2D g = bufImg.createGraphics();
g.drawImage(ImageIO.read(new File(watermark)),200, 200, null);
g.dispose();
ImageIO.write(bufImg, "png", imageToWatermark);
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}