0

I'm using AndroidSVG to dynamically place a signature rendered as an svg, for displaying to an ImageView.

Here is my code:

SVG svg = SVG.getFromString(singleEmployee.signature);
ImageView image_view = (ImageView) layout_signature.findViewById(R.id.toolboxtalk_signature_svg);
image_view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
image_view.setTag(String.format(Locale.US, "employee_signature%d", x));
Drawable drawable = new PictureDrawable(svg.renderToPicture());
image_view.setImageDrawable(drawable);

My question is, how do I get the SVG out of the ImageView later in my code execution.

Here is what I'm trying:

ViewGroup v1 = (ViewGroup) findViewById(R.id.job_ticket_form);
ImageView signatureImageView = (ImageView) v1.findViewWithTag("employee_signature1");
PictureDrawable pictureDrawable = (PictureDrawable) signatureImageView.getDrawable();
Picture picture = pictureDrawable.getPicture();
Context context = signatureImageView.getContext();
String employeeSigSVGString = null;
try {
      SVG svg = SVG.getFromResource(signatureImageView.getContext(), R.id.toolboxtalk_signature_svg);
      employeeSigSVGString = spinner_value + "|" + svg;
} catch (SVGParseException e) {
      e.printStackTrace();
}

Any ideas how to get the SVG back out of the ImageView?

  • 3
    you can't. the svg was rendered into a drawable, which cannot be transformed back into an svg. You have to use teh `singleEmployee.signature` field, as it already contains the value you seek – njzk2 May 16 '17 at 16:07
  • @njzk2 Thanks! I was hoping for a clean method to extract the svg from the drawable, but what you suggest works. – David Davis Jr. May 16 '17 at 16:18

0 Answers0