android bit地图 生成图片全黑 哪位高手能告诉小弟我为啥呢
android bitmap 生成图片全黑 谁能告诉我为啥呢?
如题,用的是二维码生成,在ImageView里面看的时候是正常的,然后保存到本地,是就黑色的,
保存代码如下
------解决方案--------------------
黑的说明没有数据,你改下压缩格式看看
------解决方案--------------------
Bitmap里没有数据就是黑的
楼主再仔细看看代码
------解决方案--------------------
qrCodeBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
这个参数怎么可能是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里面看的时候是正常的,然后保存到本地,是就黑色的,
保存代码如下
String file_name = VeDate.getNo(5) + ".png";
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File file = new File(path, file_name);
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
qrCodeBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
------解决方案--------------------
黑的说明没有数据,你改下压缩格式看看
------解决方案--------------------
Bitmap里没有数据就是黑的
楼主再仔细看看代码
------解决方案--------------------
qrCodeBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
这个参数怎么可能是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