drive.google.com ins of gr mpora Degree Req what is a eul. Your questio... 2016F
ID: 3779512 • Letter: D
Question
drive.google.com ins of gr mpora Degree Req what is a eul. Your questio... 2016F CPS2 import import java.awt. Exercise import java. awt.image. BufferedImage; import java.io. import java.net. import java.util.Date; public class Test public static void main( string[] args){ Buffered Image image null; Date date new Date(); try //you can either use URL or le for reading image using ImageIO //File image file new File("c ://apple logo.jpg"); //image Image To read (imagefile); URL url new URL ("http://imc.kean.edu/cps2231/apple logo.jpg"); image ImageIO Io.read(url); Graphics g image .getGraphics g.setFont (g.get Font().deriveFont(20f)); g drawstring demo date, 67, 200); g dispose(); ImageIO Image write Example in Java catch write(image, "jpg", new File("demo apple Logo.jpg")); (IOException e) System.out. printLn("Success")i cps 22 o, Chine Yu (Austin) HuangExplanation / Answer
package koti;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import javax.imageio.ImageIO;
public class ImageReader {
public static void main(String[] args) throws IOException {
BufferedImage image = null;
Date date = new Date();
File imagefile = new File("C:\photo.jpg");
image = ImageIO.read(imagefile);
// URL url=new
// URL("http://www.pexels.com/photo/red-love-romantic-flowers-4825/");
URL url = new URL("http://imc.kean.edu/CPS2231/apple_logo.jpg");
image = ImageIO.read(url);
Graphics g = image.getGraphics();
g.setFont(g.getFont().deriveFont(20f));
g.drawString("draw ," + date, 67, 200);
g.dispose();
ImageIO.write(image, "jpg", new File("D:\demo.jpg"));
System.out.println("success");
// to get the image height and width from file
System.out.println("to get the image height and width from file");
image = ImageIO.read(imagefile);
System.out.println("image height is:" + image.getHeight() + "pixels");
System.out.println("image width is:" + image.getWidth() + "pixels");
// to get the image height and width from url
System.out.println("to get the image height and width from url");
image = ImageIO.read(url);
System.out.println("image height is:" + image.getHeight() + "pixels");
System.out.println("image width is:" + image.getWidth() + "pixels");
}
}
output
success
to get the image height and width from file
image height is:634pixels
image width is:960pixels
to get the image height and width from url
image height is:339pixels
image width is:300pixels
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.