On my windows store app, im using a bings maps, and im trying to add a pushpin with an image
to do so , im doing this piece of code
Bing.Maps.Location center = new Bing.Maps.Location();
center.Latitude = 40.130066068147585;
center.Longitude = -8.338623046875;
Map.Center = center;
Map.ZoomLevel = 12D;
var pushpinLayer = new MapLayer();
pushpinLayer.Name = "PushPinLayer";
Map.Children.Add(pushpinLayer);
var location = new Location(40.130066068147585D, -8.338623046875D);
Image pinImage = new Image();
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("ms-appx:///Assets/POI_Red_Ipad#2x.png", UriKind.RelativeOrAbsolute);
pinImage.Width = 20;
pinImage.Height = 30;
pinImage.Source = bitmapImage;
pushpinLayer.Children.Add(pinImage);
it adds the pushpin image but it appears on the top left corner of the map, i dont know how to set its position to use the localtion variable :\
Ok so you just have things a little out of order. The first part is correct:
Bing.Maps.Location center = new Bing.Maps.Location();
center.Latitude = 40.130066068147585;
center.Longitude = -8.338623046875;
Map.Center = center;
Map.ZoomLevel = 12D;
Next, instead of creating a maplayer you would instead create your pushpin image:
Image pinImage = new Image();
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("ms-appx:///Assets/POI_Red_Ipad#2x.png", UriKind.RelativeOrAbsolute);
pinImage.Width = 20;
pinImage.Height = 30;
pinImage.Source = bitmapImage;
Then you can create your location:
var location = new Location(40.130066068147585D, -8.338623046875D);
Here is where it is different. You do not need to create an instance of the MapLayer class, instead assign the element (image in your case) and location - then add it to to the map.
MapLayer.SetPosition(pinImage, location);
Map.Children.Add(pinImage);
Related
I have a problem when I add Images in a wrapPanel, it refuses to load if there are too many images in memory.
In fact, when I create an Image control and its source comes from a URL (from which it has to download the image), delete the Image control and recreate one with the same source, the image appears directly but there is no time to download the image like the first creation of the control.
How can I remove the image from memory?
Here is my code:
Image image = new Image();
image.Width = 60;
image.Height = 60;
image.ToolTip = StringExtension.GetTextBetweenTwoWord(Utilities.resource.EmojiesLink[i], "/72/apple/271/", "_").Replace('-', ' '); // name of mood
image.Stretch = Stretch.Fill;
image.Source = new BitmapImage(new Uri(Utilities.resource.EmojiesLink[i]));
image.MouseDown += new MouseButtonEventHandler(ExtraMoodFromWebsiteMouseDown);
wrapPanel_moodFromInternet.Children.Add(image);
P.S.: it's in WPF
You can release an object from memory by calling the dispose method.
https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image.dispose?view=dotnet-plat-ext-5.0
Image image = new Image();
image.Width = 60;
image.Height = 60;
image.ToolTip = StringExtension.GetTextBetweenTwoWord(Utilities.resource.EmojiesLink[i], "/72/apple/271/", "_").Replace('-', ' '); // name of mood
image.Stretch = Stretch.Fill;
image.Source = new BitmapImage(new Uri(Utilities.resource.EmojiesLink[i]));
image.MouseDown += new MouseButtonEventHandler(ExtraMoodFromWebsiteMouseDown);
wrapPanel_moodFromInternet.Children.Add(image);
image.Dispose(true);
I am working on canvas and loading an image on it. How do I set resolution of my image to 640X480 pixels? decodepixelheight and decodepixelwidth not working.
ImageBrush brush = new ImageBrush();
BitmapImage src = new BitmapImage(new Uri(("C:\\Users\\i2v\\Desktop\\GoogleMapTA.jpg"), UriKind.Relative));
src.DecodePixelHeight = 480;
src.DecodePixelWidth = 640;
brush.ImageSource = src;
// brush.Stretch = Stretch.None;
canvas.Background = brush;
canvas.Height = src.Height;
canvas.Width = src.Width;
BitmapImage implements the System.ComponentModel.ISupportInitialize interface. This means that its properties can only be set between calls of its BeginInit and EndInit methods:
var src = new BitmapImage();
src.BeginInit();
src.UriSource = new Uri(#"C:\Users\i2v\Desktop\GoogleMapTA.jpg");
src.DecodePixelHeight = 480;
src.DecodePixelWidth = 640;
src.EndInit();
canvas.Background = new ImageBrush(src);
Note that you would usually not set DecodePixelWidth and DecodePixelHeight at the same time, since this might disrupt the native aspect ratio of the image. Set either one or the other.
I applied customized pixel-shader effect to an image.
var eff = new Shaders.PixelateEffect();
eff.HorizontalPixelCounts = 15;
eff.VerticalPixelCounts = 15;
IMG1.Effect = eff;
Then I tried to merge and overlay between the effect applied image(IMG1) and another image.(IMG2)
But, IMG1.Source bring me an original image.
ImageUtils.OverlayingImages(IMG1.Source, IMG2.Source, x, y);
How can I get an updated image source?
it happened same when I rotate the image.
Do I need to capture the image with RenderTargetBitmap?
Thank you in advance.
I've solved it like this with RenderTargetBitmap. anyway, thank you for the comments.
var eff = new Shaders.PixelateEffect();
eff.HorizontalPixelCounts = 15;
eff.VerticalPixelCounts = 15;
BitmapSource bitmap = (BitmapSource)IMG1.Source;
var r = new Rectangle();
r.Fill = new ImageBrush(bitmap);
r.Effect = eff;
Size sz = new Size(bitmap.PixelWidth, bitmap.PixelHeight);
r.Measure(sz);
r.Arrange(new Rect(sz));
var rtb = new RenderTargetBitmap(bitmap.PixelWidth, bitmap.PixelHeight, 96, 96
, PixelFormats.Default);
rtb.Render(r);
// here's the updated source with the custom effect.
IMG1.Source= ImageUtils.RenderTargetBitmapToBitmap(rtb);
I want to add a pin on a certain location on a map for a windows phone 8.0 app.
My code so far is the following:
private async void Button_Click(object sender, RoutedEventArgs e)
{
BasicGeoposition bGeo = new BasicGeoposition();
bGeo.Latitude = 37.4333;
bGeo.Longitude = 24.9167;
Geopoint geoPoint = new Geopoint(bGeo,0);
myMap.ZoomLevel = 13;
myMap.Center = geoPoint;
}
private void AddMapIcon()
{
MapIcon MapIcon1 = new MapIcon();
MapIcon1.Location = new Geopoint(new BasicGeoposition()
{
Latitude = 37.4333,
Longitude = 24.9167
});
MapIcon1.NormalizedAnchorPoint = new Point(2.0, 2.0);
myMap.MapElements.Add(MapIcon1);
}
The map is loading properly, but the pin won't appear. Any ideas on this? Is there any way to do it without using xaml controls for the pin?
This is a general way of adding any UI on map control in windows phone:
We need to create "map layers" and "map overlays" and specify the coordinates where we want to place it. Sample code:
Read the tutorial here
You can add an Image control in the overlay and point its source to the pin image you want to plot. Hope this help
You can try..
BitmapImage myImage1;
myImage1 = new BitmapImage(new Uri("/Assets/Images/pushpin-google-hi.png", UriKind.RelativeOrAbsolute));
var image = new Image();
image.Width = 50;
image.Height = 50;
image.Opacity = 100;
image.Source = myImage1;
var mapOverlay = new MapOverlay();
mapOverlay.Content = image;
mapOverlay.GeoCoordinate = new GeoCoordinate(lats, lons);
var mapLayer = new MapLayer();
mapLayer.Add(mapOverlay);
MyMap.Layers.Add(mapLayer);
MyMap.SetView(new GeoCoordinate(lats, lons), 16);
I use WriteableBitmap to set pixel in Wpf. but when I used writePixels method to change the color of pixels it's change color to black :(. It's my code snap:
ofdOpen.ShowDialog();
BitmapImage img = new BitmapImage(new Uri(ofdOpen.FileName));
WriteableBitmap wbmap = new
WriteableBitmap(img);
byte[] pixels = new byte[
wbmap.PixelHeight*wbmap.PixelWidth*
wbmap.Format.BitsPerPixel/8];
pixels[0] =255;
pixels[1] = 0;
pixels[2] = 0;
pixels[3] = 255;
wbmap.WritePixels(
new Int32Rect(0, 0,
wbmap.PixelWidth, wbmap.PixelHeight),
pixels,
wbmap.PixelWidth * wbmap.
Format.BitsPerPixel / 8, 0);
image1.Source = wbmap;
I'm googling too much. but I couldn't find any source about this problem.
It's appearing black because you're rewriting the entire contents of the image, not just a few pixels. Your pixels array is declared to be to be the size of the entire image, but you are only setting two of the first four bytes of color data. So, when you call WritePixels, it's redrawing the entire image with the provider color data, which is almost all 0's.
To correct this, only declare the pixels array to be the size of the pixels you want to write.
Finllay I found solution:
BitmapImage originalIamge = new BitmapImage();
originalIamge.BeginInit();
originalIamge.UriSource = new Uri(ofdOpen.FileName);
originalIamge.EndInit();
BitmapSource bitmapSource = new FormatConvertedBitmap(originalIamge, PixelFormats.Bgr32, null, 0);
wbmap = new WriteableBitmap(bitmapSource);
h = wbmap.PixelHeight;
w = wbmap.PixelWidth;
pixelData = new int[w * h];
widthInByte = 4 * w;
wbmap.CopyPixels(pixelData, widthInByte, 0);
image1.Source = wbmap;
Point absoluteScreenPos = PointToScreen(Mouse.GetPosition((IInputElement)sender));
Image img = new Image();
BitmapImage point = new BitmapImage(
new Uri("Images/Dott.png",
UriKind.Relative));
img.Source = point;
var rt = ((UIElement)image1).RenderTransform;
var offsetX = rt.Value.OffsetX;
var offsetY = rt.Value.OffsetY;
int newX = (int)Mouse.GetPosition((IInputElement)sender).X;
int newY = (int)Mouse.GetPosition((IInputElement)sender).Y;
for (int i = 0; i < 400; i++)
{
pixelData[i] = 0x000000ff;
}
wbmap.WritePixels(new Int32Rect(newX,newY,10,10), pixelData, widthInByte, 0);
image1.Source = wbmap;