解决方案 »
- android如何能定时下载东西?
- android获取其浏览器内全部网页地址
- java的线程里有没有类似vc的CriticalSection
- android摄像头采集 + x264进行编码
- AutoCompleteTextView如果内容过多会自动横向撑开到屏幕外去了。
- 求助大神,安卓虚拟机数据库找不到文件
- 求Android设备间屏幕共享实现方案
- android自定义悬浮数字键盘
- android系统手机, 检测网络上的新固件,有固件有更新时,下载更新包, android系统是如何实现这个功能的?
- android sdk如何运行程序哈?
- Android程序不能运行
- 在写安卓内嵌浏览器的时候,正常跳转到百度后,在百度搜索框里无法输入,输入的内容自动填写到了地址栏
楼主再仔细看看代码
我生成的bitmap在imageview里面是可以使用的,但是保存成文件就不行了,不知道为啥
在imageview里面可以显示,但是保存成图片不行,为啥呢
这个参数怎么可能是100呢?是100就表示图片全没啦。
参数改为0,表示图片没有压缩,是100%
参数改为30,表示图片压缩到原来的70%
楼主参数是100,则表示图片压缩到原来的0%, 图片当然 没有啦。
1 没有任何数据写入到图片中
2 图片数据写入编码与读取编码不一致
qrCodeBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);中的100指图片的质量,并非缩放比,android API对此描述如下:
quality Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality. Some formats, like PNG which is lossless, will ignore the quality setting
有可能是你说的编码不一致的问题,怎么解决呢? 在imageView 显示的正常保存本低有问题
public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException {
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix matrix = new MultiFormatWriter().encode(str,
BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (matrix.get(x, y)) {
pixels[y * width + x] = BLACK;
}else{
pixels[y * width + x] = WHITE;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
代码中 pixels[y * width + x] = WHITE;
这段嗲吗是我自己后加上的,加上之后就能显示了,谢谢楼上各位朋友的好心帮助,