How to reuse cached result in the FFImageLoading on Xamarin.Forms? - xamarin

I'm trying to load and resize and transform the image in the background while the application main data is loading. I need to do this because some of images are too big and I have a lot of them, so, I thing it's better to prepare all images before showing.
I execute this code in the background:
Load the image from Uri:
ImageService.Instance.LoadUrl(uri, TimeSpan.FromDays(60))
.DownSample(100, 100, false).Preload();
Load the same image and apply additional transformation to it:
ImageService.Instance.LoadUrl(uri, TimeSpan.FromDays(60))
.DownSample(100, 100, false).Transform(BlurredTransformHere).Preload();
How I could reuse later the result from these cache queries in the CachedImage?
<forms:CachedImage
x:Name="Blured"
Aspect="Fill"
CacheType="All"
HorizontalOptions="Fill"
Opacity="0.3"
VerticalOptions="Fill"/>
<forms:CachedImage
x:Name="Normal"
CacheType="All"
Aspect="AspectFit"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"/>
Should I add the same config parameters as in the query for each CachedImage? e.g. add DownsampleHeight&W and BlurredTransformation with the same parameters value?

The Transformations do not affect the cached version of your Image, they just change the way the imageSource is rendered.
In your case for the Image preloading you could apply the DownSample and later use the transformation in your CachedImage control.
<forms:CachedImage
x:Name="Blured"
Aspect="Fill"
CacheType="All"
HorizontalOptions="Fill"
Opacity="0.3"
Source="YOUR_SOURCE_URI"
VerticalOptions="Fill">
<forms:CachedImage.Transformations>
<fftransformations:BlurredTransformation Radius="30"/>
</forms:CachedImage.Transformations>
</forms:CachedImage>

Related

Display image from embedded resource

I need to display our app logo on the main page of the application but no matter what I do, nothing shows up.
<Image
Source="{StaticResource 'MystronicsWinder.Resources.AppIcon.appicon.svg'}"
Margin="20"
Aspect="AspectFill"
IsVisible="true"/>
UPDATE:
<Image
Source="{StaticResource 'MystronicsWinder.Resources.AppIcon.appicon.png'}"
Margin="20"
Aspect="AspectFill"
WidthRequest="300"
HeightRequest="300"
IsVisible="true"/>
I have the same issue with my png logo!
For displaying SVG images I use my library which you can find here: https://github.com/FreakyAli/Maui.FreakyControls
It uses Skia to display SVG images : https://github.com/FreakyAli/Maui.FreakyControls/wiki/FreakySvgImageView
Build action of all SVG images you want to use needs to be set to EmbeddedResource.
<freakyControls:FreakySvgImageView
Command="{Binding OnTapCommand}"
CommandParameter="{Binding OnTapCommandParam}"
Tapped="FreakySvgImageView_Tapped"
SvgAssembly="{x:Static samples:Constants.SvgAssembly}"
SvgMode="AspectFit"
ResourceId="{x:Static samples:Constants.DotnetBot}"/>

Change ToolbarItem Text/Icon parameters

I am new to MAUI. And I haven't done anything complex with Xamarin as well.
The application I am testing with, has Shell navigation. And I can't find a way to change the toolbar items.
I would like to be able to change either the FontSize of the text, or the color of the SVG image. And I do not want those changes to affect the rest of my application, if possible. But if there is no other way, I can live with it.
I have managed to add styling to buttons, Labels etc... If styling is an option to this, it will be even better.
If I am on the wrong path, if you point me out why, I will be also grateful.
Thank you in advance!
If you want to just change a part of pages in your project. You can try to use a <Shell.TitleView> instead of the <Shell.ToolBarItem> in the content pages you want. Such as:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiAppTest.MainPage">
<Shell.TitleView>
<HorizontalStackLayout Margin="5" HorizontalOptions="End">
<Label Text="hello" TextColor="Red" FontSize="Medium" VerticalOptions="Center" HorizontalOptions="End" />
<Image Source="your image" Margin="10" Background="green"/>
</HorizontalStackLayout>
</Shell.TitleView>
You can change style of TabBar in Style.xaml in path \Resources\Style\. Search in file for Shell.TabBarForegroundColor. You will get TargetType="Shell" and this is style for AppShell.xaml.

Getting out of memory exception while loading image using 'FFImageLoading.CachedImage' in xamrinform

I want to show list of images in single page as like gallery. In my xaml page I am creating single wrap view, in that wrap view I have
add ffimageloader for loading images. Here I have gave list of image url' to that wrap view contain ffimageloader. When I called that page it shows fallowing error.
system.outofmemoryexception: out of memory at ffimageloading.platformimageloadertask..... like that. many post's suggest if we using ffimageloader instead of image tag we will reduce this type of issues but still getting same issues after using this one also. I am running my application in xamarin android. Please suggest any idea.
Here is the sample code what I have tried
<CustomWrapView x:Name="SampleGalleryView" ItemsSource="{Binding GalleryImages}">
<CustomWrapView.ItemTemplate>
<DataTemplate>
<ffimageloading:CachedImage Source="{Binding ImageUrl}" />
</DataTemplate>
</CustomWrapView.ItemTemplate>
</CustomWrapView>
Take a look at FFImageLoading's downsampling capabilities. You can read more about it here: https://github.com/luberda-molinet/FFImageLoading/wiki/Xamarin.Forms-API#downsampling-properties
If you have a lot of items, you should use some view which is capable of doing items virtualisation (I suspect that WrapView isn't), like: ListView / CarouselView, etc

Showing multiple images one by one in WP7?

Which control is suitable for showing the images one by one like photo gallery in WP7?
The MetroFlow tool from the Coding4Fun Toolkit will help you accomplish that:
http://www.windowsphonegeek.com/articles/Getting-Started-with-the-Coding4Fun-toolkit-MetroFlow-Control
It really depends on how you want to stack them and where you are getting them from. For example, you could use a ListBox with a custom DataTemplate. Or you could use a StackPanel or a WrapPanel from the Silverlight Toolkit.
How about Telerik's RadSlideView control?
http://www.telerik.com/products/windows-phone/overview/all-controls.aspx#slideview
If the images are small just use StackPanel:
<StackPanel>
<Image ... />
<Image ... />
</StackPanel>
You can use ListBox as well (you will get Scrolling and Virtualization out of a box):
<ListBox>
<Image ... />
<Image ... />
</ListBox>
What I have done, is use the wrap panel control to display the thumbnails of the images in a grid, then when selecting an image, I navigate to a generic page with pretty much just a data bound pivot control with the source bound to my collection of photos. You can set the index of the pivot to whatever the index of the selected photo is in your collection and then swipe between the photos.

Generating and displaying images in grid in Silverlight

I want to develop an webpage like Google Images in Silverlight.
The difference is the images are generated from my DSL.
The webpage shows different images in grid and allows users to pick one.
The webpage then shows similar images to this.
Should I use Grid panel or DataGrid? And how do I handle double click on cells?
Should I generate my DSL to Shapes or Image? What are the pros and cons?
Thanks.
This is actually pretty simple, all you need to do is use a data template for the column in your datagrid.
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn Width="80">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Width="240" Height="180" Source="http://www.yourimage.com/images/myimage.png" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
Optional: If you need to change the image via code rather than inline like this then in place of the Image XAML element put a stackpanel that calls a function in your code-behind, which returns an image.
<StackPanel Loaded="StackPanel_Loaded"></StackPanel>

Resources