-
大小: 1014KB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-11-06
- 语言: Java
- 标签:
资源简介
java生成二维码,中间带logo,logo居中,完美实现,logo大小可调整。
代码片段和文件信息
package com;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
/**
* author jason
* date 2010-8-20
*/
public class FileUtility {
/**
* 图片文件类型
* @param o
* @return
*/
public static String getFormatName(object o) {
try {
ImageInputStream iis = ImageIO.createImageInputStream(o);
Iterator iter = ImageIO.getImageReaders(iis);
if (!iter.hasNext()) {
return null;
}
ImageReader reader = iter.next();
iis.close();
return reader.getFormatName();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 缩放图片大小
* @param srcBufImage
* @param width
* @param height
* @return
*/
public static BufferedImage rize(BufferedImage srcBufImage int width
int height) {
BufferedImage bufTarget = null;
double sx = (double) width / srcBufImage.getWidth();
double sy = (double) height / srcBufImage.getHeight();
int type = srcBufImage.getType();
if (type == BufferedImage.TYPE_CUSTOM) {
ColorModel cm = srcBufImage.getColorModel();
WritableRaster raster = cm.createCompatibleWritableRaster(width
height);
boolean alphaPremultiplied = cm.isAlphaPremultiplied();
bufTarget = new BufferedImage(cm raster alphaPremultiplied null);
} else
bufTarget = new BufferedImage(width height type);
Graphics2D g = bufTarget.createGraphics();
g.setRenderingHint(RenderingHints.KEY_RENDERING
RenderingHints.VALUE_RENDER_QUALITY);
g.drawRenderedImage(srcBufImage AffineTransform.getScaleInstance(sx
sy));
g.dispose();
return bufTarget;
}
/**
* 读取文件名字
* @param filePath
* @return
*/
public static String getFileName(String filePath){
String flot=“\\“;
String flotTwo=“/“;
if(filePath!=null&&!filePath.trim().equals(““)&&filePath.lastIndexOf(flot)!=-1){
String name=filePath.substring(filePath.lastIndexOf(flot)+1filePath.length());
return name;
}else if(filePath!=null&&!filePath.trim().equals(““)&&filePath.lastIndexOf(flotTwo)!=-1){
String name=filePath.substring(filePath.lastIndexOf(flotTwo)+1filePath.length());
return name;
}
return null;
}
/**
* 去掉字符串右边的空格
* @param str 要处理的字符串
* @return 处理后的字符串
*/
public static String rightTrim(String str) {
if (str == null) {
return ““;
}
int length = str.length();
for (int i = length - 1; i >= 0; i--) {
if (str.charAt(i) != 0x20) {
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 354 2013-05-27 15:09 TwoCode\.classpath
文件 383 2013-05-27 15:08 TwoCode\.project
文件 629 2013-05-27 15:08 TwoCode\.settings\org.eclipse.jdt.core.prefs
文件 4106 2013-05-27 15:10 TwoCode\bin\com\FileUtility.class
文件 6345 2013-05-27 15:10 TwoCode\bin\com\TwoDimensionCode.class
文件 808 2013-05-27 15:09 TwoCode\bin\com\TwoDimensionCodeImage.class
文件 1099539 2013-05-23 17:40 TwoCode\lib\QRCode.jar
文件 3674 2013-05-27 15:10 TwoCode\src\com\FileUtility.java
文件 7329 2013-05-27 15:10 TwoCode\src\com\TwoDimensionCode.java
文件 630 2013-05-27 15:08 TwoCode\src\com\TwoDimensionCodeImage.java
目录 0 2013-05-27 15:09 TwoCode\bin\com
目录 0 2013-05-27 15:08 TwoCode\src\com
目录 0 2013-05-27 15:08 TwoCode\.settings
目录 0 2013-05-27 15:09 TwoCode\bin
目录 0 2013-05-27 15:09 TwoCode\lib
目录 0 2013-05-27 15:08 TwoCode\src
目录 0 2013-05-27 15:09 TwoCode
----------- --------- ---------- ----- ----
1123797 17
评论
共有 条评论