Java 如何加载图片到graphics2D上,用Image类好还是BufferedImage类好
Java如何加载图片到graphics2D上,用Image类好还是BufferedImage类好?...
Java 如何加载图片到graphics2D上,用Image类好还是BufferedImage类好?
展开
展开全部
一般都用那个bufferImage,下面是一个例子程序:
img = ImageIO.read(new File("img1.jpg"));
int width=img.getWidth();
int height=img.getHeight();
int type = img.getColorModel().getTransparency();
BufferedImage image1 = new BufferedImage(width, height, type);
Graphics2D graphics2D = image1.createGraphics();
graphics2D.setRenderingHint(
RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.setColor(Color.black);
graphics2D.fillRect(20, 20, 160, 160);
graphics2D.rotate(Math.toRadians(30),width/2,height/2);
graphics2D.drawImage(img, 10, 10, 100,100,null);
graphics2D.dispose();
img = ImageIO.read(new File("img1.jpg"));
int width=img.getWidth();
int height=img.getHeight();
int type = img.getColorModel().getTransparency();
BufferedImage image1 = new BufferedImage(width, height, type);
Graphics2D graphics2D = image1.createGraphics();
graphics2D.setRenderingHint(
RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.setColor(Color.black);
graphics2D.fillRect(20, 20, 160, 160);
graphics2D.rotate(Math.toRadians(30),width/2,height/2);
graphics2D.drawImage(img, 10, 10, 100,100,null);
graphics2D.dispose();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询