How to convert ByteArray to Image in Xamarin forms [duplicate] - arrays

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);

Related

TipTap React Image Uploader with Placeholder

I am trying to build plug in the image extension (#tiptap/extension-image) to my tiptap editor, however the issue I find is with bigger images, there is no easy way to add a sort of placeholder image or text to tell the user the image is being uploaded.
The current flow is this:
const imageUrl = await doUpload();
editor.chain().focus().setImage({ src: imageUrl }).run()
So between uploading the image and setting the image, there is a delay and no feedback to the user.
So I have tried to extend the Image extension and I am able to create a method to set some text, but then I am not sure how to clear that text. Does anyone have a good solution for this?

Mapbox Icon-Image Dynamic Symbol (icon) Loading with Sprite

I am trying to do something I feel is very simple, yet seems that I am clearly misunderstanding a crucial piece of the mapbox addlayer feature.
The Goal
Create dynamically identified icons, based on a features data value (e.g. geojson feature data vale title: "walmart"). Essentially just adding dynamic store icons from the sprite image when those locations are queried via tilequery. picture representation here
The problem
I keep getting an error when trying to use the sprite values from the style. Error: util.js:349 Image "airport-11" could not be loaded. Please make sure you have added the image with map.addImage() or a "sprite" property in your style. You can provide missing images by listening for the "styleimagemissing" map event.
I see tons of resources talking about sprites, but none discuss how to exactly implement them in this fashion. I have even tried querying the sprite and then adding the values using dot notation to access sprite values. This gives an error of "undefined" and invalid value.
Example code:
map.addLayer({
id: "tilequery-points",
type: "symbol",
source: "tilequery", // Set the layer source
layout: {
"icon-image": [
"match",
["get", "title"],
["HEB"],
"H-E-B_logo",
["Pilot Flying j"],
sprite.Pilot_Travel_Centers_logo,
// "Pilot_Travel_Centers_logo",
["Dollar General"],
"Dollar_General_logo",
["Cumberland Farms Corp"],
"Cumberland_Farms_logo (1)",
["CEFCO"],
"CEFCO-convenience-stores-Logo_510px",
["BJs Wholesale Inc"],
The Question
How do I access the sprite values and not get an error?!!!
Thanks for the help! I Wouldn't ask if I didn't need it!
UPDATE
I have figured out that to use sprite images inside of any layer, the images will automatically be available if you have them in your Mapbox studio sprite image collection. The confusion was that previously, I was not able to use them from link. However, it should work automatically.
Hope it helps!
It's true the documentation about sprites is not super clear. I'll try to summarise (simplifying a bit).
A Mapbox GL style has one sprite. That's a PNG containing all the icons, plus a JSON file specifying what each icon is called (its icon ID), and where it located within the PNG. The sprite is specified by giving a URL as the sprite property: https://docs.mapbox.com/mapbox-gl-js/style-spec/sprite/
You can also add images to the sprite dynamically after the map loads, with map.loadImage and map.addImage, specifying the icon ID.
To display an icon, you use that same ID in a symbol layer: "icon-image": "myicon".
You can run into trouble when you try to combine your own icons with those in a Mapbox basemap (which are Maki icons with names like `airport-11').
To combine them, you can do one of these three things:
upload your icons to a style in Mapbox Studio
load your icons dynamically
generate a new sprite sheet offline, using something like mbsprite
I don't know what you meant about "dot notation", but no, that's not the right path.

Rendering an animated GIF in Garmin Connect IQ

According to the documentation (https://developer.garmin.com/connect-iq/programmers-guide/resource-compiler/) the resource compiler supports GIF as Bitmap. However, when I display a GIF file, I just get a still picture, and the GIF doesn't move.
The GIF I have been testing with is this: http://bestanimations.com/Animals/Mammals/Cats/cats/cute-kitty-animated-gif-2.gif
and I have saved the gif in the drawables folder (I use the ConnectIQ-plugin for Eclipse).
I have tried to include the Bitmap in the layouts resources as:
<layout id="MainLayout">
<bitmap id="MotivatorCat" x="center" y="center" filename="../drawables/motivatorcat.gif"/>
</layout>
and I have tried to include it in the drawables resources as:
<drawables>
<bitmap id="MotivatorCat" filename="motivatorcat.gif" />
</drawables>
and then loading it in initialize() by:
catgif = Ui.loadResource(Rez.Drawables.MotivatorCat);
and drawing it in onUpdate():
dc.drawBitmap(50, 50, catgif);
But nothing works.
What am I doing wrong?
The Connect IQ does not currently (as of SDK 2.1.x) support rendering of animated GIF images.

Dynamically loading images from database to webpage momentarily messes up how the masterpage looks like

I'm a senior majoring in Computer Science. I'm new at web development. I'm using ASP.NET C# with MS SQL Server. I've been trying to figure out how to load images from the database onto the webpage. I have successfully done this with the following code.
<asp:Image ID="imageClient" runat="server" style="width:100px; height:100px;"/>
protected void LoadImage()
{
ModelDataContext mdc = new ModelDataContext();
byte[] image = (from c in mdc.Clients select c.Logo).FirstOrDefault().ToArray();
string base64String = Convert.ToBase64String(image, 0, image.Length);
imageClient.ImageUrl = "data:image/jpg;base64," + base64String;
}
Right now I'm just doing it for 1 image. I will eventually be using a repeater to display multiple images on the same page.
The problem is with the loading of the image. It does some weird stuff to the masterpage that it uses. It's as if it isn't applying the CSS to the masterpage. But a few seconds later it looks as it should. The problem is definitely with the loading of the image because there is no other loading problems on any of the other pages.
I tried posting pictures of what I am seeing, but my reputation is too low.
The problem isn't browser specific, it does the same thing in all the major browsers...
If anybody could help me with the problem that would be great.
/############################/
Edit: I realized the images that I was trying to view may have had a filesize too large and it was taking too long to get it from the database and to load the image. My new approach is to save the image to a folder within my project and saving the imageurl in the database to refer to the actual location of the image.
Is this the best approach keeping in mind I am nowhere near at being advanced in Web Dev?
Thanks
Caching the image to a folder can give you benefits such as reducing load on the database. If the web pages are in a busy environment (ie. many users) caching everything you can reducing the load on the database is desirable.
As to the initial image-tag. As far as I remember, the asp:Image doesn't support a Style tag as with html img tag. I think you would need to define a css in a style-sheet (or embedded in the page) and refer to that with the CssClass tag instead - or - use the .Style("property") = "mysetting" in code instead.
F.ex:
imageClient.Style("Width") = "100px"
imageClient.Style("Height") = "100px"

Silverlight Image Loading

I'm a beginner just beginning to work with Silverlight with a very basic question. I want to display a .png image. I have already done it in the page.xaml file but I would like to do it in code (C#) so that I can add and remove images while my program is running. I have seen some code in which you add an image to the Children of a Canvas, but when I do this no images are ever displayed. Could someone provide some code and where to put it? Here is what I've been working with. There are no exceptions, but no image appears.
page.myCanvas.Children.Add(LoadImage("Image/MrBlue"));
public Image LoadImage(string resource)
{
Image img = new Image();
Uri uri = new Uri(resource, UriKind.Relative);
ImageSource imgSrc = new System.Windows.Media.Imaging.BitmapImage(uri);
img.SetValue(Image.SourceProperty, imgSrc);
return img;
}
The image is set to "Resource" and "Do not Copy."
Debugging Silverlight can be a pain, although it's quite possible to set up in VS2008 (which you might already have done. If you haven't feel free to ask...) and that can catch some of the 'simple' errors like having the wrong Uri for the image you want. Your code looks fine to me, although what I'm using is slightly different. If you want an example from a working app, the function I use for loading images is:
public void ShowPicture(Uri location)
{
Image pic = new Image();
pic.Source = new BitmapImage(location);
Grid.SetColumn(pic, 1);
Grid.SetRow(pic, 1);
LayoutRoot.Children.Add(pic);
}
Note that I have a using statement that includes System.Windows.Media.Imaging.
Even without full debugging, a utility like fiddler that shows the http requests might help track down bad Uris in code, which is all I can think of that might be wrong here. Hope it helps.
I tested your code and it works fine for me, so as Raumornie already hinted, it would seem to most likely be an issue with the path to the image. As per your code, is the image file located in a folder called Image in your Silverlight project and just named MrBlue? On a quick look, it seems to be missing the .png, or?
Good luck!

Resources