On Ftp upload, someone uploaded high-definition pictures, each picture is about 2M.
If you use the traditional BitmapImage class and then bind the Source property method, some computers will be stuck for the first time. One computer will be stuck for 10 seconds, and 4 computers will be stuck for about 40 seconds.
So I first download the image asynchronously, get the downloadFileStream object, and then bind it to the BitmapImage class. For example:
photo = new Image
{
Width = 100,
Height = 100,
Margin = new Thickness(2),
Stretch =
};
BitmapImage bitmap = new BitmapImage();
();
= downloadFileStream;
();
= bitmap;
ListBoxItem lbi = new ListBoxItem()
{
DataContext = pvo,
Content = photo
};
(lbi);
Because the StreamSource of bitmap is relatively large, the lbi object is relatively large, so the method will be stuck for about 30 seconds after adding two pictures.
So try to use thumbnails to make the BitmapImage object smaller. Here, thumbnails are used because the client needs the image size to be roughly
(100,100)。
The complete code is as follows:
photo = new Image
{
Width = 100,
Height = 100,
Margin = new Thickness(2),
Stretch =
};
using ( drawingImage = (downloadFileStream))
{
using ( thumbImage =
(100, 100, () => { return true; }, ))
{
MemoryStream ms = new MemoryStream();
(ms, );
BitmapFrame bf = (ms);
= bf;
}
}
ListBoxItem lbi = new ListBoxItem()
{
DataContext = pvo,
Content = photo
};
(lbi);
Here, you want to reference. Use the GetThumbnailImage method of the class to get the thumbImage, then use the MemoryStream to save the thumbnail stream, and then use the thumbnail stream to generate the image.
Finally, I would like to say: Although this problem is solved, you have to download high-definition pictures and generate thumbnails every time, which is very time-consuming, so when uploading the pictures, you should generate thumbnails and save the thumbnails. Because in LAN, the network speed is relatively fast, this method can basically meet the requirements.
If you use the traditional BitmapImage class and then bind the Source property method, some computers will be stuck for the first time. One computer will be stuck for 10 seconds, and 4 computers will be stuck for about 40 seconds.
So I first download the image asynchronously, get the downloadFileStream object, and then bind it to the BitmapImage class. For example:
photo = new Image
{
Width = 100,
Height = 100,
Margin = new Thickness(2),
Stretch =
};
BitmapImage bitmap = new BitmapImage();
();
= downloadFileStream;
();
= bitmap;
ListBoxItem lbi = new ListBoxItem()
{
DataContext = pvo,
Content = photo
};
(lbi);
Because the StreamSource of bitmap is relatively large, the lbi object is relatively large, so the method will be stuck for about 30 seconds after adding two pictures.
So try to use thumbnails to make the BitmapImage object smaller. Here, thumbnails are used because the client needs the image size to be roughly
(100,100)。
The complete code is as follows:
photo = new Image
{
Width = 100,
Height = 100,
Margin = new Thickness(2),
Stretch =
};
using ( drawingImage = (downloadFileStream))
{
using ( thumbImage =
(100, 100, () => { return true; }, ))
{
MemoryStream ms = new MemoryStream();
(ms, );
BitmapFrame bf = (ms);
= bf;
}
}
ListBoxItem lbi = new ListBoxItem()
{
DataContext = pvo,
Content = photo
};
(lbi);
Here, you want to reference. Use the GetThumbnailImage method of the class to get the thumbImage, then use the MemoryStream to save the thumbnail stream, and then use the thumbnail stream to generate the image.
Finally, I would like to say: Although this problem is solved, you have to download high-definition pictures and generate thumbnails every time, which is very time-consuming, so when uploading the pictures, you should generate thumbnails and save the thumbnails. Because in LAN, the network speed is relatively fast, this method can basically meet the requirements.