求教,Zxing条码生成转bmp文件 bmp图片bitmap转bmp图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ----------------------------根据输入字符串生成图片public final class EncodingHandler { private static final int BLACK = 0xff000000; 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; } } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }---------------保存你的bitmap/** 保存方法 */ public void saveBitmap() { Log.e(TAG, "保存图片"); File f = new File("/sdcard/namecard/", picName); if (f.exists()) { f.delete(); } try { FileOutputStream out = new FileOutputStream(f); //bm 就是你的bitmap 图对象,用输出流 bm.compress(Bitmap.CompressFormat.PNG, 90, out); out.flush(); out.close(); Log.i(TAG, "已经保存"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }-----------------------------------------------兄弟已经放到了嘴边,最近 都没有分数了。给分了。记得! 在这里还需要两个权限: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> 谷歌map密钥申请 请问安卓平台开发应用,一般使用什么语言做开发工具? android ActivityGoup加载WebView,WebView显示Flash显示一半 请问在recevier的onReceve里面不能打Log和debug么? 我是小白 再发NDK版本问题 求指教 这个点击两次返回键退出的程序的错误问题 判断activity是否存在 文卓爷模拟器与bluestacks安卓模拟器的优势 WebView加载html 开发手机APP时如何做到历史数据展示? ImageView自适应高度 线等....最近做XMPP-openfire
public final class EncodingHandler {
private static final int BLACK = 0xff000000;
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;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
---------------保存你的bitmap
/** 保存方法 */
public void saveBitmap() {
Log.e(TAG, "保存图片");
File f = new File("/sdcard/namecard/", picName);
if (f.exists()) {
f.delete();
}
try {
FileOutputStream out = new FileOutputStream(f);
//bm 就是你的bitmap 图对象,用输出流
bm.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
Log.i(TAG, "已经保存");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
-----------------------------------------------
兄弟已经放到了嘴边,最近 都没有分数了。给分了。记得!
在这里还需要两个权限: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>