Skip to content

Commit

Permalink
Added feature to save image in photo hub
Browse files Browse the repository at this point in the history
  • Loading branch information
amnsinghl committed Oct 3, 2014
1 parent 30d381a commit 17c6976
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions FlickrApp/FlickrApp/ImageDisplay.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Download Image"
Click="DownloadImage_Clicked"/>
</shell:ApplicationBar.MenuItems>
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar/favs.png"
Text="Favourites"
Click="FavouriteButton_Clicked"/>
Expand Down
41 changes: 38 additions & 3 deletions FlickrApp/FlickrApp/ImageDisplay.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceModel.Channels;
Expand All @@ -12,12 +13,15 @@
using FlickrNet;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Xna.Framework.Media;

namespace FlickrApp
{
public partial class ImageDisplay : PhoneApplicationPage
{
private string photoid;
private Uri photoUri;
private BitmapImage imgSource;
public ImageDisplay()
{
InitializeComponent();
Expand All @@ -27,10 +31,9 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
Photo p = (Photo)PhoneApplicationService.Current.State["photo"];
photoid = p.PhotoId;
Uri uri = new Uri(p.LargeUrl, UriKind.Absolute);
ImageSource imgSource = new BitmapImage(uri);
photoUri = new Uri(p.LargeUrl, UriKind.Absolute);
imgSource = new BitmapImage(photoUri);
MainImage.Source = imgSource;

ImageTitle.Text = p.Title;
FavAndCommentCount.Text = p.CountFaves + " Faves, " + p.CountComments + " Comments";
}
Expand Down Expand Up @@ -117,5 +120,37 @@ private void LikeButton_Clicked(object sender, EventArgs e)
});
}

private bool SaveImageToPhotoHub(WriteableBitmap bmp)
{

using (var mediaLibrary = new MediaLibrary())
{
using (var stream = new MemoryStream())
{
var fileName = string.Format("Gs{0}.jpg", Guid.NewGuid());
bmp.SaveJpeg(stream, bmp.PixelWidth , bmp.PixelHeight , 0, 100);
stream.Seek(0, SeekOrigin.Begin);
var picture = mediaLibrary.SavePicture(fileName, stream);
if (picture.Name.Contains(fileName)) return true;
}
}
return false;
}

private void DownloadImage_Clicked(object sender, EventArgs e)
{
ShowProgressIndicator();
WriteableBitmap bmp = new WriteableBitmap(imgSource);
if (SaveImageToPhotoHub(bmp))
{
MessageBox.Show("Image Saved", "Information", MessageBoxButton.OK);
}
else
{
MessageBox.Show("Error : Image Not Saved", "Information", MessageBoxButton.OK);
}
HideProgressIndicator();
}
}
}
1 change: 1 addition & 0 deletions FlickrApp/FlickrApp/Properties/WMAppManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Capability Name="ID_CAP_MEDIALIB_PLAYBACK" />
<Capability Name="ID_CAP_SENSORS" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
<Capability Name="ID_CAP_MEDIALIB_PHOTO" />
</Capabilities>
<Tasks>
<DefaultTask Name="_default" NavigationPage="SplashScreen.xaml" />
Expand Down

0 comments on commit 17c6976

Please sign in to comment.