Save GIF files to pictures library
This commit is contained in:
Родитель
b17acbb856
Коммит
49132d8f19
|
@ -38,22 +38,18 @@ namespace ImageSequencer
|
|||
|
||||
using (GifRenderer gifRenderer = new GifRenderer())
|
||||
{
|
||||
gifRenderer.Size = new Windows.Foundation.Size(w, h);
|
||||
gifRenderer.Duration = 100;
|
||||
gifRenderer.NumberOfAnimationLoops = 10000;
|
||||
gifRenderer.Sources = gifRendererSources;
|
||||
|
||||
var buffer = await gifRenderer.RenderAsync();
|
||||
|
||||
using (IsolatedStorageFileStream file = IsolatedStorageFile.GetUserStoreForApplication().CreateFile("exported." + GetFileNameRunningNumber() + ".gif"))
|
||||
var filename = "ImageSequencer." + (await GetFileNameRunningNumber()) + ".gif";
|
||||
var storageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
|
||||
using (var stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
|
||||
{
|
||||
Stream bufferStream = buffer.AsStream();
|
||||
bufferStream.CopyTo(file);
|
||||
bufferStream.Close();
|
||||
bufferStream.Dispose();
|
||||
file.Flush();
|
||||
await stream.WriteAsync(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,24 +85,29 @@ namespace ImageSequencer
|
|||
{
|
||||
FilterEffect filterEffect = new FilterEffect(images[0]);
|
||||
|
||||
ImageFusionFilter imageFusionFilter = new ImageFusionFilter(frame, new BitmapImageSource(maskBitmap.AsBitmap()), false);
|
||||
BlendFilter blendFilter = new BlendFilter(frame, BlendFunction.Normal, 1.0);
|
||||
blendFilter.MaskSource = new BitmapImageSource(maskBitmap.AsBitmap());
|
||||
|
||||
filterEffect.Filters = new List<IFilter>() { imageFusionFilter };
|
||||
filterEffect.Filters = new List<IFilter>() { blendFilter };
|
||||
framedAnimation.Add(filterEffect);
|
||||
}
|
||||
|
||||
return framedAnimation;
|
||||
}
|
||||
|
||||
private static int GetFileNameRunningNumber()
|
||||
private static async Task<int> GetFileNameRunningNumber()
|
||||
{
|
||||
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
String[] filenames = store.GetFileNames();
|
||||
var files = await KnownFolders.PicturesLibrary.GetFilesAsync();
|
||||
int max = 0;
|
||||
foreach (String filename in filenames)
|
||||
foreach (StorageFile storageFile in files)
|
||||
{
|
||||
max = Math.Max(max, Convert.ToInt32(filename.Split('.')[1]));
|
||||
var pattern = "ImageSequencer\\.\\d+\\.gif";
|
||||
if (System.Text.RegularExpressions.Regex.IsMatch(storageFile.Name, pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
|
||||
{
|
||||
max = Math.Max(max, Convert.ToInt32(storageFile.Name.Split('.')[1]));
|
||||
}
|
||||
}
|
||||
|
||||
return max + 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ using System.IO.IsolatedStorage;
|
|||
using System.IO;
|
||||
using ImageTools.IO;
|
||||
using ImageTools.IO.Gif;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace ImageSequencer
|
||||
{
|
||||
|
@ -34,32 +35,32 @@ namespace ImageSequencer
|
|||
{
|
||||
FilenameText.Text = imageFileName;
|
||||
|
||||
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(imageFileName, System.IO.FileMode.Open, IsolatedStorageFile.GetUserStoreForApplication()))
|
||||
{
|
||||
// Allocate an array large enough for the entire file
|
||||
byte[] data = new byte[stream.Length];
|
||||
// Read the entire file and then close it
|
||||
stream.Read(data, 0, data.Length);
|
||||
stream.Close();
|
||||
|
||||
ExtendedImage image = new ExtendedImage();
|
||||
image.LoadingCompleted +=
|
||||
(o, ea) => Dispatcher.BeginInvoke(() => { AnimatedImage.Source = image; });
|
||||
|
||||
image.SetSource(new MemoryStream(data));
|
||||
}
|
||||
LoadImage(imageFileName);
|
||||
}
|
||||
}
|
||||
|
||||
public async void LoadImage(String filename)
|
||||
{
|
||||
|
||||
var file = await KnownFolders.PicturesLibrary.GetFileAsync(filename);
|
||||
|
||||
ExtendedImage image = new ExtendedImage();
|
||||
image.LoadingCompleted +=
|
||||
(o, ea) => Dispatcher.BeginInvoke(() => { AnimatedImage.Source = image; });
|
||||
|
||||
image.SetSource((await file.OpenReadAsync()).AsStreamForRead());
|
||||
|
||||
}
|
||||
|
||||
public void About_Click(object sender, EventArgs e)
|
||||
{
|
||||
NavigationService.Navigate(new Uri("/AboutPage.xaml", UriKind.Relative));
|
||||
}
|
||||
|
||||
public void Delete_Click(object sender, EventArgs e)
|
||||
public async void Delete_Click(object sender, EventArgs e)
|
||||
{
|
||||
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
store.DeleteFile(imageFileName);
|
||||
var storageFile = await KnownFolders.PicturesLibrary.GetFileAsync(imageFileName);
|
||||
await storageFile.DeleteAsync();
|
||||
NavigationService.GoBack();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ using System.Collections.ObjectModel;
|
|||
using System.IO.IsolatedStorage;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.IO;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace ImageSequencer
|
||||
{
|
||||
|
@ -44,22 +45,22 @@ namespace ImageSequencer
|
|||
};
|
||||
}
|
||||
|
||||
private void PopulateGifs()
|
||||
private async void PopulateGifs()
|
||||
{
|
||||
Gifs.Clear();
|
||||
|
||||
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
String[] fileNames = store.GetFileNames();
|
||||
|
||||
foreach (String filename in fileNames)
|
||||
var files = await KnownFolders.PicturesLibrary.GetFilesAsync();
|
||||
foreach (StorageFile storageFile in files)
|
||||
{
|
||||
using (var sourceFile = store.OpenFile(filename, FileMode.Open, FileAccess.Read))
|
||||
var pattern = "ImageSequencer\\.\\d+\\.gif";
|
||||
if (System.Text.RegularExpressions.Regex.IsMatch(storageFile.Name, pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
|
||||
{
|
||||
var stream = (await storageFile.OpenReadAsync()).AsStreamForRead();
|
||||
BitmapImage bitmapImage = new BitmapImage();
|
||||
bitmapImage.SetSource(sourceFile);
|
||||
bitmapImage.SetSource(stream);
|
||||
GifThumbnail gifThumbnail = new GifThumbnail();
|
||||
gifThumbnail.BitmapImage = bitmapImage;
|
||||
gifThumbnail.FileName = filename;
|
||||
gifThumbnail.FileName = storageFile.Name;
|
||||
Gifs.Add(gifThumbnail);
|
||||
}
|
||||
}
|
||||
|
@ -92,10 +93,11 @@ namespace ImageSequencer
|
|||
NavigationService.Navigate(new Uri("/AboutPage.xaml", UriKind.Relative));
|
||||
}
|
||||
|
||||
public void Delete_Click(object sender, EventArgs e)
|
||||
public async void Delete_Click(object sender, EventArgs e)
|
||||
{
|
||||
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
store.DeleteFile(((sender as MenuItem).DataContext as GifThumbnail).FileName);
|
||||
var filename = ((sender as MenuItem).DataContext as GifThumbnail).FileName;
|
||||
var storageFile = await KnownFolders.PicturesLibrary.GetFileAsync(filename);
|
||||
await storageFile.DeleteAsync();
|
||||
PopulateGifs();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<VisualStudio>
|
||||
<FlavorProperties GUID="{C089C8C0-30E0-4E22-80C0-CE093F111A43}">
|
||||
<SilverlightMobileCSProjectFlavor>
|
||||
<FullDeploy>True</FullDeploy>
|
||||
<FullDeploy>False</FullDeploy>
|
||||
<DebuggerType>Managed</DebuggerType>
|
||||
<DebuggerAgentType>Managed</DebuggerAgentType>
|
||||
<Tombstone>False</Tombstone>
|
||||
|
|
|
@ -335,7 +335,6 @@ namespace ImageSequencer
|
|||
|
||||
HideProgressIndicator();
|
||||
|
||||
_rendering = false;
|
||||
if (resumePlaybackAfterSave)
|
||||
{
|
||||
Play();
|
||||
|
|
|
@ -1,52 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
|
||||
|
||||
<Identity Name="209161c7-5f5f-4ef5-a0d4-4e9f3eae7fdf"
|
||||
Publisher="CN=pekka"
|
||||
Version="1.0.0.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="fa534e87-99d0-4f57-a83a-94675f98961c" PhonePublisherId="e1a93e7d-92f1-4ed6-abe6-722ecd93bfef"/>
|
||||
|
||||
<Identity Name="209161c7-5f5f-4ef5-a0d4-4e9f3eae7fdf" Publisher="CN=pekka" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="fa534e87-99d0-4f57-a83a-94675f98961c" PhonePublisherId="e1a93e7d-92f1-4ed6-abe6-722ecd93bfef" />
|
||||
<Properties>
|
||||
<DisplayName>ImageSequencer</DisplayName>
|
||||
<PublisherDisplayName>pekka</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
|
||||
<Prerequisites>
|
||||
<OSMinVersion>6.3.1</OSMinVersion>
|
||||
<OSMaxVersionTested>6.3.1</OSMaxVersionTested>
|
||||
</Prerequisites>
|
||||
|
||||
<Resources>
|
||||
<Resource Language="x-generate"/>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
|
||||
<Applications>
|
||||
<Application Id="xfa534e87y99d0y4f57ya83ay94675f98961cx"
|
||||
Executable="AGHost.exe"
|
||||
EntryPoint="ImagePicker.xaml">
|
||||
<m3:VisualElements
|
||||
DisplayName="ImageSequencer"
|
||||
Square150x150Logo="Assets\SquareTile150x150.png"
|
||||
Square44x44Logo="Assets\Logo.png"
|
||||
Description="ImageSequencer"
|
||||
ForegroundText="light"
|
||||
BackgroundColor="#464646">
|
||||
<m3:DefaultTile Square71x71Logo="Assets\SquareTile71x71.png"/>
|
||||
<Application Id="xfa534e87y99d0y4f57ya83ay94675f98961cx" Executable="AGHost.exe" EntryPoint="ImagePicker.xaml">
|
||||
<m3:VisualElements DisplayName="ImageSequencer" Square150x150Logo="Assets\SquareTile150x150.png" Square44x44Logo="Assets\Logo.png" Description="ImageSequencer" ForegroundText="light" BackgroundColor="#464646">
|
||||
<m3:DefaultTile Square71x71Logo="Assets\SquareTile71x71.png">
|
||||
</m3:DefaultTile>
|
||||
<m3:SplashScreen Image="Assets\Splashscreen.png" />
|
||||
<m3:ApplicationView MinWidth="width320"/> <!--Used in XAML Designer. DO NOT REMOVE-->
|
||||
<m3:ApplicationView MinWidth="width320" />
|
||||
<!--Used in XAML Designer. DO NOT REMOVE-->
|
||||
</m3:VisualElements>
|
||||
<Extensions>
|
||||
<Extension Category="windows.backgroundTasks" EntryPoint="AgHost.BackgroundTask">
|
||||
<BackgroundTasks>
|
||||
<Task Type="systemEvent" />
|
||||
<Task Type="systemEvent" />
|
||||
</BackgroundTasks>
|
||||
</Extension>
|
||||
</Extensions>
|
||||
</Application>
|
||||
</Applications>
|
||||
<Capabilities>
|
||||
<Capability Name="picturesLibrary" />
|
||||
</Capabilities>
|
||||
<Extensions>
|
||||
<Extension Category="windows.activatableClass.inProcessServer">
|
||||
|
@ -56,4 +43,4 @@
|
|||
</InProcessServer>
|
||||
</Extension>
|
||||
</Extensions>
|
||||
</Package>
|
||||
</Package>
|
|
@ -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="ImagePicker.xaml" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче