0

I generate Qr Code ( Bitmap ) on my app And I want download this to my gallery . How Can I download bitmap ( qr code ) to my gallery .

                olustur.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bitmap imageResult = stringToBitmap(texttt.getText().toString());
                        qrcard.setVisibility(View.VISIBLE);
                        qrcodex.setImageBitmap(imageResult);
                        // I did genarate qr code in there
                    }
                });
            }
    @Override
    public void onClick(View view) {
        Intent i;
        switch (view.getId()) {         
            case R.id.qrindir:
                //I want Download Bitmap in there .
                break;          
    private Bitmap stringToBitmap(String content){
        try {
            QRCodeWriter writer = new QRCodeWriter();
            BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512);
            int width = bitMatrix.getWidth();
            int height = bitMatrix.getHeight();
            Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
                    bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
                }
            }
            return bmp;
        } catch (WriterException e) {
            e.printStackTrace();
            return null;
        }
    }

}

I generate Qr Code with Bitmap stringToBitmap

I did set Image to image view with Bitmap imageResult = stringToBitmap(texttt.getText().toString() ; qrcodex.setImageBitmap(imageResult);

OgiDev
  • 1
  • 1

1 Answers1

0

You can create a file from bitmap and save it to Gallery:

  1. How to generate file from bitmap - describes how to generate a file from bitmap in memory;
  2. For working with Gallery you need to save a photo to external storage. You can read more this.
fartem
  • 2,361
  • 2
  • 8
  • 20