Android Open Source - Android-NFC-WiFi-Controller Custom Q R Code






From Project

Back to project page Android-NFC-WiFi-Controller.

License

The source code is released under:

MIT License

If you think the Android project Android-NFC-WiFi-Controller listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package sanchezsobrino.multimedia.anwc.business;
/* ww w  . ja v  a 2 s . c om*/
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import net.glxn.qrgen.QRCode;

public class CustomQRCode {
  private final Color red_color = new Color(0xffdd0000);
  private final Color green_color = new Color(0xff009900);
  
  private BufferedImage raw_qr_code;
  private ImageIcon red_qr_code;
  private ImageIcon green_qr_code;
  
  public CustomQRCode(String str, int width, int height) throws IOException {
    raw_qr_code = ImageIO.read(QRCode.from(str).withSize(width, height).file());
    red_qr_code = new ImageIcon(replaceColor(raw_qr_code, Color.black, red_color));
    green_qr_code = new ImageIcon(replaceColor(raw_qr_code, Color.black, green_color));
  }
  
  public ImageIcon getRedQRCode() {
    return red_qr_code;
  }
  
  public ImageIcon getGreenQRCode() {
    return green_qr_code;
  }
  
  private BufferedImage replaceColor(BufferedImage image, Color src, Color dst) {
    BufferedImage copy = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = copy.createGraphics();
    g.drawRenderedImage(image, null);
    g.dispose();

    for (int i = 0; i < copy.getHeight(); i++) {
      for (int j = 0; j < copy.getWidth(); j++) {
        Color rgb = new Color(copy.getRGB(i, j));
        if (src.equals(rgb)) {
          copy.setRGB(i, j, dst.getRGB());
        } else {
          copy.setRGB(i, j, Color.TRANSLUCENT);
        }
      }
    }

    return copy;
  }
}




Java Source Code List

com.dm.zbar.android.scanner.CameraPreview.java
com.dm.zbar.android.scanner.ZBarConstants.java
com.dm.zbar.android.scanner.ZBarScannerActivity.java
sanchezsobrino.multimedia.anwc.CodeEvent.java
sanchezsobrino.multimedia.anwc.ConnectedActivity.java
sanchezsobrino.multimedia.anwc.ControlActivity.java
sanchezsobrino.multimedia.anwc.MainActivity.java
sanchezsobrino.multimedia.anwc.NfcUtils.java
sanchezsobrino.multimedia.anwc.business.AboutMenuItemListener.java
sanchezsobrino.multimedia.anwc.business.ChoosePortDialogListener.java
sanchezsobrino.multimedia.anwc.business.CodeEvent.java
sanchezsobrino.multimedia.anwc.business.CustomQRCode.java
sanchezsobrino.multimedia.anwc.business.ExitMenuItemListener.java
sanchezsobrino.multimedia.anwc.business.InstructionsMenuItemListener.java
sanchezsobrino.multimedia.anwc.business.KeySimulator.java
sanchezsobrino.multimedia.anwc.business.LocalizedString.java
sanchezsobrino.multimedia.anwc.business.TCPServer.java
sanchezsobrino.multimedia.anwc.persistence.LocalizedStringManager.java
sanchezsobrino.multimedia.anwc.presentation.ChoosePortDialog.java
sanchezsobrino.multimedia.anwc.presentation.LogPane.java
sanchezsobrino.multimedia.anwc.presentation.MainWindow.java