Guest User

Untitled

a guest
Oct 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import java.util.Map;
  2.  
  3. import javax.imageio.ImageIO;
  4. import java.awt.Graphics2D;
  5.  
  6.  
  7. import java.util.HashMap;
  8. import java.*;
  9. import java.awt.image.BufferedImage;
  10. import java.io.File;
  11. import java.io.IOException;
  12.  
  13.  
  14. public class Utils {
  15. public static String getZplCode(BufferedImage bitmap, Boolean addHeaderFooter) {
  16. ZPLConverter zp = new ZPLConverter();
  17. zp.setCompressHex(true);
  18. zp.setBlacknessLimitPercentage(80);
  19. BufferedImage grayBitmap = toGrayScale(bitmap);
  20. return zp.convertFromImage(grayBitmap, addHeaderFooter);
  21. }
  22.  
  23. public static void main(String[] args) throws IOException {
  24. BufferedImage bitmap = ImageIO.read(new File("/Users/shradheyathakre/Downloads/temp.png"));
  25. System.out.println(getZplCode(bitmap, true));
  26. }
  27.  
  28. public static BufferedImage toGrayScale(BufferedImage img) {
  29. for (int x = 0; x < img.getWidth(); ++x) {
  30. for (int y = 0; y < img.getHeight(); ++y)
  31. {
  32. int rgb = img.getRGB(x, y);
  33. int r = (rgb >> 16) & 0xFF;
  34. int g = (rgb >> 8) & 0xFF;
  35. int b = (rgb & 0xFF);
  36.  
  37. int grayLevel = (r + g + b) / 3;
  38. int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel;
  39. img.setRGB(x, y, gray);
  40. }
  41. }
  42.  
  43. return img;
  44. }
  45. }
Add Comment
Please, Sign In to add comment