WEB开发网
开发学院软件开发Java java 绘图 综合案例 阅读

java 绘图 综合案例

 2012-05-12 13:01:34 来源:WEB开发网   
核心提示:/*** * @param targetImg* 底图路径* @param fashion* 时尚指数* @param wenyi* 文艺指数* @param kengdie* 坑爹指数* @param xuepin* 血拼指数* @param huanbao* 环保指数* @param fenzhi* 评分,分值*
/**
	* 
	* @param targetImg
	* 底图路径
	* @param fashion
	* 时尚指数
	* @param wenyi
	* 文艺指数
	* @param kengdie
	* 坑爹指数
	* @param xuepin
	* 血拼指数
	* @param huanbao
	* 环保指数
	* @param fenzhi
	* 评分,分值
	* @param imgUrl
	* 右上角图片URl
	* @param imgCenter
	* 用户图
	* @param shuxingImg
	* 属性图片URL
	* @param newImgUrl
	* 新生成的图片保存地址
	* @param userName
	* 	用户名
	* @param imgSecond
	* 第二层底图
	 * @throws FWException 
	*/
	public void matrix_Images(String targetImg,int fashion,int wenyi,int kengdie,int xuepin,int huanbao,int fenzhi,String imgUrl,Image userImage,String newImgUrl,String shuxingImg,String userName, String imgSecond) throws FWException{
	try {
		File _file = new File(targetImg);
		Image src = ImageIO.read(_file);
		int wideth = src.getWidth(null);
		int height = src.getHeight(null);
		BufferedImage image = new BufferedImage(wideth, height,BufferedImage.TYPE_INT_RGB);
		//创建图层,获取绘画对象(画笔)
		Graphics g = image.createGraphics();
		g.drawImage(src, 0, 0, wideth, height, null);
		g.setColor(new Color(237,121,81));
		/*
		* 根据相应指数,决定线的端点
		*/
		//根据时尚指数确定具体坐标
		int s_x=0;
		int s_y=0;
		if(0<=fashion && fashion<21){
		s_x=248;
		s_y=253;
		}else if(20<fashion && fashion<31){
		s_x=257;
		s_y=251;
		}else if(30<fashion && fashion<41){
		s_x=266;
		s_y=249;
		}else if(40<fashion && fashion<51){
		s_x=275;
		s_y=246;
		}else if(50<fashion && fashion<61){
		s_x=284;
		s_y=243;
		}else if(60<fashion && fashion<71){
		s_x=293;
		s_y=241;
		}else if(70<fashion && fashion<81){
		s_x=302;
		s_y=238;
		}else if(80<fashion && fashion<91){
		s_x=311;
		s_y=236;
		}else if(90<fashion && fashion<1001){
		s_x=321;
		s_y=232;
		}else {
		s_x=0;
		s_y=0;
		}
		//根据文艺指数来确定具体坐标
		int w_x=0;
		int w_y=0;
		if(0<=wenyi && wenyi<21){
		w_x=172;
		w_y=254;
		}else if(20<wenyi && wenyi<31){
		w_x=161;
		w_y=251;
		}else if(30<wenyi && wenyi<41){
		w_x=152;
		w_y=249;
		}else if(40<wenyi && wenyi<51){
		w_x=143;
		w_y=245;
		}else if(50<wenyi && wenyi<61){
		w_x=134;
		w_y=244;
		}else if(60<wenyi && wenyi<71){
		w_x=125;
		w_y=241;
		}else if(70<wenyi && wenyi<81){
		w_x=116;
		w_y=238;
		}else if(80<wenyi && wenyi<91){
		w_x=107;
		w_y=236;
		}else if(90<wenyi && wenyi<1001){
		w_x=98;
		w_y=232;
		}else {
		w_x=0;
		w_y=0;
		}
		//根据坑爹指数来确定具体坐标
		int k_x=0;
		int k_y=0;
		if(0<=kengdie && kengdie<21){
		k_x=209;
		k_y=227;
		}else if(20<kengdie && kengdie<31){
		k_x=209;
		k_y=217;
		}else if(30<kengdie && kengdie<41){
		k_x=209;
		k_y=207;
		}else if(40<kengdie && kengdie<51){
		k_x=209;
		k_y=197;
		}else if(50<kengdie && kengdie<61){
		k_x=209;
		k_y=187;
		}else if(60<kengdie && kengdie<71){
		k_x=209;
		k_y=177;
		}else if(70<kengdie && kengdie<81){
		k_x=209;
		k_y=167;
		}else if(80<kengdie && kengdie<91){
		k_x=209;
		k_y=157;
		}else if(90<kengdie && kengdie<1001){
		k_x=209;
		k_y=150;
		}else {
		k_x=0;
		k_y=0;
		}
		//根据血拼指数来确定具体坐标
		int x_x=0;
		int x_y=0;
		if(0<=xuepin && xuepin<21){
		x_x=187;
		x_y=298;
		}else if(20<xuepin && xuepin<31){
		x_x=181;
		x_y=307;
		}else if(30<xuepin && xuepin<41){
		x_x=175;
		x_y=316;
		}else if(40<xuepin && xuepin<51){
		x_x=169;
		x_y=325;
		}else if(50<xuepin && xuepin<61){
		x_x=163;
		x_y=334;
		}else if(60<xuepin && xuepin<71){
		x_x=157;
		x_y=343;
		}else if(70<xuepin && xuepin<81){
		x_x=151;
		x_y=352;
		}else if(80<xuepin && xuepin<91){
		x_x=145;
		x_y=361;
		}else if(90<xuepin && xuepin<1001){
		x_x=139;
		x_y=368;
		}else {
		x_x=0;
		x_y=0;
		}
		//根据环保指数来确定具体坐标
		int h_x=0;
		int h_y=0;
		if(0<=huanbao && huanbao<21){
		h_x=232;
		h_y=298;
		}else if(20<huanbao && huanbao<31){
		h_x=238;
		h_y=307;
		}else if(30<huanbao && huanbao<41){
		h_x=244;
		h_y=316;
		}else if(40<huanbao && huanbao<51){
		h_x=250;
		h_y=325;
		}else if(50<huanbao && huanbao<61){
		h_x=256;
		h_y=334;
		}else if(60<huanbao && huanbao<71){
		h_x=262;
		h_y=343;
		}else if(70<huanbao && huanbao<81){
		h_x=268;
		h_y=352;
		}else if(80<huanbao && huanbao<91){
		h_x=275;
		h_y=361;
		}else if(90<huanbao && huanbao<1001){
		h_x=278;
		h_y=368;
		}else {
		h_x=0;
		h_y=0;
		}
		
		//画中心矩形图
		int Poly1_x[]={s_x,k_x,w_x,h_x,x_x};
		int Poly1_y[]={s_y,k_y,w_y,h_y,x_y};
		int Poly1_pts=Poly1_x.length;
		Polygon poly1= new Polygon(Poly1_x,Poly1_y, Poly1_pts);
		Polygon poly2= new Polygon();
		//设置中心矩形图五个坐标点
		poly2.addPoint(k_x, k_y);
		poly2.addPoint(w_x, w_y);
		poly2.addPoint(x_x, x_y);
		poly2.addPoint(h_x, h_y);
		poly2.addPoint(s_x, s_y);
		g.setColor(new Color(189,196,218));
		g.drawPolygon(poly1);
		g.fillPolygon(poly2);
		//添加第二层底图
		File tow_imgurl = new File(imgSecond);
		Image two_img = ImageIO.read(tow_imgurl);
		g.drawImage(two_img, 0,0, 601, 462, null);
		//添加图片矩形图中心图
//		File _filebiao = new File(imgUrl);
//		Image src_biao = ImageIO.read(_filebiao);
//		g.drawImage(src_biao, 200,263, 22, 22, null);
		//画线
//		g.setColor(new Color(102,103,103));
//		g.drawLine(209,155, 212, 265);
//		g.setColor(new Color(20,118,178));
//		g.drawLine(97,244, 202, 272);
//		g.setColor(new Color(234,84,26));
//		g.drawLine(140,388, 206, 284);
//		g.setColor(new Color(124,190,39));
//		g.drawLine(278,388, 217, 284);
//		g.setColor(new Color(136,67,150));
//		g.drawLine(322,245, 221, 272);
		//添加右上角用户图片
		//URL you_imgurl = new URL(imgCenter);
		//Image src_biao_you = ImageIO.read(you_imgurl);
		g.drawImage(userImage, 522,37, 60, 60, null);
		//添加属性图片
		File shuxing_imgurl = new File(shuxingImg);
		Image shuxing_img = ImageIO.read(shuxing_imgurl);
		g.drawImage(shuxing_img, 385,295, 100, 50, null);
		//写入指数值
		String str="【"+fenzhi+"分】";
		g.setColor(new Color(0,0,0));
		//设置字体
		g.setFont(new Font("微软雅黑",Font.BOLD,25));
		//设置文字坐标
		g.drawString(str, 480, 329);
		
		//写入右上角用户名
		g.setColor(new Color(0,0,0));
		//设置字体
		g.setFont(new Font("微软雅黑",Font.BOLD,15));
		//设置文字坐标
		userName=substring(userName,6);
		g.drawString(userName, 526, 114);
		
		//生成图片
		g.dispose();
		FileOutputStream out = new FileOutputStream(newImgUrl);
		JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
		encoder.encode(image);
		out.close(); //关闭输出流

	} catch (Exception e) {
		// TODO: handle exception
		e.printStackTrace();
		throw new FWException("-255", "error image");
	}

	}

Tags:java 绘图 综合

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接