java二维码工具类,中间带LOGO的,很强大 .

2023-11-01

 

  1. package com.util.cccm;  
  2.   
  3. import java.awt.BasicStroke;  
  4. import java.awt.Graphics;  
  5. import java.awt.Graphics2D;  
  6. import java.awt.Image;  
  7. import java.awt.Shape;  
  8. import java.awt.geom.RoundRectangle2D;  
  9. import java.awt.image.BufferedImage;  
  10. import java.io.File;  
  11. import java.io.OutputStream;  
  12. import java.util.Hashtable;  
  13. import java.util.Random;  
  14.   
  15. import javax.imageio.ImageIO;  
  16.   
  17. import com.google.zxing.BarcodeFormat;  
  18. import com.google.zxing.BinaryBitmap;  
  19. import com.google.zxing.DecodeHintType;  
  20. import com.google.zxing.EncodeHintType;  
  21. import com.google.zxing.MultiFormatReader;  
  22. import com.google.zxing.MultiFormatWriter;  
  23. import com.google.zxing.Result;  
  24. import com.google.zxing.common.BitMatrix;  
  25. import com.google.zxing.common.HybridBinarizer;  
  26. import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;  
  27.   
  28. /** 
  29.  * 二维码工具类 
  30.  *  
  31.  */  
  32. public class QRCodeUtil {  
  33.   
  34.     private static final String CHARSET = "utf-8";  
  35.     private static final String FORMAT_NAME = "JPG";  
  36.     // 二维码尺寸   
  37.     private static final int QRCODE_SIZE = 300;  
  38.     // LOGO宽度   
  39.     private static final int WIDTH = 60;  
  40.     // LOGO高度   
  41.     private static final int HEIGHT = 60;  
  42.   
  43.     private static BufferedImage createImage(String content, String imgPath,  
  44.             boolean needCompress) throws Exception {  
  45.         Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();  
  46.         hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);  
  47.         hints.put(EncodeHintType.CHARACTER_SET, CHARSET);  
  48.         hints.put(EncodeHintType.MARGIN, 1);  
  49.         BitMatrix bitMatrix = new MultiFormatWriter().encode(content,  
  50.                 BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);  
  51.         int width = bitMatrix.getWidth();  
  52.         int height = bitMatrix.getHeight();  
  53.         BufferedImage image = new BufferedImage(width, height,  
  54.                 BufferedImage.TYPE_INT_RGB);  
  55.         for (int x = 0; x < width; x++) {  
  56.             for (int y = 0; y < height; y++) {  
  57.                 image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000  
  58.                         : 0xFFFFFFFF);  
  59.             }  
  60.         }  
  61.         if (imgPath == null || "".equals(imgPath)) {  
  62.             return image;  
  63.         }  
  64.         // 插入图片   
  65.         QRCodeUtil.insertImage(image, imgPath, needCompress);  
  66.         return image;  
  67.     }  
  68.   
  69.     /** 
  70.      * 插入LOGO 
  71.      *  
  72.      * @param source 
  73.      *            二维码图片 
  74.      * @param imgPath 
  75.      *            LOGO图片地址 
  76.      * @param needCompress 
  77.      *            是否压缩 
  78.      * @throws Exception 
  79.      */  
  80.     private static void insertImage(BufferedImage source, String imgPath,  
  81.             boolean needCompress) throws Exception {  
  82.         File file = new File(imgPath);  
  83.         if (!file.exists()) {  
  84.             System.err.println(""+imgPath+"   该文件不存在!");  
  85.             return;  
  86.         }  
  87.         Image src = ImageIO.read(new File(imgPath));  
  88.         int width = src.getWidth(null);  
  89.         int height = src.getHeight(null);  
  90.         if (needCompress) { // 压缩LOGO   
  91.             if (width > WIDTH) {  
  92.                 width = WIDTH;  
  93.             }  
  94.             if (height > HEIGHT) {  
  95.                 height = HEIGHT;  
  96.             }  
  97.             Image image = src.getScaledInstance(width, height,  
  98.                     Image.SCALE_SMOOTH);  
  99.             BufferedImage tag = new BufferedImage(width, height,  
  100.                     BufferedImage.TYPE_INT_RGB);  
  101.             Graphics g = tag.getGraphics();  
  102.             g.drawImage(image, 00null); // 绘制缩小后的图   
  103.             g.dispose();  
  104.             src = image;  
  105.         }  
  106.         // 插入LOGO   
  107.         Graphics2D graph = source.createGraphics();  
  108.         int x = (QRCODE_SIZE - width) / 2;  
  109.         int y = (QRCODE_SIZE - height) / 2;  
  110.         graph.drawImage(src, x, y, width, height, null);  
  111.         Shape shape = new RoundRectangle2D.Float(x, y, width, width, 66);  
  112.         graph.setStroke(new BasicStroke(3f));  
  113.         graph.draw(shape);  
  114.         graph.dispose();  
  115.     }  
  116.   
  117.     /** 
  118.      * 生成二维码(内嵌LOGO) 
  119.      *  
  120.      * @param content 
  121.      *            内容 
  122.      * @param imgPath 
  123.      *            LOGO地址 
  124.      * @param destPath 
  125.      *            存放目录 
  126.      * @param needCompress 
  127.      *            是否压缩LOGO 
  128.      * @throws Exception 
  129.      */  
  130.     public static void encode(String content, String imgPath, String destPath,  
  131.             boolean needCompress) throws Exception {  
  132.         BufferedImage image = QRCodeUtil.createImage(content, imgPath,  
  133.                 needCompress);  
  134.         mkdirs(destPath);  
  135.         String file = new Random().nextInt(99999999)+".jpg";  
  136.         ImageIO.write(image, FORMAT_NAME, new File(destPath+"/"+file));  
  137.     }  
  138.   
  139.     /** 
  140.      * 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常) 
  141.      * @author lanyuan 
  142.      * Email: mmm333zzz520@163.com 
  143.      * @date 2013-12-11 上午10:16:36 
  144.      * @param destPath 存放目录 
  145.      */  
  146.     public static void mkdirs(String destPath) {  
  147.         File file =new File(destPath);      
  148.         //当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)   
  149.         if (!file.exists() && !file.isDirectory()) {  
  150.             file.mkdirs();  
  151.         }  
  152.     }  
  153.   
  154.     /** 
  155.      * 生成二维码(内嵌LOGO) 
  156.      *  
  157.      * @param content 
  158.      *            内容 
  159.      * @param imgPath 
  160.      *            LOGO地址 
  161.      * @param destPath 
  162.      *            存储地址 
  163.      * @throws Exception 
  164.      */  
  165.     public static void encode(String content, String imgPath, String destPath)  
  166.             throws Exception {  
  167.         QRCodeUtil.encode(content, imgPath, destPath, false);  
  168.     }  
  169.   
  170.     /** 
  171.      * 生成二维码 
  172.      *  
  173.      * @param content 
  174.      *            内容 
  175.      * @param destPath 
  176.      *            存储地址 
  177.      * @param needCompress 
  178.      *            是否压缩LOGO 
  179.      * @throws Exception 
  180.      */  
  181.     public static void encode(String content, String destPath,  
  182.             boolean needCompress) throws Exception {  
  183.         QRCodeUtil.encode(content, null, destPath, needCompress);  
  184.     }  
  185.   
  186.     /** 
  187.      * 生成二维码 
  188.      *  
  189.      * @param content 
  190.      *            内容 
  191.      * @param destPath 
  192.      *            存储地址 
  193.      * @throws Exception 
  194.      */  
  195.     public static void encode(String content, String destPath) throws Exception {  
  196.         QRCodeUtil.encode(content, null, destPath, false);  
  197.     }  
  198.   
  199.     /** 
  200.      * 生成二维码(内嵌LOGO) 
  201.      *  
  202.      * @param content 
  203.      *            内容 
  204.      * @param imgPath 
  205.      *            LOGO地址 
  206.      * @param output 
  207.      *            输出流 
  208.      * @param needCompress 
  209.      *            是否压缩LOGO 
  210.      * @throws Exception 
  211.      */  
  212.     public static void encode(String content, String imgPath,  
  213.             OutputStream output, boolean needCompress) throws Exception {  
  214.         BufferedImage image = QRCodeUtil.createImage(content, imgPath,  
  215.                 needCompress);  
  216.         ImageIO.write(image, FORMAT_NAME, output);  
  217.     }  
  218.   
  219.     /** 
  220.      * 生成二维码 
  221.      *  
  222.      * @param content 
  223.      *            内容 
  224.      * @param output 
  225.      *            输出流 
  226.      * @throws Exception 
  227.      */  
  228.     public static void encode(String content, OutputStream output)  
  229.             throws Exception {  
  230.         QRCodeUtil.encode(content, null, output, false);  
  231.     }  
  232.   
  233.     /** 
  234.      * 解析二维码 
  235.      *  
  236.      * @param file 
  237.      *            二维码图片 
  238.      * @return 
  239.      * @throws Exception 
  240.      */  
  241.     public static String decode(File file) throws Exception {  
  242.         BufferedImage image;  
  243.         image = ImageIO.read(file);  
  244.         if (image == null) {  
  245.             return null;  
  246.         }  
  247.         BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(  
  248.                 image);  
  249.         BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));  
  250.         Result result;  
  251.         Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();  
  252.         hints.put(DecodeHintType.CHARACTER_SET, CHARSET);  
  253.         result = new MultiFormatReader().decode(bitmap, hints);  
  254.         String resultStr = result.getText();  
  255.         return resultStr;  
  256.     }  
  257.   
  258.     /** 
  259.      * 解析二维码 
  260.      *  
  261.      * @param path 
  262.      *            二维码图片地址 
  263.      * @return 
  264.      * @throws Exception 
  265.      */  
  266.     public static String decode(String path) throws Exception {  
  267.         return QRCodeUtil.decode(new File(path));  
  268.     }  
  269.   
  270.     public static void main(String[] args) throws Exception {  
  271.         String text = "薯 灯可分列式本上楞珂要瓜熟蒂落!000000000000000";  
  272.         QRCodeUtil.encode(text, "c:/df.jsp""c:/a/"true);  
  273.     }  
  274. }  
