Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What image format can c# load fastest?

this may seem like an odd question, and I don't know the formats of images so I'll just go ahead and ask...

I'm making a minesweeper game (relevant to different things too) which utilizes a grid of buttons, then I'm adding a sprite to the buttons using backgroundImage. If the grid is 9x9 it's fine. 15x15 it slows down and 30x30 you can visibly see each button being loaded.

That raises me to my question: Which image format would load fastest? Obviously, file size takes a part in the loading speed, however, I am enquiring as to if, say, a jpeg - with the same filesize as a gif - will load faster. or a bmp, png, etc.

I'm asking this as to see if I can get my grid to load faster using a different format.

Thanks!

like image 939
Anteara Avatar asked Nov 01 '12 11:11

Anteara


People also ask

What are the 3 types images format?

The PNG, JPEG, and GIF formats are most often used to display images on the Internet. Some of these graphic formats are listed and briefly described below, separated into the two main families of graphics: raster and vector.

Is PNG or JPG better?

Because of their different compression processes, JPEGs contain less data than PNGs — and therefore, are usually smaller in size. Unlike JPEGs, PNGs support transparent backgrounds, making them preferred for graphic design.

Which image format should I use?

The PNG file format is optimized for digital use, making it the most commonly used image format. It also supports more colors than the GIF format – PNG can handle up to 16 million colors, while GIF only supports 256 colors.

What is the most accepted image format?

JPG is the most used image file format. JPG is the file extension for JPEG files (Joint Photographic Experts Group, a committee of ISO and ITU).


3 Answers

You want an image format that paints faster. There's only one, the one whose pixel format directly matches the video adapter's setting so that the pixel data can be directly copied without needing format adjustments.

On most any modern machine, that's PixelFormat.Format32bppPArgb. It draws ten times faster than all the other ones.

You won't get that format when loading an image from a resource or a file, you have to create it.

Do note that this still won't give you stellar paint speed if every cell in the grid is a control. Particularly if it is a button, they are very expensive to draw since they support transparency effects. You'll only get ahead here if you draw the entire grid in one Paint event handler. Like the form's.

A completely different approach is to cover up the visible delays with this hack.

like image 180
Hans Passant Avatar answered Oct 06 '22 00:10

Hans Passant


use the 8-bit PNG or GIF format and reduce the number of colors in the palette. Some image programs such as PhotoShop allow you to save the image for the web and fine-tune the image settings. By reducing the color palette from 256 to something like 32, you greatly reduce the size of the file. The less colors that the image has, the smaller the file size is going to be.

PNG has a similar feature called "Interlaced". You may want to turn this feature off so that the full image downloads quicker.

Because the 8-bit PNG and GIF formats have the potential to result in much smaller image files, try to keep this in mind when creating graphics and illustrations for your application. Try to keep the amount of colors to a minimum and use flat graphics instead of photographs. This way you can create images with palettes of 16 colors, keeping the file size extremely small and fast to load.

Best Regards

like image 26
Ibrahim Oudah Avatar answered Oct 06 '22 01:10

Ibrahim Oudah


Are you reloading the image every time you paint a button? If so, there's your problem - solve it with a cache.

Are you painting the image at its native size? Runtime resampling can create a performance hit.

like image 37
plinth Avatar answered Oct 05 '22 23:10

plinth