二维码
来源:互联网 发布:c语言if else嵌套 编辑:程序博客网 时间:2024/05/07 01:12
public class MainActivity extends AppCompatActivity { private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv= (ImageView) findViewById(R.id.iv); } private Bitmap generateBitmap(String content,int width, int height) { QRCodeWriter qrCodeWriter = new QRCodeWriter(); Map<EncodeHintType, String> hints = new HashMap<>(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); try { BitMatrix encode = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints); int[] pixels = new int[width * height]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (encode.get(j, i)) { pixels[i * width + j] = 0x00000000; } else { pixels[i * width + j] = 0xffffffff; } } } return Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565); } catch (WriterException e) { e.printStackTrace(); } return null; } public void generate(View view) { Bitmap qrBitmap = generateBitmap("我是xxx,请叫我xxx",400, 400); iv.setImageBitmap(qrBitmap); }}
阅读全文
0 0
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- 二维码
- Maven之(五)Maven仓库
- Titan数据库快速入门之决战云巅
- linux-C下的死锁检测(pthread_mutex_)
- TyrantMaster(2)
- get和post的区别
- 二维码
- kafka中的topic为什么要进行分区?
- python smtplib 发送邮件
- [算法分析与设计] leetcode 每周一题: 030. Substring with Concatenation of All Words
- HDU 2047 阿牛的EOF牛肉串
- 前缀和
- Python安装教程
- Titan数据库快速入门之神的光芒
- HashMap为什么是不安全的?HashTable和ConcurrentHashMap为什么是安全的 ?