答案 0 :(得分:0)
试试这段代码。
//今天到了。并放入位于xml文件中右下角//的ListView。
final Calendar cal = Calendar.getInstance();
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH)+1;
day = cal.get(Calendar.DAY_OF_MONTH);
TextView out=(TextView)findViewById(R.id.yourtextview);
out.setText(day+"."+month+"."+year);
答案 1 :(得分:0)
试试这个
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class WatermarkImage {
public static void main(String[] args) {
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
File origFile = new File("E:/watermark/test.jpg");
ImageIcon icon = new ImageIcon(origFile.getPath());
// create BufferedImage object of same width and height as of original image
BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(),
icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
// create graphics object and add original image to it
Graphics graphics = bufferedImage.getGraphics();
graphics.drawImage(icon.getImage(), 0, 0, null);
// set font for the watermark text
graphics.setFont(new Font("Arial", Font.BOLD, 20));
String watermark = sdfDate.format(now);
// add the watermark text
graphics.drawString(watermark, (icon.getIconWidth()*80)/100, (icon.getIconHeight()*90)/100);
graphics.dispose();
File newFile = new File("E:/watermark/WatermarkedImage.jpg");
try {
ImageIO.write(bufferedImage, "jpg", newFile);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(newFile.getPath() + " created successfully!");
}
}
答案 2 :(得分:0)
尝试此代码。为我省了很多精力
String d = "18-11-2019";
BufferedImage bi = ImageIO.read(sourceFile);
Graphics2D graphics = bi.createGraphics();
Font font = new Font("ARIAL", Font.PLAIN, 50);
graphics.setFont(font);
graphics.drawString(d, 50, 50);
bi.flush();
ImageIO.write(bi, "jpg", targetFile);