⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scale.jsp

📁 提供 精通Java Web动态图表编程 一书的源代码, 大家赶快下载呀
💻 JSP
字号:
<!--
 	Fig. 7.9_04: scale.jsp
 	功能: 图形对象的缩放
-->
<%@ page language="java" contentType="image/png;charset=GB2312"
	import="java.awt.image.*"
	import="java.awt.*"
	import="javax.imageio.*"
	import="java.io.*"
	import="java.awt.geom.*"
	import="java.net.*"
%>

<%
	// 清空缓冲区
	response.reset();

	// 注意这里的MIME类型
	response.setContentType("image/png");

	// 创建一个 400X400 的图像
	int width = 400, height = 400;

	BufferedImage image = new BufferedImage(width, height,
	  BufferedImage.TYPE_INT_RGB);

	// 创建Java2D对象
	Graphics2D g2d = image.createGraphics();

	// 填充背景
	g2d.setColor(Color.WHITE);
	g2d.fillRect(0, 0, width, height);

	g2d.setColor(Color.BLACK);

	// 设置标题
	g2d.setFont(new Font("汉真广标", Font.PLAIN, 35));
	g2d.drawString("图像文件的缩放", 10, 35);

	Image logoPNG;
			
    try 
    {
		URL imageURL = 
			new URL("http://localhost:8080/chap07/Fig7.9/Fig.7.9_04/logo.png");
	   
		// 加载并显示图像
		logoPNG = ImageIO.read(imageURL);
		g2d.drawImage(logoPNG, 10, 50, null);

		g2d.translate(width/5, height/2.5);
		g2d.scale(2.0, 2.0);
		g2d.drawImage(logoPNG, 0, 0, null);

		g2d.scale(0.25, 0.25);
		g2d.drawImage(logoPNG, 250, -180, null);
    }
   catch(Exception e)
   {
		g2d.drawString("读入图像文件错误!", 100, 200);
   }
   
   // 部署图形
   g2d.dispose();

   // 利用ImageIO类的write方法对图像进行编码
   ServletOutputStream sos = response.getOutputStream();
   ImageIO.write(image, "PNG", sos);
   sos.close();
%>


<%
/**************************************************************************
 * (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓).  *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors of this code have used their                   *
 * best efforts in preparing the code. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these codes. The authors *
 * shall not be liable in any event for incidental or consequential       *
 * damages in connection with, or arising out of, the furnishing,         *
 * performance, or use of these programs.                                 *
 **************************************************************************/
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -