Beispiel #1
0
        private void rgb565swapped(ref byte[] imgBuf, int width, int height, int pixelsize, int totalImageSize)
        {
            byte[] rawData = new byte[totalImageSize];
            Buffer.BlockCopy(imgBuf, 0, rawData, 0, totalImageSize);  // then we can keep the result in imgBuf

            // Mirror the picture line by line
            long pixWidth = pixelsize * width;
            long i        = 0;
            long j        = 0;

            for (long h = 0; h < height; h++)
            {
                long offset = h * pixWidth;
                for (long w = 0; w < pixWidth; w++)
                {
                    i = offset + w;
                    j = offset + (pixWidth - 1) - w;
                    if (i < 0 || i >= totalImageSize || j < 0 || j >= totalImageSize)
                    {
                        Trace.WriteLine("h=" + h + " offset=" + offset + " pixw=" + pixWidth + " i=" + i + " j=" + j);
                    }
                    else
                    {
                        imgBuf[i] = rawData[j];
                    }
                }
            }
            Trace.WriteLine("ConvertImageFileFormat: mirroring done");

            // Convert the raw data to bitmap format
            Rectangle  rect  = new Rectangle(0, 0, width, height);
            BitmapData bData = MyBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, MyBitmap.PixelFormat);

            IntPtr ptr = bData.Scan0;

            System.Runtime.InteropServices.Marshal.Copy(imgBuf, 0, ptr, totalImageSize);
//            byte[] pt = System.Runtime.InteropServices.Marshal.st  PtrToStructure(ptr , typeof( bData.Scan0 ));
//            Buffer.BlockCopy(imgBuf,0, pt, 0, totalImageSize);

            MyBitmap.UnlockBits(bData);
        }