Skip to content

Commit

Permalink
Added the possibility to share a network using a QR Code (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed May 19, 2024
1 parent 4268ece commit dd8cdcc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
18 changes: 18 additions & 0 deletions InternetTest/InternetTest/UserControls/WiFiInfoItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,24 @@
</Border.Effect>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Image x:Name="QrImage" />
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button
x:Name="SaveQrBtn"
Margin="0 0 5 0"
Padding="3"
Background="{DynamicResource LightAccent}"
Click="SaveQrBtn_Click"
Content="{x:Static lang:Resources.Save}"
FontWeight="Bold"
Foreground="{DynamicResource Accent}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="CloseQrBtn"
Padding="3"
Click="CloseQrBtn_Click"
Content="{x:Static lang:Resources.Close}"
FontWeight="Bold"
Style="{DynamicResource DefaultButton}" />
</StackPanel>
</StackPanel>
</Border>
Expand Down
25 changes: 25 additions & 0 deletions InternetTest/InternetTest/UserControls/WiFiInfoItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MIT License
SOFTWARE.
*/
using InternetTest.Classes;
using Microsoft.Win32;
using QRCoder;
using System.Drawing;
using System.Drawing.Imaging;
Expand Down Expand Up @@ -128,4 +129,28 @@ private void GetQrBtn_Click(object sender, RoutedEventArgs e)
QrImage.Source = bitmapImage;
QrPopup.IsOpen = true;
}

private void CloseQrBtn_Click(object sender, RoutedEventArgs e)
{
QrPopup.IsOpen = false;
}

private void SaveQrBtn_Click(object sender, RoutedEventArgs e)
{
var dialog = new SaveFileDialog() { Filter = "PNG Files|*.png", Title = Properties.Resources.Save, FileName = WLANProfile.SSIDConfig?.SSID?.Name ?? "" };
if (dialog.ShowDialog() ?? false)
{
SaveImageSourceToPng(QrImage.Source, dialog.FileName);
}
}

void SaveImageSourceToPng(ImageSource imageSource, string filePath)
{
var encoder = new PngBitmapEncoder();
var frame = BitmapFrame.Create((BitmapSource)imageSource);
encoder.Frames.Add(frame);

using var stream = new FileStream(filePath, FileMode.Create);
encoder.Save(stream);
}
}

0 comments on commit dd8cdcc

Please sign in to comment.