[英]Show Base64String image as MapIcon image in windows phone 8.1
I converted images to base64 string and saved to the SQLite database. 我将图像转换为base64字符串并保存到SQLite数据库。 I want to show that image in the map. 我想在地图上显示该图像。
Code used to convert String to image 用于将String转换为图像的代码
public static BitmapImage Base64StringToBitmap(string source)
{
var ims = new InMemoryRandomAccessStream();
var bytes = Convert.FromBase64String(source);
var dataWriter = new DataWriter(ims);
dataWriter.WriteBytes(bytes);
dataWriter.StoreAsync();
ims.Seek(0);
var img = new BitmapImage();
img.SetSource(ims);
return img;
}
How can I show this image in map. 如何在地图上显示此图像。 Showing pushpins 显示图钉
private void loadPushpin(object sender, RoutedEventArgs e)
{
using (var dbConn = new SQLiteConnection(App.DB_PATH))
{
var query = dbConn.Table<Contacts>();
var result = query.ToList();
foreach (var item in result)
{
Contacts obj = new Contacts();
MapIcon MapIcon1 = new MapIcon();
MapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri(""));
MapIcon1.Location = new Geopoint(new BasicGeoposition()
{
Latitude = Convert.ToDouble(item.Latitude),
Longitude = Convert.ToDouble(item.Longitude)
});
MapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
MapIcon1.Title = item.Name;
MyLocationMap.MapElements.Add(MapIcon1);
}
}
}
Try using CreateFromStream and pass InMemboryRandomeAccessStream instead of CreateFromUri. 尝试使用CreateFromStream并传递InMemboryRandomeAccessStream而不是CreateFromUri。 Below is the code 下面是代码
var ims = new InMemoryRandomAccessStream();
var bytes = Convert.FromBase64String(source);
var dataWriter = new DataWriter(ims);
dataWriter.WriteBytes(bytes);
dataWriter.StoreAsync();
ims.Seek(0);
var img = new BitmapImage();
img.SetSource(ims);
return img;
MapIcon MapIcon1 = new MapIcon();
MapIcon1.Image = RandomAccessStreamReference.CreateFromStream(ims);;
Update 更新资料
private async void loadPushpin(object sender, RoutedEventArgs e)
{
using (var dbConn = new SQLiteConnection(App.DB_PATH))
{
var query = dbConn.Table<Contacts>();
var result = query.ToList();
foreach (var item in result)
{
Contacts obj = new Contacts();
MapIcon1.Location = new Geopoint(new BasicGeoposition()
{
Latitude = Convert.ToDouble(item.Latitude),
Longitude = Convert.ToDouble(item.Longitude)
});
var ims = new InMemoryRandomAccessStream();
var bytes = Convert.FromBase64String(item.ImageString);//set your image base 64 string here...
var dataWriter = new DataWriter(ims);
dataWriter.WriteBytes(bytes);
await dataWriter.StoreAsync();
ims.Seek(0);
MapIcon MapIcon1 = new MapIcon();
MapIcon1.Image = RandomAccessStreamReference.CreateFromStream(ims);
MapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
MapIcon1.Title = item.Name;
MyLocationMap.MapElements.Add(MapIcon1);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.