Set Adaptive Tile Background from Image - c#

I am creating a TileNotification to display the last edited project on my app's tile. When doing this I want to set the tile's background to be the project cover image. I'm creating the TileContent like this:
TileContent content = new TileContent()
{
Visual = new TileVisual()
{
TileMedium = new TileBinding()
{
Content = new TileBindingContentAdaptive()
{
BackgroundImage = new TileBackgroundImage()
{
Source = new TileImageSource("ms-appx:///Assets/Images/MainPageBackground.jpg"),
Overlay = 10
},
Children =
{
new TileText()
{
Text = DataModel.Instance.CurrentProject.Title,
Align = TileTextAlign.Left
}
}
}
}
}
};
The problem is that the only way to set the Source property seems to be with a TileImageSource, which only accepts a string. And since the project's cover image is stored in ApplicationData.Current.LocalFolder... I can't just give it a string. Is there any way to set the image source from an actual image rather than a string?

After some more searching I found this method of doing it.
You can use the "ms-appdata:///Local" prefix to get the file. In my case:
$"ms-appdata:///local/Projects/{ProjectName}/Slides/0.gif".
That can then be handed in as the source.

Related

How to get the width of a photo taken in Xamarin

I have the following code to take a picture in Xamarin:
MediaFile photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions()
{
SaveToAlbum = true,
Name = fileName
});
However, after I've taken the picture, I want to retrieve the width of the image. I thought there might be a:
photo.Width
But there is not. There is a PhotoSize property on the StoreCameraMediaOptions, but that appears to be a way to dictate the size, rather than retrieve it.
Is there a way to do this in Xamarin, or an existing plug-in that will accomplish it?
Using FFImageLoading the ImageInformation class gives you the original height & width,
you could assign a mediafile to an image then get the width of that image that rendered the mediafile
var image = new CachedImage()
{
Source = ImageSource.FromStream(() => photo.GetStream())
};
image.Success += (sender, e) =>
{
var h = e.ImageInformation.OriginalHeight;
var w = e.ImageInformation.OriginalWidth;
};
Hope this one might helps.
Here you go this might help you...
public static Size GetImageSize(string fileName)
{
#if __IOS__
UIImage image = UIImage.FromFile(fileName);
return new Size((double)image.Size.Width, (double)image.Size.Height);
#endif
return Size.Zero;
}

Adding Multiple Custom Markers to Bing Maps (API) example

I've started with this example:
https://code.msdn.microsoft.com/bing/Using-the-Bing-Maps-V8-Web-07e21f3a#content
Which basically gives a form with a search option and present the search result in a html file.
Now I'm trying to add an array of items instead of one to the html file, to show these.
But I can't seem to understand how to get the html file to capture the list of addresses from the Form1.cs file with a button click
I've added this to the form:
private void GroupBtn_Click(object sender, EventArgs e)
{
var pushpinInfos = new[] {
new { lat = 41.80584, lng = 21.15498, title = "Salmon Market", description = "Kipper Gostivar", icon = "http://icons.iconarchive.com/icons/icons-land/vista-map-markers/24/Map-Marker-Marker-Inside-Chartreuse-icon.png" },
new { lat = 42.000900, lng = 21.466440, title = "Market", description = "Gostivar", icon = "https://i-msdn.sec.s-msft.com/dynimg/IC488534.jpeg" }
};
MyWebBrowser.Document.InvokeScript("SetMap", new object[] { pushpinInfos });
}
And this to the html file:
function SetMap(addresses) {
//Create an infobox at the center of the map but don't show it.
infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
visible: false
});
//Assign the infobox to a map instance.
infobox.setMap(map);
pinLayer = new Microsoft.Maps.EntityCollection();
map.entities.push(pinLayer);
var pins1 = JSON.stringify(addresses);
// alert(pins1);
$.each(JSON.parse(pins1), function (key, pinJson) {
var position = new Microsoft.Maps.Location(pinJson.lat, pinJson.lng);
// Creates a Pushpin
var pin = new Microsoft.Maps.Pushpin(position, { text: pinJson.Title, icon: 'images/map_pin_13.png', typeName: 'sampleCustom' });
//Store some metadata with the pushpin.
pin.metadata = {
title: 'Pin',
description: 'Discription for pin'
};
//Add a click event handler to the pushpin.
Microsoft.Maps.Events.addHandler(pin, 'click', pushpinClicked);
//Add pushpin to the map.
map.entities.push(pin);
pinLayer.push(pin);
});
}
But it doesn't work, and I can't seem to debug the html form.
So my questions are:
1) Isn't there a way to debug the html part?
2) Where did i go wrong with trying to show the 2 addresses on the map?
A couple of issues in your code:
You create a pin layer, but are adding the pins directly to the map and the layer. This will cause an issue.
Your pin layer is using the deprecated EntityCollection class and map.entities. Use map.layers and Microsoft.Maps.Layer
Pushpin's don't have a typeName option. That was a feature in an old map control and not available in the latest version as rendering happens on an HMTL5 canvas which doesn't support CSS styles.
Minor thing, but when using a layer, add events to it rather than individual shapes, it helps with performance.
Here is a modified version of your code:
function SetMap(addresses) {
//Create an infobox at the center of the map but don't show it.
infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
visible: false
});
//Assign the infobox to a map instance.
infobox.setMap(map);
pinLayer = new Microsoft.Maps.Layer();
map.layers.insert(pinLayer);
//Add a click event handler to the pin layer.
Microsoft.Maps.Events.addHandler(pinLayer, 'click', pushpinClicked);
var pins1 = JSON.stringify(addresses);
// alert(pins1);
$.each(JSON.parse(pins1), function (key, pinJson) {
var position = new Microsoft.Maps.Location(pinJson.lat, pinJson.lng);
// Creates a Pushpin
var pin = new Microsoft.Maps.Pushpin(position, { text: pinJson.Title, icon: 'images/map_pin_13.png', typeName: 'sampleCustom' });
//Store some metadata with the pushpin.
pin.metadata = {
title: 'Pin',
description: 'Discription for pin'
};
//Add pushpin to the map.
pinLayer.add(pin);
});
}

