Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale images to canvas? how to? #19

Closed
GoogleCodeExporter opened this issue Jul 24, 2015 · 3 comments
Closed

Scale images to canvas? how to? #19

GoogleCodeExporter opened this issue Jul 24, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

Hello and thank you for gread library!

I'm trying to use it in my app.
Idea is to use svg icons, and render them to bitmap cache objects to fit 
different screen resolutions.

Here is code example.

SVG svg = SVG.getFromResource(getActivity(), R.raw.avatar_default);
Bitmap mBitmap = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
Canvas c=new Canvas(mBitmap);
svg.renderToCanvas(c);
img.setImageBitmap(mBitmap);


by passing width, height I assume to scale svg to fit bitmap rectangle.

Here is example in attachment.
Selected picture is one from code above. How to scale svg to different size 
canvas? 
I also attach couple source pictures from grid on screenshot. As you see, when 
I'm trying to render svg with defaults 96x96 to 120x120 pixels Canvas\Bitmap 
I've got artefacts on picture...
I tried different scale modes on ImageViews but no luck :(

Original issue reported on code.google.com by swe...@gmail.com on 21 Oct 2013 at 11:52

Attachments:

@GoogleCodeExporter
Copy link
Author

Hi swexru

I'm glad you are finding the library useful.  Thanks.

The solution to your problem is the viewBox attribute.  It tells the renderer 
what the bounds of your picture content is, so it knows how to scale it.  
Inkscape doesn't add viewBox, so you either have to add them to the file 
yourself, or add a viewBox after it is loaded, but before you render to canvas.

See the FAQ for more info.  https://code.google.com/p/androidsvg/wiki/FAQ

In your case, adding the following lines should work for all or most of your 
files:

svg.setDocumentViewBox(0, 0, svg.getDocumentWidth(), svg.getDocumentHeight());
svg.setDocumentWidth("100%");
svg.setDocumentHeight("100%");

Original comment by paul.leb...@gmail.com on 22 Oct 2013 at 2:08

  • Changed state: Invalid

@GoogleCodeExporter
Copy link
Author

Thank you! Sorry for my blindness...

Original comment by swe...@gmail.com on 22 Oct 2013 at 7:58

@GoogleCodeExporter
Copy link
Author

No worries. You're welcome.

Original comment by paul.leb...@gmail.com on 23 Oct 2013 at 12:29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant