Example #1
0
        public static MemBitmap CopyImgBuffer(this MemBitmap src, int srcX, int srcY, int srcW, int srcH)
        {
            //simple copy
            Rectangle orgSourceRect = new Rectangle(0, 0, src.Width, src.Height);
            Rectangle requestRect   = new Rectangle(srcX, srcY, srcW, srcH);
            Rectangle toCopyRect    = Rectangle.Intersect(new Rectangle(0, 0, src.Width, src.Height),
                                                          new Rectangle(srcX, srcY, srcW, srcH));

            if (toCopyRect.Width == 0 || toCopyRect.Height == 0)
            {
                return(null);
            }
            //-----
            MemBitmap copyBmp = new MemBitmap(toCopyRect.Width, toCopyRect.Height);

            unsafe
            {
                using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = MemBitmap.GetBufferPtr(src))
                    using (CpuBlit.Imaging.TempMemPtr dstBufferPtr = MemBitmap.GetBufferPtr(copyBmp))
                    {
                        int *srcPtr  = (int *)srcBufferPtr.Ptr;
                        int *dstPtr  = (int *)dstBufferPtr.Ptr;
                        int  lineEnd = srcY + srcH;
                        int  orgSrcW = src.Width;
                        for (int line = toCopyRect.Top; line < toCopyRect.Bottom; ++line)
                        {
                            NativeMemMx.memcpy((byte *)dstPtr, (byte *)(srcPtr + ((line * orgSrcW) + toCopyRect.Left)), toCopyRect.Width * 4);
                            dstPtr += toCopyRect.Width;
                        }
                    }
            }

            return(copyBmp);
        }
Example #2
0
        public static int[] CopyImgBuffer(MemBitmap memBmp, int width, int height)
        {
            //calculate stride for the width

            int destStride = MemBitmap.CalculateStride(width, CpuBlit.Imaging.PixelFormat.ARGB32);
            int newBmpW = destStride / 4;
            int[] buff2 = new int[newBmpW * height];
            unsafe
            {

                using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = MemBitmap.GetBufferPtr(memBmp))
                {
                    byte* srcBuffer = (byte*)srcBufferPtr.Ptr;
                    int srcIndex = 0;
                    int srcStride = memBmp.Stride;
                    fixed (int* destHead = &buff2[0])
                    {
                        byte* destHead2 = (byte*)destHead;
                        for (int line = 0; line < height; ++line)
                        {
                            //System.Runtime.InteropServices.Marshal.Copy(srcBuffer, srcIndex, (IntPtr)destHead2, destStride);
                            NativeMemMx.memcpy((byte*)destHead2, srcBuffer + srcIndex, destStride);
                            srcIndex += srcStride;
                            destHead2 += destStride;
                        }
                    }
                }
            }
            return buff2;
        }
Example #3
0
 /// <summary>
 /// copy from actual image direct to hBmpScan0
 /// </summary>
 /// <param name="memBmp"></param>
 /// <param name="hBmpScan0"></param>
 public static void CopyToWindowsBitmapSameSize(
     MemBitmap memBmp,
     IntPtr hBmpScan0)
 {
     //1st, fast
     CpuBlit.Imaging.TempMemPtr tmp = MemBitmap.GetBufferPtr(memBmp);
     //System.Runtime.InteropServices.Marshal.Copy(rawBuffer, 0,
     //   hBmpScan0, rawBuffer.Length);
     unsafe
     {
         NativeMemMx.memcpy((byte *)hBmpScan0, (byte *)tmp.Ptr, tmp.LengthInBytes);
     }
 }
Example #4
0
        public static int[] CopyImgBuffer(MemBitmap src, int srcX, int srcY, int srcW, int srcH)
        {
            //calculate stride for the width 
            int destStride = MemBitmap.CalculateStride(srcW, CpuBlit.Imaging.PixelFormat.ARGB32);
            int newBmpW = destStride / 4;

            int[] buff2 = new int[newBmpW * srcH];
            unsafe
            {

                using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = MemBitmap.GetBufferPtr(src))
                {
                    byte* srcBuffer = (byte*)srcBufferPtr.Ptr;
                    int srcIndex = 0;
                    int srcStride = src.Stride;
                    fixed (int* destHead = &buff2[0])
                    {
                        byte* destHead2 = (byte*)destHead;

                        //move to specific src line
                        srcIndex += srcStride * srcY;

                        int lineEnd = srcY + srcH;
                        for (int line = srcY; line < lineEnd; ++line)
                        {
                            //System.Runtime.InteropServices.Marshal.Copy(srcBuffer, srcIndex, (IntPtr)destHead2, destStride);
                            NativeMemMx.memcpy((byte*)destHead2, srcBuffer + srcIndex, destStride);
                            srcIndex += srcStride;
                            destHead2 += destStride;
                        }
                    }
                }
            }

            return buff2;
        }