-
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using Xamarin.Forms; | ||
|
||
namespace MediaManager.Forms | ||
{ | ||
public static class ImageSourceHelper | ||
{ | ||
public static ImageSource ToImageSource(this object image) | ||
{ | ||
#if ANDROID | ||
if (image is Android.Graphics.Bitmap bitmap) | ||
return MediaManager.Forms.Platforms.Android.ImageSourceHelper.ToImageSource(bitmap); | ||
#elif IOS | ||
if (image is CoreGraphics.CGImage cgImage) | ||
return MediaManager.Forms.Platforms.Ios.ImageSourceHelper.ToImageSource(cgImage); | ||
else if (image is UIKit.UIImage uIImage) | ||
return MediaManager.Forms.Platforms.Ios.ImageSourceHelper.ToImageSource(uIImage); | ||
#elif WINDOWS | ||
//TODO: This one should not be async. It might deadlock | ||
if (image is Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage) | ||
return MediaManager.Forms.Platforms.Uap.ImageSourceHelper.ToImageSource(bitmapImage).GetAwaiter().GetResult(); | ||
#endif | ||
return null; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Windows.Storage.Streams; | ||
using Windows.UI.Xaml.Media.Imaging; | ||
using Xamarin.Forms; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace MediaManager.Forms.Platforms.Uap | ||
{ | ||
public static class ImageSourceHelper | ||
{ | ||
public static async Task<ImageSource> ToImageSource(this BitmapImage bitmapImage) | ||
{ | ||
IRandomAccessStreamReference random = RandomAccessStreamReference.CreateFromUri(bitmapImage.UriSource); | ||
Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(await random.OpenReadAsync()); | ||
Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync(); | ||
byte[] bitmapData = pixelData.DetachPixelData(); | ||
|
||
return ImageSource.FromStream(() => new MemoryStream(bitmapData)); | ||
} | ||
} | ||
} |
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
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
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
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