Skip to content

Commit

Permalink
Fix Local files will not show on Windows #9
Browse files Browse the repository at this point in the history
  • Loading branch information
microspaze committed Feb 5, 2024
1 parent 0dbd735 commit aa81445
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ protected virtual void AfterLoading(TImageContainer image, bool fromMemoryCache)

protected virtual async Task<TImageContainer> GenerateImageAsync(string path, ImageSourceType sourceType, Stream imageData, ImageInformation imageInformation, bool enableTransformations, bool isPlaceholder)
{
//using (imageData)
using (imageData)
{
var decoder = ResolveDecoder(imageInformation.Type);
var decoderContainer = await decoder.DecodeAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ public async static Task<WriteableBitmap> ToBitmapImageAsync(this Stream imageSt
if (imageStream == null)
return null;

using (IRandomAccessStream image = imageStream.AsRandomAccessStream())
{
//NO NEED TO FREE RandomAccessStream, OTHERWISE Bitmap WILL NOT SHOW
var image = imageStream.AsRandomAccessStream();
if (image != null)
{
if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0))
{
using (var downscaledImage = await image.ResizeImage(imageService, scale, downscale.Item1, downscale.Item2, mode, downscaleDipUnits, allowUpscale, imageInformation).ConfigureAwait(false))
var downscaledImage = await image.ResizeImage(imageService, scale, downscale.Item1, downscale.Item2, mode, downscaleDipUnits, allowUpscale, imageInformation).ConfigureAwait(false);
if (downscaledImage != null)
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(downscaledImage);
downscaledImage.Seek(0);
Expand Down Expand Up @@ -86,6 +89,7 @@ await imageService.Dispatcher.PostAsync(async () =>
return bitmap;
}
}
return null;
}

public async static Task<BitmapHolder> ToBitmapHolderAsync(this Stream imageStream, IImageService<BitmapSource> imageService, double scale, Tuple<int, int> downscale, bool downscaleDipUnits, InterpolationMode mode, bool allowUpscale, ImageInformation imageInformation = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BitmapHolder(byte[] pixels, int width, int height)

public byte[] PixelData { get; private set; }

public int PixelCount { get { return (int)(PixelData.Length / 4); } }
public int PixelCount { get { return PixelData == null ? 0 : (int)(PixelData.Length / 4); } }

public void SetPixel(int x, int y, ColorHolder color)
{
Expand Down

0 comments on commit aa81445

Please sign in to comment.