Beispiel #1
0
        private void SetImage_toFloat(Bitmap bmp)
        {
            Util.FreeBuffer(ref imgBuf);
            ImageUtil.BitmapToGrayImageBuffer(bmp, ref imgBuf, ref bw, ref bh, ref bytepp);

            // byte -> float
            unsafe {
                var bufOld = imgBuf;
                imgBuf = Marshal.AllocHGlobal(bw * bh * 4);
                for (int y = 0; y < bh; y++)
                {
                    var pbyte  = (byte *)bufOld + y * bw;
                    var pfloat = (float *)imgBuf + y * bw;
                    for (int x = 0; x < bw; x++, pbyte++, pfloat++)
                    {
                        *pfloat = (float)*pbyte / 255;
                    }
                }
                Marshal.FreeHGlobal(bufOld);
            }

            bytepp = 4;
            imgBox.SetImageBuffer(imgBuf, bw, bh, bytepp, true);
            imgBox.Invalidate();
        }