package com.util.cccm;

import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.OutputStream;
import java.util.Hashtable;
import java.util.Random;

import javax.imageio.ImageIO;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.Result;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

/**
 * 二维码工具类
 * 
 */
public class QRCodeUtil {

	private static final String CHARSET = "utf-8";
	private static final String FORMAT_NAME = "JPG";
	// 二维码尺寸
	private static final int QRCODE_SIZE = 300;
	// LOGO宽度
	private static final int WIDTH = 60;
	// LOGO高度
	private static final int HEIGHT = 60;

	private static BufferedImage createImage(String content, String imgPath,
			boolean needCompress) throws Exception {
		Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
		hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
		hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
		hints.put(EncodeHintType.MARGIN, 1);
		BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
				BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);
		int width = bitMatrix.getWidth();
		int height = bitMatrix.getHeight();
		BufferedImage image = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000
						: 0xFFFFFFFF);
			}
		}
		if (imgPath == null || "".equals(imgPath)) {
			return image;
		}
		// 插入图片
		QRCodeUtil.insertImage(image, imgPath, needCompress);
		return image;
	}

	/**
	 * 插入LOGO
	 * 
	 * @param source
	 *            二维码图片
	 * @param imgPath
	 *            LOGO图片地址
	 * @param needCompress
	 *            是否压缩
	 * @throws Exception
	 */
	private static void insertImage(BufferedImage source, String imgPath,
			boolean needCompress) throws Exception {
		File file = new File(imgPath);
		if (!file.exists()) {
			System.err.println(""+imgPath+"   该文件不存在!");
			return;
		}
		Image src = ImageIO.read(new File(imgPath));
		int width = src.getWidth(null);
		int height = src.getHeight(null);
		if (needCompress) { // 压缩LOGO
			if (width > WIDTH) {
				width = WIDTH;
			}
			if (height > HEIGHT) {
				height = HEIGHT;
			}
			Image image = src.getScaledInstance(width, height,
					Image.SCALE_SMOOTH);
			BufferedImage tag = new BufferedImage(width, height,
					BufferedImage.TYPE_INT_RGB);
			Graphics g = tag.getGraphics();
			g.drawImage(image, 0, 0, null); // 绘制缩小后的图
			g.dispose();
			src = image;
		}
		// 插入LOGO
		Graphics2D graph = source.createGraphics();
		int x = (QRCODE_SIZE - width) / 2;
		int y = (QRCODE_SIZE - height) / 2;
		graph.drawImage(src, x, y, width, height, null);
		Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
		graph.setStroke(new BasicStroke(3f));
		graph.draw(shape);
		graph.dispose();
	}

	/**
	 * 生成二维码(内嵌LOGO)
	 * 
	 * @param content
	 *            内容
	 * @param imgPath
	 *            LOGO地址
	 * @param destPath
	 *            存放目录
	 * @param needCompress
	 *            是否压缩LOGO
	 * @throws Exception
	 */
	public static void encode(String content, String imgPath, String destPath,
			boolean needCompress) throws Exception {
		BufferedImage image = QRCodeUtil.createImage(content, imgPath,
				needCompress);
		mkdirs(destPath);
		String file = new Random().nextInt(99999999)+".jpg";
		ImageIO.write(image, FORMAT_NAME, new File(destPath+"/"+file));
	}

	/**
	 * 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
	 * @author lanyuan
	 * Email: mmm333zzz520@163.com
	 * @date 2013-12-11 上午10:16:36
	 * @param destPath 存放目录
	 */
	public static void mkdirs(String destPath) {
		File file =new File(destPath);    
		//当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
		if (!file.exists() && !file.isDirectory()) {
			file.mkdirs();
		}
	}

	/**
	 * 生成二维码(内嵌LOGO)
	 * 
	 * @param content
	 *            内容
	 * @param imgPath
	 *            LOGO地址
	 * @param destPath
	 *            存储地址
	 * @throws Exception
	 */
	public static void encode(String content, String imgPath, String destPath)
			throws Exception {
		QRCodeUtil.encode(content, imgPath, destPath, false);
	}

	/**
	 * 生成二维码
	 * 
	 * @param content
	 *            内容
	 * @param destPath
	 *            存储地址
	 * @param needCompress
	 *            是否压缩LOGO
	 * @throws Exception
	 */
	public static void encode(String content, String destPath,
			boolean needCompress) throws Exception {
		QRCodeUtil.encode(content, null, destPath, needCompress);
	}

	/**
	 * 生成二维码
	 * 
	 * @param content
	 *            内容
	 * @param destPath
	 *            存储地址
	 * @throws Exception
	 */
	public static void encode(String content, String destPath) throws Exception {
		QRCodeUtil.encode(content, null, destPath, false);
	}

	/**
	 * 生成二维码(内嵌LOGO)
	 * 
	 * @param content
	 *            内容
	 * @param imgPath
	 *            LOGO地址
	 * @param output
	 *            输出流
	 * @param needCompress
	 *            是否压缩LOGO
	 * @throws Exception
	 */
	public static void encode(String content, String imgPath,
			OutputStream output, boolean needCompress) throws Exception {
		BufferedImage image = QRCodeUtil.createImage(content, imgPath,
				needCompress);
		ImageIO.write(image, FORMAT_NAME, output);
	}

	/**
	 * 生成二维码
	 * 
	 * @param content
	 *            内容
	 * @param output
	 *            输出流
	 * @throws Exception
	 */
	public static void encode(String content, OutputStream output)
			throws Exception {
		QRCodeUtil.encode(content, null, output, false);
	}

	/**
	 * 解析二维码
	 * 
	 * @param file
	 *            二维码图片
	 * @return
	 * @throws Exception
	 */
	public static String decode(File file) throws Exception {
		BufferedImage image;
		image = ImageIO.read(file);
		if (image == null) {
			return null;
		}
		BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(
				image);
		BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
		Result result;
		Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
		hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
		result = new MultiFormatReader().decode(bitmap, hints);
		String resultStr = result.getText();
		return resultStr;
	}

	/**
	 * 解析二维码
	 * 
	 * @param path
	 *            二维码图片地址
	 * @return
	 * @throws Exception
	 */
	public static String decode(String path) throws Exception {
		return QRCodeUtil.decode(new File(path));
	}

	public static void main(String[] args) throws Exception {
		String text = "薯 灯可分列式本上楞珂要瓜熟蒂落!000000000000000";
		QRCodeUtil.encode(text, "c:/df.jsp", "c:/a/", true);
	}
}

 

 

 

 

  1.   
  1. package com.util.cccm;  
  2.   
  3. import java.awt.Graphics2D;  
  4. import java.awt.geom.AffineTransform;  
  5. import java.awt.image.BufferedImage;  
  6.   
  7. import com.google.zxing.LuminanceSource;  
  8.   
  9. public class BufferedImageLuminanceSource extends LuminanceSource {  
  10.     private final BufferedImage image;  
  11.     private final int left;  
  12.     private final int top;  
  13.   
  14.     public BufferedImageLuminanceSource(BufferedImage image) {  
  15.         this(image, 00, image.getWidth(), image.getHeight());  
  16.     }  
  17.   
  18.     public BufferedImageLuminanceSource(BufferedImage image, int left,  
  19.             int top, int width, int height) {  
  20.         super(width, height);  
  21.   
  22.         int sourceWidth = image.getWidth();  
  23.         int sourceHeight = image.getHeight();  
  24.         if (left + width > sourceWidth || top + height > sourceHeight) {  
  25.             throw new IllegalArgumentException(  
  26.                     "Crop rectangle does not fit within image data.");  
  27.         }  
  28.   
  29.         for (int y = top; y < top + height; y++) {  
  30.             for (int x = left; x < left + width; x++) {  
  31.                 if ((image.getRGB(x, y) & 0xFF000000) == 0) {  
  32.                     image.setRGB(x, y, 0xFFFFFFFF); // = white   
  33.                 }  
  34.             }  
  35.         }  
  36.   
  37.         this.image = new BufferedImage(sourceWidth, sourceHeight,  
  38.                 BufferedImage.TYPE_BYTE_GRAY);  
  39.         this.image.getGraphics().drawImage(image, 00null);  
  40.         this.left = left;  
  41.         this.top = top;  
  42.     }  
  43.   
  44.       
  45.     public byte[] getRow(int y, byte[] row) {  
  46.         if (y < 0 || y >= getHeight()) {  
  47.             throw new IllegalArgumentException(  
  48.                     "Requested row is outside the image: " + y);  
  49.         }  
  50.         int width = getWidth();  
  51.         if (row == null || row.length < width) {  
  52.             row = new byte[width];  
  53.         }  
  54.         image.getRaster().getDataElements(left, top + y, width, 1, row);  
  55.         return row;  
  56.     }  
  57.   
  58.       
  59.     public byte[] getMatrix() {  
  60.         int width = getWidth();  
  61.         int height = getHeight();  
  62.         int area = width * height;  
  63.         byte[] matrix = new byte[area];  
  64.         image.getRaster().getDataElements(left, top, width, height, matrix);  
  65.         return matrix;  
  66.     }  
  67.   
  68.       
  69.     public boolean isCropSupported() {  
  70.         return true;  
  71.     }  
  72.   
  73.       
  74.     public LuminanceSource crop(int left, int top, int width, int height) {  
  75.         return new BufferedImageLuminanceSource(image, this.left + left,  
  76.                 this.top + top, width, height);  
  77.     }  
  78.   
  79.       
  80.     public boolean isRotateSupported() {  
  81.         return true;  
  82.     }  
  83.   
  84.       
  85.     public LuminanceSource rotateCounterClockwise() {  
  86.         int sourceWidth = image.getWidth();  
  87.         int sourceHeight = image.getHeight();  
  88.         AffineTransform transform = new AffineTransform(0.0, -1.01.0,  
  89.                 0.00.0, sourceWidth);  
  90.         BufferedImage rotatedImage = new BufferedImage(sourceHeight,  
  91.                 sourceWidth, BufferedImage.TYPE_BYTE_GRAY);  
  92.         Graphics2D g = rotatedImage.createGraphics();  
  93.         g.drawImage(image, transform, null);  
  94.         g.dispose();  
  95.         int width = getWidth();  
  96.         return new BufferedImageLuminanceSource(rotatedImage, top,  
  97.                 sourceWidth - (left + width), getHeight(), width);  
  98.     }  
  99. }  
