0

I am trying to generate a png file with a signature on it. so I want it to be transparent background, but all I could do is generate a signature with white background which is not the out put I want.

here is my code btw. incase I am missing something.

File file = new File(getExternalFilesDir(null), IndividualFragment.lastname.getText().toString().concat("_").concat(IndividualFragment.firstname.getText().toString()).concat("_sig") + ".png");
            FileOutputStream out = null;
            Bitmap bitmap = signatureView.getSignatureBitmap();
            try {
                out = new FileOutputStream(file);
                if (bitmap != null) {
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
                } else {
                    throw new FileNotFoundException();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (out != null) {
                        out.flush();
                        out.close();

                        if (bitmap != null) {
                            Toast.makeText(getApplicationContext(),
                                    "Image saved successfully at " + file.getPath(),
                                    Toast.LENGTH_LONG).show();
                            AttachmentsFragment.appPath.setText(file.getPath());
                            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
                                new MyMediaScanner(this, file);
                            } else {
                                ArrayList<String> toBeScanned = new ArrayList<String>();
                                toBeScanned.add(file.getAbsolutePath());
                                String[] toBeScannedStr = new String[toBeScanned.size()];
                                toBeScannedStr = toBeScanned.toArray(toBeScannedStr);
                                MediaScannerConnection.scanFile(this, toBeScannedStr, null,
                                        null);
                            }
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

Thanks in advance guys, your help is much appreciated.

Zain
  • 37,492
  • 7
  • 60
  • 84
JeffyO
  • 81
  • 10

1 Answers1

0

For future references.

Check this library. it helps me alot.

https://github.com/gcacace/android-signaturepad

JeffyO
  • 81
  • 10