Question
I'm developing a Tizen 5.0 application for Samsung TV where I need to display approximately 200 images in a collection view. Due to security restrictions, I cannot use FFImageloading.
The images are currently 900x600 in size, and I want to reduce them by a factor of 3 to save memory. While the initial images load quickly, performance degrades when scrolling through the collection view.
What is the most efficient way to resize these images while maintaining good performance?
Answer
Problem Understanding
The developer needs to:
- Display a large number of images (200+) in a collection view
- Resize images from 900x600 to smaller dimensions (approximately 300x200)
- Maintain good performance while scrolling
- Work within Tizen 5.0 security constraints that prevent using FFImageloading
Solution Methods
- Using SkiaSharp for Image Resizing: SkiaSharp provides efficient image processing capabilities and works within Tizen's security constraints.
Code Examples
public void ImageResizer(string inputPath, string outputPath)
{
int desiredWidth = 300; // 1/3 of original width
int desiredHeight = 200; // 1/3 of original height
const int quality = 75; // JPEG quality setting
using (var input = File.OpenRead(inputPath))
using (var inputStream = new SKManagedStream(input))
using (var original = SKBitmap.Decode(inputStream))
{
using (var resized = original.Resize(
new SKImageInfo(desiredWidth, desiredHeight),
SKBitmapResizeMethod.Lanczos3))
{
if (resized == null) return;
using (var image = SKImage.FromBitmap(resized))
using (var output = File.OpenWrite(outputPath))
{
image.Encode(SKEncodedImageFormat.Jpeg, quality)
.SaveTo(output);
}
}
}
}
Additional Tips
- Consider resizing images during the initial load rather than on-demand
- For better performance, you can:
- Use streams instead of file paths for input/output
- Implement asynchronous processing
- Cache resized images
- The Lanczos3 resizing method provides good quality but you can experiment with other methods for better performance