Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
E.g. Resize an 8000x8000 big size image to 500x500 small size image, below C# .NET methods were tested:

1. Bitmap smallimg = new Bitmap(bigimg, 500, 500);

2. Bitmap smallimg = bigimg.GetThumbnailImage(500, 500, ...);

3. Bitmap smallimg = new Bitmap(500, 500);
Graphics.FromImage(smallimg).DrawImage(bigimg, 0, 0, 500, 500);

Above methods all cost about 400~500 milliseconds time. It is too slow.

Any method can speed up the image resizing?

Include using Intel Graphics HD 520 capacity (e.g. DirectX 12).

What I have tried:

PictureBox pb = new PictureBox();
pb.Image = bigimg; // 8000x8000 image

pb.DrawToBitmap(...) is also very slow.
Posted
Updated 31-Jan-23 16:54pm
Comments
PIEBALDconsult 31-Jan-23 22:26pm    
I never (or rarely) try to do anything faster than Microsoft's best can do it.
[no name] 1-Feb-23 20:57pm    
You have to be more specific. Was it "load time"? Render time? Save time? Saveing or displaying? If it's for viewing, use a ViewBox. You could even save the visual from the ViewBox. Anyway, if you're "resizing" just to save, you should be batching it or doing it in the background if it's an issue (and not on the UI thread).

1 solution

 
Share this answer
 
v3
Comments
w14243 1-Feb-23 0:15am    
Tested it, it is very very slow.
Graeme_Grant 1-Feb-23 3:12am    
Have you tried any 3rd-party libs?
w14243 1-Feb-23 3:16am    
Have not. I don't know any 3rd-party libs.
w14243 1-Feb-23 22:38pm    
Tested it.
SKBitmap.Resize is about 125ms, but SKBitmap.Decode is about 1000ms.

private void button2_Click(object sender, EventArgs e)
{
long t0 = Environment.TickCount64;

using (var original = SKBitmap.Decode(@"D:\y\7\y.jpg")) // 7000x9000 size image
{
long t3 = Environment.TickCount64;
long t3e = t3 - t0; // about 1000ms

using (var resized = original.Resize(new SKImageInfo(70 * 10, 90 * 10), SKFilterQuality.High))
{
long t4 = Environment.TickCount64;
long t4e = t4 - t3; // about 125ms

if (resized == null)
return;

Bitmap bmp = new Bitmap(resized.Encode(SKEncodedImageFormat.Jpeg, 100).AsStream(), false);

long t7 = Environment.TickCount64;
long t7e = t7 - t4; // about 30ms

PictureBox pb = new PictureBox();
pb.Image = bmp;
pb.SizeMode = PictureBoxSizeMode.AutoSize;
pb.Left = 0;
pb.Top = 0;
this.Controls.Add(pb);

long te = t7 - t0;

int bb = 0;
}
}


int xx = 0;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900