解决方案 »
- 导入csv或其他数据文件到sqlite的问题。
- android aidl 求解释!
- 新手开发遇到提示有错误,但无法定位到错误
- monkey 求助
- 紧急:有关屏幕响应事件?谢谢!
- viewpager切换fragment的问题
- eclipse中安装ADT插件
- 第一个Andorid——HelloWorld出现错误
- Android行车记录仪软件后台录像,二十四小时不间断循环录像,欢迎大家捧场
- cannot cast 'android.view.View' to 'com.easybooks.android.text.Spinner'
- 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;
这段嗲吗是我自己后加上的,加上之后就能显示了,谢谢楼上各位朋友的好心帮助,