@SuppressLint("InflateParams") private MyQrodeDialog(Context context, int defStyle) { super(context, defStyle); View contentView = getLayoutInflater().inflate(R.layout.dialog_my_qr_code, null); mIvCode = (ImageView) contentView.findViewById(R.id.iv_qr_code); try { bitmap = QrCodeUtils.Create2DCode( String.format("http://my.oschina.net/u/%s", AppContext.getInstance().getLoginUid())); mIvCode.setImageBitmap(bitmap); } catch (WriterException e) { e.printStackTrace(); } requestWindowFeature(Window.FEATURE_NO_TITLE); contentView.setOnLongClickListener( new OnLongClickListener() { @Override public boolean onLongClick(View v) { dismiss(); if (FileUtils.bitmapToFile( bitmap, FileUtils.getSavePath("OSChina") + "/myqrcode.png")) { AppContext.showToast("二维码已保存到oschina文件夹下"); } else { AppContext.showToast("SD卡不可写,二维码保存失败"); } return false; } }); super.setContentView(contentView); }
public static Bitmap getMinimalQRCodeBitmap(String url) { Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); hints.put(EncodeHintType.MARGIN, 5); try { final BitMatrix result = new QRCodeWriter().encode(url, BarcodeFormat.QR_CODE, 0, 0, hints); final int width = result.getWidth(); final int height = result.getHeight(); final int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { final int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE; } } final Bitmap smallBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); smallBitmap.setPixels(pixels, 0, width, 0, 0, width, height); return smallBitmap; } catch (final WriterException x) { x.printStackTrace(); return null; } }
private void generateQR(String userKey) { String qrData = "tox://" + userKey; int qrCodeSize = 400; QRCodeEncode qrCodeEncoder = new QRCodeEncode( qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeSize); FileOutputStream out; try { Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); out = new FileOutputStream( Environment.getExternalStorageDirectory().getPath() + "/Antox/" + friendName + ".png"); bitmap.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); } catch (WriterException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public Ticket(String name, Double cena) { this.name = name; this.cena = cena; SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); Date aktDate = new Date(); aktDate.setHours(aktDate.getHours() - 2); aktDate.setMinutes(aktDate.getMinutes() - 15); this.zakupiony = sdf.format(aktDate); Date waznyDo = aktDate; waznyDo.setHours(waznyDo.getHours() + 24); this.wazny = sdf.format(waznyDo); Random r = new Random(); this.nrKontrolny = this.nrKontrolny + String.format("%03d%n", r.nextInt(999)).trim(); this.nrTrn = this.nrTrn + this.nrTrnMod + String.format("%03d%n", r.nextInt(999)).trim(); this.url = this.url + getNrTrn(); /* utworzenie QR Code i konwersja do bitmapy */ QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(url, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), 600); try { this.bitmap = qrCodeEncoder.encodeAsBitmap(); } catch (WriterException e) { e.printStackTrace(); } }
// 要转换的地址或字符串,可以是中文 public void createQRImage(String url) { try { // 判断URL合法性 if (url == null || "".equals(url) || url.length() < 1) { return; } Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); // 图像数据转换,使用了矩阵转换 BitMatrix bitMatrix = new QRCodeWriter().encode(url, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints); int[] pixels = new int[QR_WIDTH * QR_HEIGHT]; // 下面这里按照二维码的算法,逐个生成二维码的图片, // 两个for循环是图片横列扫描的结果 for (int y = 0; y < QR_HEIGHT; y++) { for (int x = 0; x < QR_WIDTH; x++) { if (bitMatrix.get(x, y)) { pixels[y * QR_WIDTH + x] = 0xff000000; } else { pixels[y * QR_WIDTH + x] = 0xffffffff; } } } // 生成二维码图片的格式,使用ARGB_8888 Bitmap bitmap = Bitmap.createBitmap(QR_WIDTH, QR_HEIGHT, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, QR_WIDTH, 0, 0, QR_WIDTH, QR_HEIGHT); // 显示到一个ImageView上面 sweepIV.setImageBitmap(bitmap); } catch (WriterException e) { e.printStackTrace(); } }
public final void exportDiagram( OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormatOption) throws IOException { List<BufferedImage> flashcodes = null; try { if ("split".equalsIgnoreCase(getSkinParam().getValue("flashcode")) && fileFormatOption.getFileFormat() == FileFormat.PNG) { final String s = getSource().getPlainString(); flashcodes = exportSplitCompress(s); } else if ("compress".equalsIgnoreCase(getSkinParam().getValue("flashcode")) && fileFormatOption.getFileFormat() == FileFormat.PNG) { final String s = getSource().getPlainString(); flashcodes = exportFlashcodeCompress(s); } else if (getSkinParam().getValue("flashcode") != null && fileFormatOption.getFileFormat() == FileFormat.PNG) { final String s = getSource().getPlainString(); flashcodes = exportFlashcodeSimple(s); } } catch (WriterException e) { Log.error("Cannot generate flashcode"); e.printStackTrace(); flashcodes = null; } if (fileFormatOption.getFileFormat() == FileFormat.PDF) { exportDiagramInternalPdf(os, cmap, index, flashcodes); return; } if (fileFormatOption.getFileFormat() == FileFormat.MJPEG) { // exportDiagramInternalMjpeg(os); // return;* throw new UnsupportedOperationException(); } lastInfo = exportDiagramInternal(os, cmap, index, fileFormatOption, flashcodes); }
private Bitmap createBitmap(String content, final int size) { final Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); hints.put(EncodeHintType.MARGIN, 0); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); BitMatrix result; try { result = sQRCodeWriter.encode(content, BarcodeFormat.QR_CODE, size, size, hints); } catch (WriterException ex) { mLogger.warn("qr encoder failed: " + ex.toString()); return null; } final int width = result.getWidth(); final int height = result.getHeight(); final int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { final int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.TRANSPARENT; } } final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_get, container, false); // set qr ImageView imageView = (ImageView) rootView.findViewById(R.id.qrcode_show); String qrData = User.adresse + "-=" + "0"; int qrCodeDimention = 500; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder( qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention); int color1 = Color.parseColor("#000000"); int color2 = Color.parseColor("#951F40"); try { Bitmap bm = replaceColor(qrCodeEncoder.encodeAsBitmap(), color1, color2); imageView.setImageBitmap(bm); } catch (WriterException e) { e.printStackTrace(); } // try { // Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); // imageView.setImageBitmap(bitmap); // } catch (WriterException e) { // e.printStackTrace(); // } // Button Button gen = (Button) rootView.findViewById(R.id.Button_gen); gen.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { updateQR(); } }); EditText etb = (EditText) rootView.findViewById(R.id.betrag_et); etb.clearComposingText(); etb.setHint("0.00"); // button // Button cb = (Button) rootView.findViewById(R.id.Button_betrag); // cb.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // updateDetail(); // } // }); return rootView; }
public void updateQR() { View v = getView(); DecimalFormat f = new DecimalFormat("#0.00"); EditText etb = (EditText) v.findViewById(R.id.betrag_et); TextView btv = (TextView) v.findViewById(R.id.hint_tv); String value = "0.00"; value = etb.getText().toString(); ImageView imageView = (ImageView) getView().findViewById(R.id.qrcode_show); String qrData = User.adresse + "-=" + value; double c = 0.0; c = Double.valueOf(value); String showv = (f.format(c) + " €"); if (!(c == 0)) { // btv.setText(value + " €"); btv.setText(showv); } else { btv.setText("Der Zahlende kann nun den Betrag angeben."); } int qrCodeDimention = 500; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder( qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention); int color1 = Color.parseColor("#000000"); int color2 = Color.parseColor("#951F40"); try { Bitmap bm = replaceColor(qrCodeEncoder.encodeAsBitmap(), color1, color2); imageView.setImageBitmap(bm); } catch (WriterException e) { e.printStackTrace(); } SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date myDate = new Date(); User.guthaben += c; Transactions.sum[Transactions.i] = String.valueOf(c); Transactions.adresse[Transactions.i] = "no adress"; Transactions.date[Transactions.i] = sdf.format(myDate.getTime()); Transactions.i = Transactions.i + 1; // try { // Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); // imageView.setImageBitmap(bitmap); // } catch (WriterException e) { // e.printStackTrace(); // } }
/** * 根据内容生成二维码数据 * * @param content 二维码文字内容[为了信息安全性,一般都要先进行数据加密] * @param width 二维码照片宽度 * @param height 二维码照片高度 * @return */ public static BitMatrix createQRCode(String content, int width, int height) { Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); // 设置字符编码 hints.put(EncodeHintType.CHARACTER_SET, ToolString.encoding); // 指定纠错等级 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); BitMatrix matrix = null; try { matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); } catch (WriterException e) { e.printStackTrace(); } return matrix; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_signature); byte[] signature = getIntent().getByteArrayExtra(EXTRA_SIGNATURE); String signatureString = new BigInteger(signature).toString(); ImageView qrImageView = (ImageView) findViewById(R.id.qr_imageView); try { qrImageView.setImageBitmap(generateQRCodeBitmap(signatureString)); } catch (WriterException e) { e.printStackTrace(); } }
public static int[] generateQR(String text, int dimension) { QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix matrix = null; try { matrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, dimension, dimension); } catch (WriterException e) { e.printStackTrace(); } int[] pixels = new int[dimension * dimension]; for (int y = 0; y < dimension; y++) { int offset = y * dimension; for (int x = 0; x < dimension; x++) { if (matrix.get(x, y)) pixels[offset + x] = Color.BLACK; else pixels[offset + x] = Color.WHITE; } } return pixels; }
/** @param args */ public static void main(String[] args) { Charset charset = Charset.forName("UTF-8"); CharsetEncoder encoder = charset.newEncoder(); byte[] b = null; try { // Convert a string to UTF-8 bytes in a ByteBuffer ByteBuffer bbuf = encoder.encode(CharBuffer.wrap("http://www.google.co.in/")); b = bbuf.array(); } catch (CharacterCodingException e) { System.out.println(e.getMessage()); } String data; try { data = new String(b, "UTF-8"); // get a byte matrix for the data BitMatrix matrix = null; ByteMatrix byteMatrix = null; int h = 100; int w = 100; com.google.zxing.Writer writer = new MultiFormatWriter(); try { Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); matrix = writer.encode(data, com.google.zxing.BarcodeFormat.QR_CODE, w, h, hints); } catch (com.google.zxing.WriterException e) { System.out.println(e.getMessage()); } // change this path to match yours (this is my mac home folder, you can use: c:\\qr_png.png if // you are on windows) String filePath = "D:\\CreateQR.JPG"; File file = new File(filePath); try { MatrixToImageWriter.writeToFile(matrix, "JPG", file); System.out.println("printing to " + file.getAbsolutePath()); } catch (IOException e) { System.out.println(e.getMessage()); } } catch (UnsupportedEncodingException e) { System.out.println(e.getMessage()); } }
// 生成QR图 private void createImage() { try { // 需要引入core包 QRCodeWriter writer = new QRCodeWriter(); String text = RQcode; Log.i(TAG, "生成的文本:" + text); if (text == null || "".equals(text) || text.length() < 1) { return; } // 把输入的文本转为二维码 BitMatrix martix = writer.encode(text, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT); System.out.println("w:" + martix.getWidth() + "h:" + martix.getHeight()); Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints); int[] pixels = new int[QR_WIDTH * QR_HEIGHT]; for (int y = 0; y < QR_HEIGHT; y++) { for (int x = 0; x < QR_WIDTH; x++) { if (bitMatrix.get(x, y)) { pixels[y * QR_WIDTH + x] = 0xff000000; } else { pixels[y * QR_WIDTH + x] = 0xffffffff; } } } barcodeBitmap = Bitmap.createBitmap(QR_WIDTH, QR_HEIGHT, Bitmap.Config.ARGB_8888); barcodeBitmap.setPixels(pixels, 0, QR_WIDTH, 0, 0, QR_WIDTH, QR_HEIGHT); imgOutput.setImageBitmap(barcodeBitmap); } catch (WriterException e) { e.printStackTrace(); } }
@SuppressLint("InflateParams") private MyQRCodeDialog(Context context, int defStyle) { super(context, defStyle); View contentView = getLayoutInflater().inflate(R.layout.dialog_my_qr_code, null); mIvCode = (ImageView) contentView.findViewById(R.id.iv_qr_code); try { bitmap = QrCodeUtil.Create2DCode( String.format("http://me.yuedong.com/u/%s", AppContext.getContext().getLoginUid())); mIvCode.setImageBitmap(bitmap); } catch (WriterException e) { e.printStackTrace(); } requestWindowFeature(Window.FEATURE_NO_TITLE); mIvCode.setOnLongClickListener( new OnLongClickListener() { @Override public boolean onLongClick(View v) { dismiss(); if (FileUtils.bitmapToFile( bitmap, FileUtils.getSavePath("Yuedong") + "/my_qr_code.png")) { ToastUtil.toast("二维码已保存到 Yuedong 文件夹下"); } else { ToastUtil.toast("SD卡写入错误,二维码保存失败"); } return false; } }); contentView.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { MyQRCodeDialog.this.dismiss(); return false; } }); super.setContentView(contentView); }
/** * Encode. * * @param text the text to encode * @return the image */ public Image encode(String text) { // Encode the text QRCode qrcode = new QRCode(); try { Encoder.encode(text, ErrorCorrectionLevel.H, qrcode); } catch (WriterException e) { e.printStackTrace(); } byte[][] matrix = qrcode.getMatrix().getArray(); int size = qrcode.getMatrixWidth() * scale; // Make the BufferedImage that are to hold the QRCode BufferedImage im = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); im.createGraphics(); Graphics2D g = (Graphics2D) im.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, size, size); // BitMatrix for validation BitMatrix bm = new BitMatrix(qrcode.getMatrixWidth()); // paint the image using the ByteMatrik for (int h = 0; h < qrcode.getMatrixWidth(); h++) { for (int w = 0; w < qrcode.getMatrixWidth(); w++) { // Find the colour of the dot if (matrix[h][w] == 0) g.setColor(Color.WHITE); else { g.setColor(Color.BLACK); bm.set(w, h); // build the BitMatrix } // Paint the dot g.fillRect(w * scale, h * scale, scale, scale); } } return im; }
@Override protected void afterViews() { txvNomeEvento.setText("Bruno e Barreto"); txvDataEvento.setText(TreatDate.formatString("dd/MM/yyyy", new Date())); txvLocalEvento.setText("Santarena"); // ImageView to display the QR code in. This should be defined in // your Activity's XML layout file ImageView imageView = (ImageView) findViewById(R.id.img_qrcode); String qrData = "Data I want to encode in QR code"; int qrCodeDimention = 500; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder( qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention); try { Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); imageView.setImageBitmap(bitmap); } catch (WriterException e) { e.printStackTrace(); } }
private static Bitmap getQRCodeBitmap( String url, int size, int margin, Hashtable<EncodeHintType, Object> hints) { try { final BitMatrix result = new QRCodeWriter().encode(url, BarcodeFormat.QR_CODE, 0, 0, hints); final int width = result.getWidth(); final int height = result.getHeight(); final int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { final int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE; } } final Bitmap smallBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); smallBitmap.setPixels(pixels, 0, width, 0, 0, width, height); Bitmap largeBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(largeBitmap); Paint p = new Paint(); p.setDither(false); p.setAntiAlias(false); Rect src = new Rect(0, 0, smallBitmap.getWidth(), smallBitmap.getHeight()); Rect dst = new Rect( margin, margin, largeBitmap.getWidth() - margin, largeBitmap.getHeight() - margin); canvas.drawColor(0xFFFFFFFF); canvas.drawBitmap(smallBitmap, src, dst, p); return largeBitmap; } catch (final WriterException x) { x.printStackTrace(); return null; } }
/** * Generate a QR code with the payment information of a given size, optionally, with branding * * @param size A size of the QR code (without the branding) in pixels * @param paymentString A SPAYD string with payment information * @param hasBranging A flag that can be used to turn on/off branding * @return An image with the payment QR code * @throws IOException */ public static BufferedImage getQRCode(Integer size, String paymentString, boolean hasBranging) throws IOException { if (size == null) { size = SpaydConstants.defQRSize; } else if (size < SpaydConstants.minQRSize) { size = SpaydConstants.minQRSize; } else if (size > SpaydConstants.maxQRSize) { size = SpaydConstants.maxQRSize; } BitMatrix matrix = null; int h = size; int w = size; int barsize = -1; Writer writer = new MultiFormatWriter(); try { Map<EncodeHintType, Object> hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class); hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1"); QRCode code = Encoder.encode(paymentString, ErrorCorrectionLevel.M, hints); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); barsize = size / (code.getMatrix().getWidth() + 8); matrix = writer.encode(paymentString, com.google.zxing.BarcodeFormat.QR_CODE, w, h, hints); } catch (com.google.zxing.WriterException e) { System.out.println(e.getMessage()); } if (matrix == null || barsize < 0) { throw new InvalidFormatException(); } BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix); if (hasBranging) { Graphics2D g = (Graphics2D) image.getGraphics(); BasicStroke bs = new BasicStroke(2); g.setStroke(bs); g.setColor(Color.BLACK); g.drawLine(0, 0, w, 0); g.drawLine(0, 0, 0, h); g.drawLine(w, 0, w, h); g.drawLine(0, h, w, h); String str = "QR Platba"; int fontSize = size / 12; g.setFont(new Font("Verdana", Font.BOLD, fontSize)); FontMetrics fm = g.getFontMetrics(); Rectangle2D rect = fm.getStringBounds(str, g); g.setColor(Color.WHITE); g.fillRect( 2 * barsize, h - fm.getAscent(), (int) rect.getWidth() + 4 * barsize, (int) rect.getHeight()); int padding = 4 * barsize; BufferedImage paddedImage = new BufferedImage(w + 2 * padding, h + padding + (int) rect.getHeight(), image.getType()); Graphics2D g2 = paddedImage.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); g2.setFont(new Font("Verdana", Font.BOLD, fontSize)); g2.setPaint(Color.WHITE); g2.fillRect(0, 0, paddedImage.getWidth(), paddedImage.getHeight()); g2.drawImage(image, padding, padding, Color.WHITE, null); g2.setColor(Color.BLACK); g2.drawString(str, padding + 4 * barsize, (int) (padding + h + rect.getHeight() - barsize)); image = paddedImage; } return image; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.qr_created); save = (Button) findViewById(R.id.save); imageView = (ImageView) findViewById(R.id.show_qr); Intent i = getIntent(); String data = i.getStringExtra("Info"); try { Bitmap bitmap = encodeAsBitmap(data); imageView.setImageBitmap(bitmap); } catch (WriterException e) { e.printStackTrace(); } save.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(CreateQR.this); builder.setTitle("Dosya Adı"); final EditText input = new EditText(CreateQR.this); input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); builder.setView(input); builder.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { name = input.getText().toString(); imageView.buildDrawingCache(); Bitmap bm = imageView.getDrawingCache(); OutputStream fOut = null; Uri outputFileUri; try { File root = new File( Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "Easy Estate"); root.mkdirs(); File sdImageMainDirectory = new File(root, name + ".jpg"); outputFileUri = Uri.fromFile(sdImageMainDirectory); fOut = new FileOutputStream(sdImageMainDirectory); } catch (Exception e) { Toast.makeText( CreateQR.this, "Bir hata oldu. " + e.getMessage(), Toast.LENGTH_LONG) .show(); Log.e("KAYDET", e.getMessage()); } try { bm.compress(Bitmap.CompressFormat.PNG, 100, fOut); Toast.makeText(CreateQR.this, "Kaydedildi", Toast.LENGTH_SHORT).show(); fOut.flush(); fOut.close(); } catch (Exception e) { } } }); builder.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.show(); } }); }