Jay
Jay

Reputation: 1889

Imaging.Imageformat which one is best fit in memory management

Which format among System.Drawing.Imaging.Imageformat is best options on what scenarios?

I am interested with respect to application memory consumption along with the quality of the image.

In my application I have images loading in memory where quality is not priority just the content in the image should be visible, Which Imageformat best fits here?

Upvotes: 0

Views: 377

Answers (1)

Dai
Dai

Reputation: 155055

Memory management is irrelevant - ImageFormat is used to control the format when saving an in-memory bitmap to an IO stream (e.g. a file on disk).

Images in .NET are either Bitmaps or a vector Metafile. I'm fairly certain you're working with Bitmap, which means each instance you create will always occupy Stride * Height * PixelFormat bytes of memory.

While you could have the bytes of a well-compressed PNG or JPEG image in-memory (perhaps in a MemoryStream or Byte[] array), you won't be able to do anything with it (e.g. display it on-screen, modify the image's pixels, etc) until it's represented in-memory as a raster Bitmap, because that's what GDI+ (i.e. System.Drawing.*) needs.

(Yes, there are exceptions, such as loading a JFIF into memory and manipulating the DCT blocks (a la jpegtran), or using a graphics API such as Direct3D or OpenGL that has the ability to read compressed images directly into the graphics card's memory (but even then, textures would still be in-memory in a raster format).

Upvotes: 1

Related Questions