Skip to content
Permalink
Browse files

Merge pull request #16 from GlitchedPolygons/feature/6-add-gif-support

Fixed #6.
  • Loading branch information
GlitchedPolygons committed Oct 14, 2019
2 parents c8effce + ff91204 commit 9dc1caf124707b92c610b4dcb093c46c843f55a5
@@ -16,6 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using System.IO;

namespace GlitchedPolygons.GlitchedEpistle.Client.Windows.ViewModels
{
public class ImageViewerViewModel : ViewModel
@@ -30,6 +32,19 @@ public class ImageViewerViewModel : ViewModel
#region UI Bindings
private byte[] imageBytes;
public byte[] ImageBytes { get => imageBytes; set => Set(ref imageBytes, value); }

private MemoryStream imageBytesStream;
public MemoryStream ImageBytesStream
{
get
{
if (imageBytesStream is null)
{
imageBytesStream = new MemoryStream(ImageBytes ?? new byte[0]);
}
return imageBytesStream;
}
}
#endregion
}
}
@@ -88,7 +88,7 @@ public byte[] FileBytes
var img = new BitmapImage();
img.BeginInit();
img.DecodePixelWidth = 300;
img.StreamSource = new MemoryStream(value);
img.StreamSource = FileBytesStream;
img.EndInit();
img.Freeze();
Image = img;
@@ -100,6 +100,19 @@ public byte[] FileBytes
}
}

private MemoryStream fileBytesStream;
public MemoryStream FileBytesStream
{
get
{
if (fileBytesStream is null)
{
fileBytesStream = new MemoryStream(FileBytes ?? new byte[0]);
}
return fileBytesStream;
}
}

private bool isOwn;
public bool IsOwn
{
@@ -127,7 +140,7 @@ public Visibility ClipboardTickVisibility
set => Set(ref clipboardTickVisibility, value);
}

public Visibility ImageVisibility => IsImage() ? Visibility.Visible : Visibility.Hidden;
public Visibility ImageVisibility => IsImage() || IsGif() ? Visibility.Visible : Visibility.Hidden;
public Visibility AttachmentButtonVisibility => HasAttachment() ? Visibility.Visible : Visibility.Hidden;
#endregion

@@ -1,19 +1,19 @@
<!--
Glitched Epistle - Windows Client
Copyright (C) 2019 Raphael Beck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Glitched Epistle - Windows Client
Copyright (C) 2019 Raphael Beck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<Window x:Class="GlitchedPolygons.GlitchedEpistle.Client.Windows.Views.ImageViewerView"
@@ -22,6 +22,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GlitchedPolygons.GlitchedEpistle.Client.Windows.Views"
xmlns:gif="clr-namespace:XamlAnimatedGif;assembly=XamlAnimatedGif"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Icon="/Resources/Images/epistle-icon.png"
@@ -42,7 +43,9 @@
Margin="50"
Name="Image"
Cursor="SizeAll"
Source="{Binding ImageBytes}" />
gif:AnimationBehavior.AnimateInDesignMode="True"
gif:AnimationBehavior.RepeatBehavior="Forever"
gif:AnimationBehavior.SourceStream="{Binding ImageBytesStream}" />
</Border>
</Grid>
</Window>
@@ -1,26 +1,27 @@
<!--
Glitched Epistle - Windows Client
Copyright (C) 2019 Raphael Beck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Glitched Epistle - Windows Client
Copyright (C) 2019 Raphael Beck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<UserControl x:Class="GlitchedPolygons.GlitchedEpistle.Client.Windows.Views.UserControls.MessageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:gif="clr-namespace:XamlAnimatedGif;assembly=XamlAnimatedGif"
mc:Ignorable="d">

<Grid Margin="0,0,0,5">
@@ -137,16 +138,19 @@
Command="{Binding DownloadAttachmentCommand}" />
</WrapPanel>

<!-- Image (only displayed when attachment is a .png or .jpg) -->
<!-- Image (only displayed when attachment is an image) -->
<Image Cursor="Hand"
Source="{Binding Image}"
Visibility="{Binding ImageVisibility}"
Style="{DynamicResource ImageAttachmentStyle}"
MaxWidth="350"
MaxHeight="350"
Margin="5,26,0,-12"
Name="ImagePreview"
HorizontalAlignment="Left"
Source="{Binding Image}"
Visibility="{Binding ImageVisibility}"
Style="{DynamicResource ImageAttachmentStyle}">
gif:AnimationBehavior.AnimateInDesignMode="true"
gif:AnimationBehavior.RepeatBehavior="Forever"
gif:AnimationBehavior.SourceStream="{Binding FileBytesStream}">
<Image.InputBindings>
<MouseBinding Gesture="LeftClick"
Command="{Binding ClickedOnImageAttachmentCommand}" />

0 comments on commit 9dc1caf

Please sign in to comment.
You can’t perform that action at this time.