This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DllImport("gdi32.dll", EntryPoint = "DeleteObject")] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
public static extern bool DeleteObject([In] IntPtr hObject); | |
public static ImageSource ToImageSource(this Bitmap bmp) | |
{ | |
var handle = bmp.GetHbitmap(); | |
try | |
{ | |
return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static BitmapSource Resize(this BitmapSource source, int resolution) | |
{ | |
var scale = resolution / source.DpiX; | |
// サイズ変更 | |
var transformedBitmap = new TransformedBitmap(); | |
transformedBitmap.BeginInit(); | |
transformedBitmap.Source = source; | |
transformedBitmap.Transform = new ScaleTransform(scale, scale); | |
transformedBitmap.EndInit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static BitmapSource Resize(this BitmapSource source, int resolution) | |
{ | |
var scale = resolution / source.DpiX; | |
// サイズ変更 | |
var transformedBitmap = new TransformedBitmap(); | |
transformedBitmap.BeginInit(); | |
transformedBitmap.Source = source; | |
transformedBitmap.Transform = new ScaleTransform(scale, scale); | |
transformedBitmap.EndInit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static BitmapSource Rotation(this BitmapSource source, int angle) | |
{ | |
if (source == null) throw new ArgumentNullException(nameof(source)); | |
var transformedBitmap = new TransformedBitmap(); | |
transformedBitmap.BeginInit(); | |
transformedBitmap.Source = source; | |
transformedBitmap.Transform = new RotateTransform(90); | |
transformedBitmap.EndInit(); | |
return transformedBitmap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] SaveToJpeg(this BitmapSource source, int qualityLevel) | |
{ | |
if (source == null) throw new ArgumentNullException(nameof(source)); | |
using (var outputStream = new MemoryStream()) | |
{ | |
// WICのEncoderを利用してJpegファイルに保存する | |
// System.Drawingパッケージの場合、8bit形式のJpegに対応していないため | |
var encoder = new JpegBitmapEncoder { QualityLevel = qualityLevel }; | |
encoder.Frames.Add(BitmapFrame.Create(source)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static BitmapSource CreateFormJpeg(byte[] bytes) | |
{ | |
using (var stream = new MemoryStream(bytes)) | |
{ | |
var decoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); | |
return decoder.Frames[0]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static BitmapImage Create(byte[] bytes) | |
{ | |
var result = new BitmapImage(); | |
using (var stream = new MemoryStream(bytes)) | |
{ | |
result.BeginInit(); | |
result.CacheOption = BitmapCacheOption.OnLoad; | |
result.CreateOptions = BitmapCreateOptions.None; | |
result.StreamSource = stream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void OnInitialized() | |
{ | |
InitializeComponent(); | |
//NavigationService.NavigateAsync("MainPage?title=Hello%20from%20Xamarin.Forms"); | |
NavigationService.NavigateAsync("NavigationPage/MainPage?title=Hello%20from%20Xamarin.Forms"); | |
} | |
protected override void RegisterTypes() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" | |
prism:ViewModelLocator.AutowireViewModel="True" | |
x:Class="NavigationService.Views.SecondPage"> | |
<StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="Center"> | |
<Label Text="Second Page."/> | |
<Button Text="Go Back." Command="{Binding GoBackCommand}"/> | |
</StackLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SecondPageViewModel : BindableBase | |
{ | |
private readonly INavigationService _navigationService; | |
public ICommand GoBackCommand { get; } | |
public SecondPageViewModel(INavigationService navigationService) | |
{ | |
_navigationService = navigationService; | |
GoBackCommand = new DelegateCommand(() => | |
{ | |
_navigationService.GoBackAsync(); |