Can you add xaml into your FlipTileData BackContent?

Is it possible to set xaml inside the FlipTileData.BackContent? Basically I just want to be able to set a full layout with multiple lines, control over spacing and layout and maybe an inline image.
Is this possible or is the FlipTileData.BackContent limited to text only?
This is my current code for BackContent but I can not get anything other than just text to work in the there.
private FlipTileData GetSecondaryTileData()
{
FlipTileData tileData = new FlipTileData
{
Title = resortforTile.ListName,
BackgroundImage = new Uri("/Assets/Tiles/MountainTile.png", UriKind.Relative),
BackContent = ""
};
return tileData;
}
You cannot set XAML as BackContent but you can render the XAML into an image and set the BackBackgroundImage to this image.
More info at http://www.jayway.com/2012/04/03/advanced-transparent-live-tiles-with-count-for-windows-phone/

mapscript : adding Label to Layer with persian text

I am having some issues using Persian text as label. I am using C# mapscript. I am setting the following at runtime:(like button click)
private void addLayer(String layerName)
{
if (layer == null)
{
//create a layer
layer = new layerObj(mapInstance);
layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
layer.status = mapscript.MS_ON;
layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
}
// Create a classObj
OSGeo.MapServer.classObj classobj = new OSGeo.MapServer.classObj(layer);
//create Label
labelObj label = new labelObj();
label.font = "sc";
label.type = MS_FONT_TYPE.MS_TRUETYPE;
label.encoding = "utf-8";
classobj.addLabel(label);
//add user data
//create feature
shapeObj feature = new shapeObj(mapscript.MS_SHAPEFILE_POINT);
lineObj line = new lineObj();
pointObj point = new pointObj(50,50, 0, 0);
line.add(point);
feature.add(line);
feature.text = "این متن فارسی است :گژپچ";
layer.addFeature(feature);
}
But labels are displayed as '?????'.
how can i fix this? Is there any conversion I need to do before setting the text value?
Appreciate any help
Try using different font file: label.font = "sc";.
The ‘□’ comes when it can't find the letter in that .ttf file.(May be it is not mapped to ttf or mapped to a different Unicode character). You can either go into .ttf file and change the font geometry or you can install different font files to get the correct one.

Parameter to an image

How to add a parameter for an image to this variable?
var selectionDisplay = new SelectionDisplay(button.Label as string);
Thanks in advance!
EDIT:
I have this set of images and their respective code below (see pic1)
This is where the program gets the images to be displayed. The code for the buttons is this one:
var files = Directory.GetFiles(#".\GalleryImages");
foreach (var file in files)
{
FileInfo fileInfo = new FileInfo(file);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(file, UriKind.Relative);
bi.EndInit();
var button = new KinectTileButton
{
Label = System.IO.Path.GetFileNameWithoutExtension(file),
Background = new ImageBrush(bi)
};
this.wrapPanel.Children.Add(button);
}
This is where the program gets the images to be displayed.
The code for the buttons is this one:
private void KinectTileButtonclick(object sender, RoutedEventArgs e)
{
var button = (KinectTileButton)e.fake_fake_fakeource;
var selectionDisplay = new SelectionDisplay(button.Label as string);
this.kinectRegionGrid.Children.Add(selectionDisplay);
e.Handled = true;
Right now, when i click on of the images, the SelectionDisplay window pops up, which look like this (see pic2). What i want is that when I click an image the SelectionDisplay window should open with the respective image... meaning that if I click on the image with a dog, the window should open with the dog's image, not with other image.
I hope I've made myself clear and that you can help me.
http://i58.tinypic.com/8zl6h3.jpg
http://i57.tinypic.com/208fosy.png
is this the constructor you are talking about? is this where i should make changes? should i add something after "string itemid"?
public SelectionDisplay(string itemId)
{
this.InitializeComponent();
this.messageTextBlock.Text = string.Format(CultureInfo.CurrentCulture,Properties.Resources.SelectedMessage,itemId);
}
I see two approaches:
Just pass the image brush in your constructor. Its view->view, so you aren't breaking MVVM (and it looks like you aren't using that pattern anyways).
new SelectionDisplay(button.Label, button.Background);
Set the path as the "tag" of the button. The tag property is an object you can put whatever you want into (the framework does not use it, and so it is included for this very purpose). Then just pass the string to SelectionDisplay, and instantiate the image just like you are doing for the button:
var button = new KinectTileButton
{
Label = System.IO.Path.GetFileNameWithoutExtension(file),
Background = new ImageBrush(bi),
Tag = file
};
var selectionDisplay = new SelectionDisplay(button.Label as string, button.Tag as string);
FrameworkElement.Tag on MSDN (Note that Button derives from FrameworkElement, as do all controls, so it automatically has it as well!)
UPDATE
I see that SelectionDisplay is a UserControl in your project, so you just need to change its constructor to look like:
Numbers match above:
SelectionDisplay(string labelText, ImageBrush sourceImage)
SelectionDisplay(string labelText, string imagePath)
That is the source of the error you are getting, you have to modify the constructor to take the new parameter.
Please let me know if I can clarify anything.

Categories

Resources