I want to load svg image in Android using Glide. In fact Glide support such job and I found a sample https://github.com/bumptech/glide/tree/v3.6.0/samples/svg/src/main/java/com/bumptech/svgsample/app. The question is that I want to directly load the image from a string which is in svg format, not from the svg file. The string is received from network or selected from sqlite. Can someone help me? I have searched a long time but it seems no one meet such requirement.
Your question is unclear. You haven't been that clear on what part you are stuck on.
If you just need to get an InputStream from a String, then you can do:
InputStream stream = new ByteArrayInputStream(svgString.getBytes(StandardCharsets.UTF_8));
Related
So the simple idea is that I have SVG data as a string that I fetch from Internet.
I would like to show that as an icon in my app. Is there any way I can do this?
I have seen countless examples where SVG data is in a file located in the app's directory that is then showed but this is not what I am looking for. I literally have the data in XML format after http request and I only need to transform that to a Image or something else visible on the screen.
I have been trying to find a solution to this for hours now, so I would really appreciate some help :S
Android doesn't support svg with ImageView directly,you could display SVG with some commonly used third-party controls.
Like FFImageLoading.
Add Xamarin.FFImageLoading.Svg nuget package to platform project. Use ImageService with svg data resolver for displaying svg images.
For Android:
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
then use like:
var svgString = #"<svg><rect width=""30"" height=""30"" style=""fill:blue"" /></svg>";
ImageView imageView = FindViewById<ImageView>(Resource.Id.image_view);
ImageService.Instance
.LoadString(svgString)
.LoadingPlaceholder(placeHolderPath)
.WithCustomDataResolver(new SvgDataResolver(64, 0, true))
.WithCustomLoadingPlaceholderDataResolver(new SvgDataResolver(64, 0, true))
.Into(imageView);
I am developing an application in which i am using Glide Library to load image from server. But Unfortunately this is not working and i am completely unaware about this and trying to solve this issue since last two days.
this is my code.
Glide.with(this).load(response.getBank_cash_deposit().getData().getAttributes().getAttachment()).into(mSelectedImage);
Try Log your image response. you're getting correct image URL or not.
If the image URL is correct then check whether there is space in your image URL or not.
If the space is exists then replace space in your URL String with %20 with the help of string.replace() function.
String image=response.getBank_cash_deposit().getData().getAttributes().getAttachment();
Log.d("Image",image);
if space exists
then
image.replace(" ","%20");
Also check image url on web.
A very strange behaviour, while writing code for showing GIF image in image-view.
what i am doing is
InputStream is = this.getResources().openRawResource(R.drawable.logo);
logo is gif image that is in the drawable folder.
when I write that line of code in Eclipse , image loads successfully but when I import that code on Android Studio What I am seeing is an error on R.drawable.logo
and the error is
Expected Resource of type raw
supplying the wrong type of resource identifier. For Example when calling Resources.getString(int id), You should be passing R.string.something not R.drawable.something
one code runs on Eclipse not on Android Studio
I am sure that no problem with the imports.
After doing some R&D i have found a work-around for that
and that is instead of creating drawable folder and put that image into it
create assets folder in main/src/assests and paste that image and then open Input steam.
InputStream is = context.getAssets().open("logo.gif");
that worked for me but sill dont know the answer why
InputStream is = this.getResources().openRawResource(R.drawable.logo);
was not working.
you can try using ion https://github.com/koush/ion#load-an-image-into-an-imageview is a nice library for load images and support gif from local store , resorces or from Url.
Simple solution is using Glide library
compile 'com.github.bumptech.glide:glide:4.3.1'
And Load your ImageView
Glide.with(YourActivity.this).load(R.drawable.your_gif).into(yourImageView);
I'm using picasso library to download images from URL.What I need is just download the stream not a bitmap, but there is no such method in it.Is it true?
There is :
Picasso.with(this).load(URL_LONG).get(); // return bitmap
Sometimes there are some large images from URL.I need to handle them before displaying for avoiding out of memory.So I cannot load them into bitmap immediately.This is the reason i need the stream.
There is already a feature to provide what you need in Picasso Library. You can actually scale the image when you stream it. Check out this SOF Question.
I have a quick question how to receive a jpg image from a web api call.
String result = webApiManager.getBarcode(dataStorageManager.currentUser.CustomerID);
This method returns a jpg image but I am unsure how to handle it and display it in an ImageView. Furthermore, what data type is a jpg image and how do I convert it into an image that I can display using an ImageView. Can someone point me in the right direction on how to accomplish this. Thanks for your time.
Regards,
Ryan
instead of returning the image as a jpg...why not just return the URL to the image and then use AsyncTask in processing it...
It will be easier and faster that way... just my 2cents