SVG image not display - android

i have converted a psd file into svg, it works good at browser but not works on android native applications, how can i do this?
ImageView imageView = (ImageView)findViewById(R.id.img1);
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
//Parse the SVG file from the resource
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
//Get a drawable from the parsed SVG and apply to ImageView
imageView.setImageDrawable(svg.createPictureDrawable());
This is the code i used to display svg image. it works when i used simple svg images, but it not works converted svg images using illustrator . how can i do?

I am guessing that your SVG just contains the image from the PSD. Is that the case?
If all that the SVG contains is a bitmap image, then you are not really using SVGs for their proper purpose (vector art). You would be better off just converting the PSD to a JPEG or PNG and loading that into an ImageView.
However, if you are definitely sure you want to load an SVG, then the solution depends on which SVG library you are using.
svg-android: As far as I know, it doesn't support <image> elements, so there is no solution
AndroidSVG: supports <image>, so it should work as long as the device has the memory to load the image. If the image is embedded in the file, you should be fine. If it references an external image, you will need to pass in an SVGExternalFileResolver so it knows how to find the bitmap. See my answer to the following question: https://stackoverflow.com/a/21531168/1292848

Related

Adding SVG images from assets folder in adapter

I want to load SVG in ImageView from Gridview Adapter,
i do this:
imageView.setImageURI(Uri.parse("file:///android_asset/ico/s.svg"));
but not work and dont show anything
I want to load SVG in ImageView from Gridview Adapter, i do this:
First, ImageView does not support SVG directly.
Second, your code appears to be loading a PNG file, not an SVG file.
Third, file:///android_asset/ is for WebView. It does not work elsewhere in the Android SDK.
You should consider switching to using Glide as an image-loader. It handles file:///android_asset/ and has sample code for transcoding SVG files. Plus, it does the image-loading work on a background thread.
Otherwise, you can use AssetManager and its open() method to get an InputStream on an asset. If that asset is a PNG, JPEG, or WebP file, you can use BitmapFactory.decodeStream() to read in the stream and give you a Bitmap back that you can use for the ImageView. You would need a third-party library to do something with an SVG asset. And, you need to arrange to do this work on a background thread, as otherwise your UI will freeze and cause users to think that your app is stuck.

How do I render an SVG in an Android app?

After finding Display SVG Image in image view in android on Google and going to Having issue on Real Device using vector image in android. SVG-android, I find that "You need a 3rd-party JAR to do it" is a bit of overkill. Is there any way to render an SVG without using 3rd-party libraries?
I managed to display an SVG using a WebView, since that is more than capable of rendering an SVG:
webView.loadUrl("file:///android_res/drawable/file.svg"); // point it to the SVG
webView.setBackgroundColor(0x00000000); // set the background to transparent
This makes it render much like a transparent PNG would in an ImageView. The only caveat is that the SVG must use the viewBox attribute and not use the height or width attributes, to ensure it resizes properly.
Using custom fonts actually works really well in Android.
You can use the free icomoon web application to convert SVGs to custom .ttf font characters.
If you are using it for imagePicker sort of feature then,
webView.loadURl(selectedFileLocation.toString)
else if it is to display a .svg image from web,
webView.loadURl(/*url for the .svg file*/)

converted SVG is not displaying in android canvas

I have eps image files. i have converted to .svg by online converter nut now this converted svg is not getting displayed on the screen. (Code works with other original svg image).
Is there something like we can not use converted svg images in android apps?
Here is my code:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view = new GestureImageView(this);
svgImg=sVGParser.getSVGFromResource(getResources(),R.raw.american);
view.setImageDrawable(svgImg.createPictureDrawable());
view.setLayoutParams(params);
view.setMaxScale(15f);
ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
layout.addView(view);
}
More than likely the problem is with the SVG generated by the online converter you used.
It appears as if you are using svg-android. You might have more success with AndroidSVG which supports more of the SVG spec.
I would personally suggest you not to use SVG as Android does not support SVG rasterization, you may like to read more discussion here.
but if you really got stick with svg then here are some useful solutions may help you.
Scaling SVGs in Android
Is there any lite SVG viewer for Android
svg image files android
Here are some beautiful tutorials for display SVG in android
Android ImageView and Drawable with SVG Support
Android. ImageView with SVG Support
I could have created a sample code for this but I am in Xcode now.

Android transparent images copied to gallery obtain solid black background

I use the following statement to copy an image from the assets to the gallery app, which works fine:
MediaStore.Images.Media.insertImage(getContentResolver(), myBitmap, myTitle , myDescription);
The images are png-files with a transparent background. They are displayed correctly when I load them from the assets to, for example an ImageView.
The problem is, that the formerly transparent background of the imported images became solid black in the gallery.
The png is a png24 created by gimp. I also tried a transparent gif and a png with transparency added by Apple's preview application with the same result.
Why it happens?
I know this is an old question but I just had the same problem. The problem is that MediaStore.Images.Media.insertImage stores the file with a MIME_TYPE of "image/jpeg", and jpeg doesn't support transparency.
One solution is to make your own content provider that uses another image format. The Picasso image library might be worth a look too.

Is it possible to display svgz on Android?

is there a simple way to display SVGZ images within an Android app. I know that there are a few libraries to display SVG images. But they do not support SVGZ as far as I know.
In case that there is no library that can display SVGZ images, is it possible to unzip the file with java.util.zip?
Yes it should be possible to extract the svg file and visualize it with a small lib called svg-android.
Small Example:
GZIPInputStream is=/*...*/;
PictureDrawable img = SVGParser.getSVGFromInputStream(is, 0, 0)
.createPictureDrawable();
Try this fork of svg-android.
It detects svgz automatically, so you can do directly
SVGParser.getSVGFromResource(getResources(), R.raw.mysvgz);
and it is more compatible with the svg definition. In other words, the original version of svg-android can not view many svgs due to lacks of some features.

Categories

Resources