In the following snippet of code I am trying to get the image directly from the network the application is supposed to work with. (Xamarin.forms)
if (!String.IsNullOrEmpty(CurrentProduct.Image))
{
SharpCifs.Config.SetProperty("jcifs.smb.client.lport", "8080");
//Get Auth
var auth = new NtlmPasswordAuthentication("CLD", "login", "password");
string path = $@"smb://file/products/{CurrentProduct.Image}".Replace($"\\", $"/");
//Get target's SmbFile.
var file = new SmbFile(path, auth);
try
{
if (file.Exists())
{
// Get readable stream.
var readStream = file.GetInputStream();
//Create reading buffer.
MemoryStream memStream = new MemoryStream();
//Get bytes.
((Stream)readStream).CopyTo(memStream);
var stream1 = new MemoryStream(memStream.ToArray());
if (stream1.Length < 120188100)
{
//Save image
ProductImage = ImageSource.FromStream(() => stream1);
//Dispose readable stream.
readStream.Dispose();
InfoColSpan = 1;
}
else
{
Common.AlertError("Image trop lourde pour l'affichage");
}
}
}
catch (Exception ex)
{
Common.AlertError(ex, "Impossible de charger l'image");
}
}
Usually things work fine, but for a couple of days, we've received massive preview image for some products. I started getting the error that the drawing was too large.
Now a quick search allowed me to se the most common fix is to move the image in another folder (drawable-xxhdpi) which is not possible for me since I'm not choosing where I store the image here. The other proposed solution was to change the image size, but I don't know how to do it on an imagesource filetype. I tried limiting the size of the stream to avoid the issue, but to no avail.