I want to know how to change QR code image size? This is my code. It creates QR code but small.
String Cus_Name = (String) cmbCus_NameAdd.getSelectedItem();
String Cus_Id = lblCus_IDAdd2.getText();
String Odr_No = lblOrderNoAdd2.getText();
String Matir = lblMeterialAdd2.getText();
String amount = txtNoOfProductAdd.getText();
String date = lblDateAdd2.getText();
String time = lblTimeAdd2.getText();
String place = (String) cmbPlaceAdd.getSelectedItem();
String newLine = System.getProperty("line.separator");
String Details = "Customer Name - " + Cus_Name + "" + newLine + " Customer ID - " + Cus_Id + "" + newLine + " Order No - " + Odr_No + "" + newLine + " Material - " + Matir + "" + newLine + " Amount - " + amount + "" + newLine + " Date - " + date + "" + newLine + " Time - " + time + "" + newLine + " Place - " + place + "";
ByteArrayOutputStream out = QRCode.from(Details).to(ImageType.JPG).stream(); // this line creates QR code
File f = new File("C:\\Users\\Pulasthi Dinusha\\Desktop\\MainGui\\lib\\QR_Generator_Libs\\" + Odr_No + ".jpg");
FileOutputStream fos;
try {
fos = new FileOutputStream(f);
fos.write(out.toByteArray());
fos.flush();
} catch (FileNotFoundException ex) {
Logger.getLogger(test2.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(test2.class.getName()).log(Level.SEVERE, null, ex);
}
ImageIcon iconLogo = new ImageIcon("C:\\Users\\Pulasthi Dinusha\\Desktop\\MainGui\\lib\\QR_Generator_Libs\\" + Odr_No + ".jpg");
// In init() method write this code
lblQRcodeAdd.setIcon(iconLogo);
My Solution Of QR Image Resize
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class QRCodeImageResizer {
public static void main(String[] args) throws IOException {
File folder = new File("/Users/pulasthi/Desktop/images");
File[] listOfFiles = folder.listFiles();
System.out.println("Total No of Files:"+listOfFiles.length);
Image img = null;
BufferedImage tempPNG = null;
BufferedImage tempJPG = null;
File newFilePNG = null;
File newFileJPG = null;
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
img = ImageIO.read(new File("/Users/pulasthi/Desktop/images/"+listOfFiles[i].getName()));
tempPNG = resizeImage(img, 100, 100);
tempJPG = resizeImage(img, 100, 100);
newFilePNG = new File("/Users/pulasthi/Desktop/images/resize/"+listOfFiles[i].getName()+"_New.png");
newFileJPG = new File("/Users/pulasthi/Desktop/images/resize/"+listOfFiles[i].getName()+"_New.jpg");
ImageIO.write(tempPNG, "png", newFilePNG);
ImageIO.write(tempJPG, "jpg", newFileJPG);
}
}
System.out.println("Saved");
}
/**
* This function resize the image file and returns the BufferedImage object that can be saved to file system.
*/
public static BufferedImage resizeImage(final Image image, int width, int height) {
final BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
final Graphics2D graphics2D = bufferedImage.createGraphics();
graphics2D.setComposite(AlphaComposite.Src);
//below three lines are for RenderingHints for better image quality at cost of higher processing time
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.drawImage(image, 0, 0, width, height, null);
graphics2D.dispose();
return bufferedImage;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.