I am solving a task where I need to convert Bitmap data to custom image format. I am currently doing this: [em]Bitmap.GetBitmap()[/em] => RLP => byte array (custom format) => send. I need to achieve the best performance possible. I have one crazy idea, please tell me what you think about it : .
I want to access Bitmap object directly from RLP without using [em]GetBitmap()[/em] first. [em]GetBitmap()[/em] allocates new array every single time you call it and you cannot specify it to store data in already predefined byte array. Hence I get GC being called too often if I call [em]GetBitmap()[/em], for example, 250 times in 10 seconds. I also expect to achieve better speed by eliminating calls to [em]GetBitmap()[/em].
Maybe GHI team could add an option to pass not only integers, strings, arrays etc. to RLP, but objects as well?
By the way, during my investigation, if my idea could work, I came across [em]GHI.Utilities.Bitmap[/em] class. My first thought was that GHI guys have already partially implemented my idea, but I was quickly disappointed when I found out that they are using [em].GetBitmap()[/em] first and then are doing some byte array manipulation internally. There are two things I would like to point out about this class:
- If you call [em]Convert(Bitmap bitmap, Bitmaps.BitsPerPixel bpp)[/em], [em]GetBitmap()[/em] is being called 3 times! That’s painfully slow, plus you get memory fragmentation. Why not use [em]bitmap.Width * bitmap.Height * 4[/em] instead of [em]bitmap.GetBitmap().Length[/em]?
- Error message is not accurate:
if (outputBuffer.Length != Bitmaps.RequiredBufferSize(bitmap, bpp)) throw new ArgumentOutOfRangeException("outputBuffer", "outputBuffer is too small. Call RequiredBufferSize to determine how large it must be");