简述网站开发的三层架构中国建设银行网站转账
news/
2025/10/3 10:46:52/
文章来源:
简述网站开发的三层架构,中国建设银行网站转账,国际型网站建设,网页脚本设计近用到Java动态生成背景透明的图片功能#xff0c;从gif和png中选择了png格式#xff0c;个中缘由就不说了#xff0c;于是动手到网上搜索有用的代码。现把搜索结果总结如下#xff1a;1. 生成png图片int width 400;int height 300;// 创建BufferedImage对象BufferedImag…近用到Java动态生成背景透明的图片功能从gif和png中选择了png格式个中缘由就不说了于是动手到网上搜索有用的代码。现把搜索结果总结如下1. 生成png图片int width 400;int height 300;// 创建BufferedImage对象BufferedImage image new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);// 获取Graphics2DGraphics2D g2d image.createGraphics();// 画图g2d.setColor(new Color(255,0,0));g2d.setStroke(new BasicStroke(1));g2d.draw//释放对象g2d.dispose();// 保存文件ImageIO.write(image, png, new File(c:/test.png));int width 400;int height 300;// 创建BufferedImage对象BufferedImage image new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);// 获取Graphics2DGraphics2D g2d image.createGraphics();// 画图g2d.setColor(new Color(255,0,0));g2d.setStroke(new BasicStroke(1));g2d.draw//释放对象g2d.dispose();// 保存文件ImageIO.write(image, png, new File(c:/test.png));这只是绘制图形的代码其背景是黑色的如何才能背景透明呢继续搜索没有得到结果不过搜出以下代码它只是把自己绘制的图形设置为透明或半透明背景并不透明如下2. 绘制半透明图形int width 400;int height 300;// 创建BufferedImage对象BufferedImage image new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);// 获取Graphics2DGraphics2D g2d image.createGraphics();// 设置透明度g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f)); // 1.0f为透明度 值从0-1.0依次变得不透明// 画图g2d.setColor(new Color(255,0,0));g2d.setStroke(new BasicStroke(1));g2d.draw//释放对象//透明度设置 结束g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));g2d.dispose();// 保存文件ImageIO.write(image, png, new File(c:/test.png));这样绘制的图形应该说是前景透明的背景依然是黑色:(网上没有看到有益的代码在csdn上一位说自己实现了但却没有说怎么实现的没办法只能自己摸索了耗了半个多小时几乎查看了BufferedImage 和Graphics2D 所有方法和属性终于找到了解决方案只不过是增加两行代码而已如下int width 400;int height 300;// 创建BufferedImage对象BufferedImage image new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);// 获取Graphics2DGraphics2D g2d image.createGraphics();// ---------- 增加下面的代码使得背景透明 -----------------image g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);g2d.dispose();g2d image.createGraphics();// ---------- 背景透明代码结束 -----------------// 画图g2d.setColor(new Color(255,0,0));g2d.setStroke(new BasicStroke(1));g2d.draw//释放对象g2d.dispose();// 保存文件ImageIO.write(image, png, new File(c:/test.png));白背景变透明package com.goldgrid.socket.client;import java.awt.Graphics2D;import java.awt.Image;import java.awt.image.BufferedImage;import java.io.ByteArrayOutputStream;import java.io.File;import javax.imageio.ImageIO;import javax.swing.ImageIcon;import org.apache.log4j.Logger;public class Alpha {protected static Logger logger Logger.getLogger(ClientSocket.class);public byte[] transferAlpha(Image image) {ByteArrayOutputStream byteArrayOutputStream new ByteArrayOutputStream();try {ImageIcon imageIcon new ImageIcon(image);BufferedImage bufferedImage new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),BufferedImage.TYPE_4BYTE_ABGR);Graphics2D g2D (Graphics2D) bufferedImage.getGraphics();g2D.drawImage(imageIcon.getImage(), 0, 0, imageIcon.getImageObserver());int alpha 0;for (int j1 bufferedImage.getMinY(); j1 .getHeight(); j1) {for (int j2 bufferedImage.getMinX(); j2 .getWidth(); j2) {int rgb bufferedImage.getRGB(j2, j1);int R (rgb 0xff0000 ) 16 ;int G (rgb 0xff00 ) 8 ;int B (rgb 0xff );if(((255-R)30) ((255-G)30) ((255-B)30)){rgb ((alpha 1) }bufferedImage.setRGB(j2, j1, rgb);}}g2D.drawImage(bufferedImage, 0, 0, imageIcon.getImageObserver());//ImageIO.write(bufferedImage, png, new File(d:/test.png.png));ImageIO.write(bufferedImage, png, byteArrayOutputStream);} catch (Exception e) {logger.error(e.toString());}finally{}return byteArrayOutputStream.toByteArray();}}提供个比较傻的思路1.取得控件背景色2.指定需要透明的颜色3.逐点扫描image把需要透明的颜色setRGB成控件背景色预想效率很低我记得我以前用过很简单的方法设置透明色的不过忘了怎么用的了呵呵BufferedImage temp ImageIO.read(new File(chess.bmp));//取得图片int imgHeight temp.getHeight();//取得图片的长和宽int imgWidth temp.getWidth();int c temp.getRGB(3,3);BufferedImage bi new BufferedImage(imgWidth, imgHeight,BufferedImage.TYPE_4BYTE_ABGR);//新建一个类型支持透明的BufferedImagefor(int i 0; i {for(int j 0; j {if(temp.getRGB(i, j) c)bi.setRGB(i, j, c 0x00ffffff);//这里把背景设为透明elsebi.setRGB(i, j, temp.getRGB(i, j));}}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/925791.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!