Projemde, Mysql Db Tablosunda (Blob) varolan resme filigran eklemeye çalışıyorum.java uygulamasında MySqlDB görüntüsüne filigran ekleme
Herhangi bir görüntü dosyasına filigran eklemek için aşağıdaki yöntemi kullandım ve iyi çalışıyor. > Filigran ekleme -? - Spring MVC kullanıyorum DB> Güncelleme DB'den görüntü alınamadı için bu yöntemi kullanılır Nasıl
public static void addTextWatermark(String text, File sourceImageFile, File destImageFile) {
try {
BufferedImage sourceImage = ImageIO.read(sourceImageFile);
Graphics2D g2d = (Graphics2D) sourceImage.getGraphics();
// initializes necessary graphic properties
AlphaComposite alphaChannel = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
g2d.setComposite(alphaChannel);
g2d.setColor(Color.WHITE);
g2d.setFont(new Font("Arial", Font.BOLD, 64));
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(text, g2d);
// calculates the coordinate where the String is painted
int centerX = (sourceImage.getWidth() - (int) rect.getWidth())/2;
int centerY = sourceImage.getHeight()/2;
// paints the textual watermark
g2d.drawString(text, centerX, centerY);
ImageIO.write(sourceImage, "png", destImageFile);
g2d.dispose();
System.out.println("The tex watermark is added to the image.");
} catch (IOException ex) {
System.err.println(ex);
}
}
.
Fotoğrafım Modeli sınıftır:
public class Photo {
@Id @GeneratedValue
private int id;
private int user_id;
private String name;
@Lob
private Blob content;
çağırmak Servis Katmanı Fotoğrafı almak için: Bu entegre etmek
photoService.updatePhoto(photo);
Herkes beni açıklayınız:
Photo photo = photoService.getPhotoById(50);
fotoğrafını güncellemek projemde addTextWatermark() yöntemi.
Çok teşekkürler Sanjeev. Şimdi iyi çalışıyor :) –
Size yardımcı olduğuna sevindim .. Eğlenceli kodlama var :) – Sanjeev
2 yıl sonra ve bu sadece kıçımı kurtardı. Çok teşekkür ederim :) – user2023608