Reputation: 63
I'm trying binding image from ASP.NET Web Api service there i have contorller
public class ImageController : ApiController
{
public HttpResponseMessage GetImage()
{
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StreamContent(new FileStream("FileAddress", FileMode.Open));
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
}
}
client side is Windows 8 universal app there are next code
private async void Button_Click(object sender, RoutedEventArgs e)
{
Uri datauri = new Uri("http://localhost:63606/Api/Image");
var client = new HttpClient();
var datafil = await client.GetAsync(datauri);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, datauri);
HttpResponseMessage response = await client.SendRequestAsync(request, HttpCompletionOption.ResponseHeadersRead);
InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
DataWriter writer = new DataWriter(randomAccessStream.GetOutputStreamAt(0));
}
I don't know what to do , I couldn't get image for example in BitmapImage file.
Upvotes: 1
Views: 410
Reputation: 101
Second way if you want get many photo is that you can create new folder in API folder and named it for example PhotoRepository add photo in this folder and get photo via it URI
private void Button_Click(object sender, RoutedEventArgs e)
{
Uri datauri = new Uri("http://localhost:63606/PhotoReposytory/"photo name".jpg");
//jpg or other format
BitmapImage foto = new BitmapImage(datauri);
Image1.Source = foto;
}
Upvotes: 1
Reputation: 101
inYou can do the following
public class ImageController : ApiController
{
public HttpResponseMessage GetImage()
{
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StreamContent(new FileStream("FileAddress", FileMode.Open));
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
}
}
and in the WinRt app write following code
private async void Button_Click(object sender, RoutedEventArgs e)
{
Uri datauri = new Uri("Api Uri");
BitmapImage image= new BitmapImage(datauri);
// if you want show result in XAML Controls
Image1.Sourse=image;
}
in XAML
<Image x:Name="Image1" HorizontalAlignment="Left" Height="292" Margin="48,413,0,0" VerticalAlignment="Top" Width="310"/>
Upvotes: 2