When i inflate SVG into ImageView, it appears blurred on pre-lollipop devices whereas it is working fine on Lollipop or later devices. I don't want to use third party libraries to process svg and inflate it into ImageView. Please help.
Asked
Active
Viewed 719 times
1
-
This seems like if the SVG scaling happened **after** the vector has been converted to a Bitmap... – Phantômaxx Dec 28 '15 at 11:00
-
@FrankN.Stein how to fix the issue. Can you please help? – Malwinder Singh Dec 28 '15 at 11:01
-
OK. Given that I'm using the `applantation` variant of `svg-android`, it's a 2 step process: get tge Drawable from the SVG (imposing the dimension in px - so a previous calculation is done to determine the appropriate size for the device's density), then convert the Drawable to a Bitmap to be assigned to an ImageView (or whichever View). – Phantômaxx Dec 28 '15 at 11:13
-
@ Frank N. Stein -- the OP is using lollipop which supports SVG unlike previous versions so no need to convert to PNG. – Tasos Dec 28 '15 at 11:16
-
Add your code in your Q. and check here for the documentation -- https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html – Tasos Dec 28 '15 at 11:17
-
@Tasos: please re-read the question title: `SVG Blur on pre Lollipop devices` – Phantômaxx Dec 28 '15 at 11:18
-
@ Frank N. Stein -- ahh sorry, cool – Tasos Dec 28 '15 at 11:19
-
@FrankN.Stein can you please post answer below? Thanks buddy! – Malwinder Singh Dec 28 '15 at 11:22
-
@Tasos also keep in mind that SVG != VectorDrawable. VectorDrawables only use a **subset** of the SVG structure. – Phantômaxx Dec 28 '15 at 11:26
-
It would be broad. But I'm sure you got the concept: **1** - get the SVG properly dimensioned. **2** - convert it into a Bitmap and use it. – Phantômaxx Dec 28 '15 at 11:28
-
it will be easier if you view the svg in a browser and take a snapshot in PNG and use it as a drawable for pre lollipop devices. Or use a paint package to save it for multiple resolutions and put them in the res folder for different pixel densities – Tasos Dec 28 '15 at 11:34
-
@Tasos thanks but i do not want to use png unless they are very much required. I use SVGs as much as i can. – Malwinder Singh Dec 28 '15 at 11:36
-
@FrankN.Stein Can you please tell how to get SVG properly dimensioned and how to convert it to bitmap? – Malwinder Singh Dec 28 '15 at 11:40
-
This should be explained in your library documentation. For the sizing, it's just a matter of reasoning in dp (what would be an appropriate dp value for your resolution/s?) then use the proper scale factor (for density buckets) and scale it to px (graphic operations are in px, unfortunately). This is for calculating the width and height while getting the svg into a Drawable. The conversion to Bitmap should be then trivial. – Phantômaxx Dec 28 '15 at 12:07
1 Answers
0
you need to add vectorDrawables.useSupportLibrary = true to your build.gradle file: :
///////////For Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
=========================================
///////////For Gradle Plugin 1.5
android {
defaultConfig {
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Check out this link for more info : http://android-developers.blogspot.in/2016/02/android-support-library-232.html

Shanki Bansal
- 1,681
- 2
- 22
- 32