package com.util.cccm;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;

import com.google.zxing.LuminanceSource;

public class BufferedImageLuminanceSource extends LuminanceSource {
	private final BufferedImage image;
	private final int left;
	private final int top;

	public BufferedImageLuminanceSource(BufferedImage image) {
		this(image, 0, 0, image.getWidth(), image.getHeight());
	}

	public BufferedImageLuminanceSource(BufferedImage image, int left,
			int top, int width, int height) {
		super(width, height);

		int sourceWidth = image.getWidth();
		int sourceHeight = image.getHeight();
		if (left + width > sourceWidth || top + height > sourceHeight) {
			throw new IllegalArgumentException(
					"Crop rectangle does not fit within image data.");
		}

		for (int y = top; y < top + height; y++) {
			for (int x = left; x < left + width; x++) {
				if ((image.getRGB(x, y) & 0xFF000000) == 0) {
					image.setRGB(x, y, 0xFFFFFFFF); // = white
				}
			}
		}

		this.image = new BufferedImage(sourceWidth, sourceHeight,
				BufferedImage.TYPE_BYTE_GRAY);
		this.image.getGraphics().drawImage(image, 0, 0, null);
		this.left = left;
		this.top = top;
	}

	
	public byte[] getRow(int y, byte[] row) {
		if (y < 0 || y >= getHeight()) {
			throw new IllegalArgumentException(
					"Requested row is outside the image: " + y);
		}
		int width = getWidth();
		if (row == null || row.length < width) {
			row = new byte[width];
		}
		image.getRaster().getDataElements(left, top + y, width, 1, row);
		return row;
	}

	
	public byte[] getMatrix() {
		int width = getWidth();
		int height = getHeight();
		int area = width * height;
		byte[] matrix = new byte[area];
		image.getRaster().getDataElements(left, top, width, height, matrix);
		return matrix;
	}

	
	public boolean isCropSupported() {
		return true;
	}

	
	public LuminanceSource crop(int left, int top, int width, int height) {
		return new BufferedImageLuminanceSource(image, this.left + left,
				this.top + top, width, height);
	}

	
	public boolean isRotateSupported() {
		return true;
	}

	
	public LuminanceSource rotateCounterClockwise() {
		int sourceWidth = image.getWidth();
		int sourceHeight = image.getHeight();
		AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0,
				0.0, 0.0, sourceWidth);
		BufferedImage rotatedImage = new BufferedImage(sourceHeight,
				sourceWidth, BufferedImage.TYPE_BYTE_GRAY);
		Graphics2D g = rotatedImage.createGraphics();
		g.drawImage(image, transform, null);
		g.dispose();
		int width = getWidth();
		return new BufferedImageLuminanceSource(rotatedImage, top,
				sourceWidth - (left + width), getHeight(), width);
	}
}


 

 

 

 

 

 源码和包下载:http://download.csdn.net/detail/mmm333zzz/6695793

原文地址:

http://blog.csdn.net/mmm333zzz/article/details/17259513

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java二维码工具类,中间带LOGO的,很强大 . 的相关文章

随机推荐

  • python自动化测试web页面组成_Selenium自动化测试网页

    今天想跟大家分享的是 关于selenium的自动化测试一些基础的东西 安装环境 1 Python环境 安装完成后通过Windows命令提示符CMD输入 python 查看是否安装成功 2 安装setuptools与pip setuptool
  • markdown 矩阵

    无括号 begin matrix 1 2 3 4 5 6 7 8 9 end matrix 1 2
  • VUE3 + Ant Design Vue构建

    步骤 node 和 npm 已安装前提下 1 安装vue 安装vue脚手架 npm install g vue cli 安装vue vue create 项目名 2 安装Ant Design Vue 最好安装的时候不要用pnpm 我用pnp
  • 内存分区-包含bss段data段

    都说四大内存分区 代码区 全局区 堆区 栈区 但是这个说法比较粗略 其实从低地址 gt 高地址 依次为代码区 常量 全局变量和静态变量 bss段 堆区 栈区 代码区 常量 const define 全局区 data段 静态变量和初始化的全局
  • RabbitMQ--基础--11.2--幂等性,惰性队列

    RabbitMQ 基础 11 2 幂等性 惰性队列 1 幂等性 就是重复消费消息 1 1 消息重复消费 消费者在消费MQ中的消息时 MQ已把消息发送给消费者 消费者在给MQ返回ack时网络中断 故MQ未收到确认消息 该条消息会重新发给其它的
  • 线程池的使用(7种创建方法)

    目录 1 固定数量的线程池 a 线程池返回结果 b 定义线程池名称或优先级 2 带缓存的线程池 3 执 定时任务 a 延迟执 次 b 固定频率执 c scheduleAtFixedRate VS scheduleWithFixedDelay
  • VS中后台运行设置

    背景知识 操作系统装载应用程序后 做完初始化工作就转到程序的入口点执行 程序默认入口点实际上是由连接程序设置的 不同的连接器选择的入口函数也不尽相同 在VC 下 连接器对控制台程序设置的入口函数是 mainCRTStartup mainCR
  • 【Linux】linux常用基本命令

    Linux中许多常用命令是必须掌握的 这里将我学linux入门时学的一些常用的基本命令分享给大家一下 希望可以帮助你们 这个是我将鸟哥书上的进行了一下整理的 希望不要涉及到版权问题 1 显示日期的指令 date 2 显示日历的指令 cal
  • 熔断与降级的区别

    原文 熔断与降级的区别 前言 今天在博客上看到一句话 在分布式系统中 限流和熔断是处理并发的两大利器 关于限流和熔断 需要记住一句话 客户端熔断 服务端限流 发现为什么是限流和熔断 而不是限流和降级 于是就有了这篇文章 相似处 1 目的一致
  • Zerotier 搭建手册(含Moon节点)

    一 前言 没有申请到公网IP 内网穿透只好选用zerotier 好处就是P2P端点的带宽 不受云服务器和FRP带宽限制 打算用zerotier组建了笔记本 NAS 手机三个端 满足NAS在IPV4大内网环境下的相互访问 zerotier主服
  • mysql-5.0.24a-win32.zip_go.sum · skymysky/Nightingale - Gitee.com

    bazil org fuse v0 0 0 20160811212531 371fbbdaa898 go mod h1 Xbm BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8 cloud google com
  • C++ ifstream open 读取txt文件出现中文乱码的解决方法

    由于编解码的问题 txt读写会出现中文乱码 打开txt文件 点另存为 可看到编码方式有 编码方式为UTF 8时 会出现中文乱码 将编码方式换为ANSI时 问题解决
  • spring boot的两种部署方式

    spring boot的两种部署方式 文章目录 spring boot的两种部署方式 前言 一 jar包部署 二 war包部署 jar包和war包方式对比 前言 springboot的打包方式有很多种 有打成war的 有打成jar的 也有直
  • 使用Matlab设计数字滤波器,从原理到代码

    目录 0 前言 1 数字滤波器的设计方法概述 2 IIR数字滤波器的设计方法 2 1 模拟滤波器设计 2 1 1 巴特沃斯滤波器设计 2 1 2 切比雪夫滤波器设计 2 1 3 椭圆滤波器设计 2 2 模拟滤波器转数字滤波器 2 2 1 冲
  • 【Android】Android6.0+ 动态申请权限

    Android 6 0 SDK 版本号大于23后 对于普通权限可以在AndroidMinifest xml文件中可以直接使用 而对于那些危险权限 如 定位权限 通话 发送短信等 需要动态申请权限 下面是一个通过高德定位的案例 MainAct
  • request对象对请求体,请求头参数的解析

    1 请求体参数解析 1 1 GET请求 1 1 1 请求url中 xxx xxx格式为查询字符串参数 通过request GET获取请求参数 1 1 2 请求url中 xxx 2 xxx格式为路径参数 通过request GET获取 1 1
  • IDEA常用配置之双斜杠注释紧跟代码头

    文章目录 双斜杠注释改成紧跟代码头 双斜杠注释改成紧跟代码头
  • qRegisterMetaType-Qt中注册定义类型

    概述 如果想要我们自己自定义的类型也可以有 Qt 自己类型的功能的话 就必须注册我们的类型到 Qt 中 这样才可以在信号和槽的通讯机制中使用我们的自定义的类型 Q DECLARE METATYPE 被 Q DECLARE METATYPEQ
  • QMetaObject::connectSlotsByName: No matching signal for问题的解决方法

    之前是用转到槽的方式添加信号回调 现在发现结构混乱 改为手动connect 删掉之前的回调函数后 再编译 找到报错的地方 删除case 然后自己添加connect 注意此时代码运行会报 QMetaObject connectSlotsByN
  • java二维码工具类,中间带LOGO的,很强大 .

    java view plain copy print package com util cccm import java awt BasicStroke import java awt Graphics import java awt Gr