Image Formats
-
Hi. Can anyone give me a general gude (or a link to some resources) on the subject of different image formats? But let me explain more specifically: I have a control that shows a lot of text items whose size & format depend on the content itself. This means that every time the control is repainted, a lot of text rendering occurs. To go around this problem I use a very simple idea - render the text to an image an draw the image until the text changes. The only problem with this idea is the consumption of a lot of RAM. What can I do to reduce the amount of memory I use? GDI+ offeres only the abstract Image class (Bitmap & Metafile as its descendents) for Drawing Images on the screen. Is there a way to reduce the colors or perhaps use some sort of compression when I save the Images in the in-memory buffer? Thank you.
-
Hi. Can anyone give me a general gude (or a link to some resources) on the subject of different image formats? But let me explain more specifically: I have a control that shows a lot of text items whose size & format depend on the content itself. This means that every time the control is repainted, a lot of text rendering occurs. To go around this problem I use a very simple idea - render the text to an image an draw the image until the text changes. The only problem with this idea is the consumption of a lot of RAM. What can I do to reduce the amount of memory I use? GDI+ offeres only the abstract Image class (Bitmap & Metafile as its descendents) for Drawing Images on the screen. Is there a way to reduce the colors or perhaps use some sort of compression when I save the Images in the in-memory buffer? Thank you.
You really can't do anything. A bitmap in memory must be a bitmap, which means it's huge. You could keep it in memory as a jpeg in a stream, and re build the bitmap from that, I do that to cache a lot of images, but I believe it will be too slow to do this to keep an image that is being drawn on every paint event.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi. Can anyone give me a general gude (or a link to some resources) on the subject of different image formats? But let me explain more specifically: I have a control that shows a lot of text items whose size & format depend on the content itself. This means that every time the control is repainted, a lot of text rendering occurs. To go around this problem I use a very simple idea - render the text to an image an draw the image until the text changes. The only problem with this idea is the consumption of a lot of RAM. What can I do to reduce the amount of memory I use? GDI+ offeres only the abstract Image class (Bitmap & Metafile as its descendents) for Drawing Images on the screen. Is there a way to reduce the colors or perhaps use some sort of compression when I save the Images in the in-memory buffer? Thank you.
Hi, what you ask can be found in the doc under "PixelFormat Enumeration". but I am afraid you're idea is not very sound; replacing text by an image to speed things up is not the way to go. Instead make your text drawing faster. Text drawing normally is VERY fast, unless you're doing something wrong. If you need help on this, just show some of your code. :)
Luc Pattyn [My Articles]
-
Hi. Can anyone give me a general gude (or a link to some resources) on the subject of different image formats? But let me explain more specifically: I have a control that shows a lot of text items whose size & format depend on the content itself. This means that every time the control is repainted, a lot of text rendering occurs. To go around this problem I use a very simple idea - render the text to an image an draw the image until the text changes. The only problem with this idea is the consumption of a lot of RAM. What can I do to reduce the amount of memory I use? GDI+ offeres only the abstract Image class (Bitmap & Metafile as its descendents) for Drawing Images on the screen. Is there a way to reduce the colors or perhaps use some sort of compression when I save the Images in the in-memory buffer? Thank you.
Hi, To reduce the memory consumption : 1- Use the jpeg format 2- Specify the compression level 3- Always dispose graphics objects, pens, images,.. and set them to null Here some code to specify the compression level : private static ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for(j = 0; j < encoders.Length; ++j) { if(encoders[j].MimeType == mimeType) return encoders[j]; } return null; } private void SaveJPGWithCompressionSetting( Image image, string szFileName, long lCompression ) { EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter( Encoder.Quality, lCompression ); ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); image.Save( szFileName, ici, eps ); }