Hello. Do these methods only work on images stored in the Assets folder of the app? Currently I have an BitmapImage that is set using a RandomAccessStream rather than a Uri, then found out this wasn't possible as it only works for certain types of bitmaps (Uri specified to web or local app directory). So as it worked for images in my Assets folder using the Uri scheme ms-appx I had other images in /LocalCache instead of Assets but I couldn't get it to work. The Uri shows as below.
Uri = file:///C:/Data/Users/DefApps/APPDATA/Local/Packages/MYAPPFOLDER/LocalCache/MyImage.png
According to msdn http://blogs.windows.com/buildingapps/2014/06/19/common-questions-and-answers-about-files-and-app-data-part-1-app-data/
localcache uses the Uri scheme ms-appdata:///localcache, so I tried this as well but it has failed and the WriteableBitmapExtension tools throw an error
WinRT information: 'uri': Only http, https and ftp schemes are allowed.
Additional information: The parameter is incorrect.
It would be nice if more support was added for files outside of the AppData folder using the one Uri scheme and you could use files anywhere (so long as your app has the required permission). I even tried specifying the absolute path as shown in the first Uri in my post and though the image loads in my app the Bitmap tools failed to do anything with the image.
All I am trying to do is resize a bitmapimage and get the color and it seems very difficult using the native api, I was hoping this one would help but so far I have not been able to manage.
public static async Task<Color> GetColorFromBitmap(BitmapImage image)
{
try
{
WriteableBitmap WriteableImage = await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(image);
WriteableImage = WriteableBitmapExtensions.Resize(WriteableImage, 1, 1, WriteableBitmapExtensions.Interpolation.Bilinear);
Color PixelColor = WriteableImage.GetPixel(0, 0);
return PixelColor;
}
catch (Exception ex)
{
return Colors.Black;
}
}
Instead of trying to convert all BitmapImages (whether set as Uri or set using SetSourceAsync(RandomAccessStream)) I instead just tried to create the WriteableBitmap from the start, and though it was created so the first line in the code above was not necessary, the second line failed for the resize on the WriteableBitmaps that were created using a Bitmap that was set using a RandomAccessStream.
Can anyone advise how I can get an image in my app LocalCache folder resized :) Thanks for your time and help in advance!
Uri = file:///C:/Data/Users/DefApps/APPDATA/Local/Packages/MYAPPFOLDER/LocalCache/MyImage.png
According to msdn http://blogs.windows.com/buildingapps/2014/06/19/common-questions-and-answers-about-files-and-app-data-part-1-app-data/
localcache uses the Uri scheme ms-appdata:///localcache, so I tried this as well but it has failed and the WriteableBitmapExtension tools throw an error
WinRT information: 'uri': Only http, https and ftp schemes are allowed.
Additional information: The parameter is incorrect.
It would be nice if more support was added for files outside of the AppData folder using the one Uri scheme and you could use files anywhere (so long as your app has the required permission). I even tried specifying the absolute path as shown in the first Uri in my post and though the image loads in my app the Bitmap tools failed to do anything with the image.
All I am trying to do is resize a bitmapimage and get the color and it seems very difficult using the native api, I was hoping this one would help but so far I have not been able to manage.
public static async Task<Color> GetColorFromBitmap(BitmapImage image)
{
try
{
WriteableBitmap WriteableImage = await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(image);
WriteableImage = WriteableBitmapExtensions.Resize(WriteableImage, 1, 1, WriteableBitmapExtensions.Interpolation.Bilinear);
Color PixelColor = WriteableImage.GetPixel(0, 0);
return PixelColor;
}
catch (Exception ex)
{
return Colors.Black;
}
}
Instead of trying to convert all BitmapImages (whether set as Uri or set using SetSourceAsync(RandomAccessStream)) I instead just tried to create the WriteableBitmap from the start, and though it was created so the first line in the code above was not necessary, the second line failed for the resize on the WriteableBitmaps that were created using a Bitmap that was set using a RandomAccessStream.
Can anyone advise how I can get an image in my app LocalCache folder resized :) Thanks for your time and help in advance!