Get unmanaged data start address int addrStart = 32() Get unmanaged data start address int addrStart = 32() įor ( int i = 0 i /// Writes bitmap data to unmanaged memory ReadBmpData and WriteBmpData are pretty quick, it takes only 0.01s to read and write data. Pay attention, only 24bit bitmaps are supported now, but you can easily extend it for other bitmap types, just add code to GetPixelInfoSize and GetSimilarColor methods. ReadBmpData and WriteBmpData – These methods just copy unmanaged memory (pixels color information) to managed buffer and vice versa. If( bmpSource != null ) bmpSource.UnlockBits( bmpDataSource ) If (bmpDest != null) bmpDest.UnlockBits(bmpDataDest) WriteBmpData(bmpDataDest, destBuffer, imageWidth, imageHeight) Copy all colors to destination bitmaps MatchColors(buffer, destBuffer, pixelSize, bmpDest.Palette) ReadBmpData(bmpDataSource, buffer, pixelSize, imageWidth, imageHeight) Int pixelSize = GetPixelInfoSize(bmpDataSource.PixelFormat) īyte buffer = new byte īyte destBuffer = new byte New Rectangle( 0, 0, imageWidth, imageHeight), / /// Bitmap to convert /// Converted bitmap public Bitmap ConvertTo8bppFormat(Bitmap bmpSource) / /// Converts input bitmap to 8bpp format All results are relevant for 1024x768 bitmaps.ĬonvertTo8bppFormat has no loops its role is to allocate all buffers and to call methods that do the real job. Now let's see the solution and test results. Almost every image has a lot of pixels that have the same color, so for those pixels, color matching will be executed only once. For example, during color matching, for each 24bit color we match the appropriate index in the 256 color palette. It is one of the principles for time critical code development – do not allocate memory on demand, but perform allocation before.
0 Comments
Leave a Reply. |