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.
Related
I'm developing a music Player, and since i have started I've a question: Should i use Drawable or Bitmap?
Considered that:
I have to load many images, one for every song (The image is loaded only when it is the turn of that song).
The image loaded has to be visualized on the Widget and Notification too.
The same image is displayed on more activities.
The image loading has to be as fast as possible.
The memory usage have to be as low as possible, even after have loaded several images.
I was thinking to temporarly save images of actual playlist, so I don't have to reload it every time is played the same song.
I am using Glide library to have better performance in this moment, and I am working with bitmap. Any suggestion?
Both graphics objects works almost everywhere.
If you loading from file system (downloads) you need to load Bitmaps to create BitmapDrawables so you may apply bitmap directly in this case.
If you are using from the res folder you can load as Drawables.
Drawable is just a wrapper for things that can be drown (colors, vector images, layer-lists, selectors and bitmaps).
Whereas bitmaps are actually representation of images in Android.
So, your question is invalid, we can not equate bitmap and Drawable.
I would like to create fragment with image as background. What I do is saving image in .png format, putting it to drawable folder and than using it as background in layout. First thing I noticed is that the view stutters, so I created different images for different densities. But I'm still afraid that in older devices with worser CPU view would statter.
Question
Do I have to use libraries like Picasso for adding images as background ? What is the best approach ?
I think that base approach of using libraries like Picasso, Glide, UniversalImageLoader is for downloading images from network, caching, decoding, smooth loading in runtime.
If you want just set background for imageView from your local resources the only thing you should consider is to do this efficiently. This is nice described by google here and should be enough for your case.
This is a different situation. I want to load a image file which has stored with different extension like 'photo.xyz' instead of 'photo.jpg or photo.png' using Picasso. to avoid image from gallery i am storing image like this. Please help me is there any option to show like this.
Neither Picasso nor Android (which does the actual image decoding) cares what the file name is. It can be anything. The type of the image is always determined from the first few bytes of the actual image data.
As a small workaround you can programmatically put .nomedia file into your app folder to prevent images to be cached by mediaserver and displayed in a Gallery app.
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
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.