Re: Pixelated small images and circles
Posted: 15 Dec 2020, 14:31
The images are added in a folder called "Content" in the build folder (with sub-folders for images' categories), and then this class load the images for the ViewModel:
This class is used in the ViewModels, for example like this :
In xaml, the images are displayed with a binding :
There is no "noesis:Dependency" in xaml, the images are not used in WPF or Unity, only after the project is built.
for information, I am only the integrator working in the xaml file so I didn't write the C#
Several developpers write the ViewModels, not always use the LoadImage class but it seems they always use the "Texture2D(TextureSource)"
Code: Select all
namespace TMPC
{
public static class LoadImage
{
/// <summary>
/// Load an image in Content folder
/// </summary>
/// <param name="folderName"></param>
/// <param name="fileName"></param>
public static ImageSource GetImageSource(string folderName, string fileName)
{
var filePath = Path.Combine("Content", folderName, fileName);
if (!File.Exists(filePath))
{
return null;
}
#if NOESIS
var fileData = File.ReadAllBytes(filePath);
var tex = new Texture2D(2, 2, TextureFormat.RGBA32, false);
tex.LoadImage(fileData);
return new TextureSource(tex);
#else
return new BitmapImage(new Uri($"pack://siteoforigin:,,,/{filePath}"));
#endif
}
/// <summary>
/// Load an image in Content folder
/// </summary>
/// <param name="filePath"></param>
public static ImageSource GetImageSource(string filePath)
{
if (!File.Exists(filePath))
{
return null;
}
#if NOESIS
var fileData = File.ReadAllBytes(filePath);
var tex = new Texture2D(2, 2, TextureFormat.RGBA32, false);
tex.LoadImage(fileData);
return new TextureSource(tex);
#else
return new BitmapImage(new Uri($"pack://siteoforigin:,,,/{filePath}"));
#endif
}
/// <summary>
/// Get Path for image
/// </summary>
/// <param name="folderName"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public static string GetPath(string folderName, string fileName)
{
return Path.Combine("Content", folderName, fileName);
}
}
}Code: Select all
msg.SenderImg = LoadImage.GetImageSource(msgR.PathImgSender);
Code: Select all
<Border Grid.Column="1" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="45" Height="45" CornerRadius="45">
<Border.Background>
<ImageBrush ImageSource="{Binding SenderImg}"/>
</Border.Background>
</Border>
for information, I am only the integrator working in the xaml file so I didn't write the C#
Several developpers write the ViewModels, not always use the LoadImage class but it seems they always use the "Texture2D(TextureSource)"