Exemplo n.º 1
0
    public void Lock()
    {
        if (m_locked)
        {
            throw new Exception("Bitmap already locked.");
        }

        // https://stackoverflow.com/questions/1563038/fast-work-with-bitmaps-in-c-sharp

        Rectangle rect = new Rectangle(0, 0, Width, Height);

        m_bitmapData = BitmapRef.LockBits(rect, ImageLockMode.ReadWrite, BitmapRef.PixelFormat);

        //int rgbValueLength = IsAlphaBitmap ? 4 : 3;
        int rgbValueLength = 4;  // TODO fix this

        m_bitmapSizeBytes = (Width * Height) * rgbValueLength;

#if !USE_UNSAFE_FUNCTIONS
        m_bitmapPtr = m_bitmapData.Scan0;

        if (m_bitmapDataCopy == null || m_bitmapDataCopy.Length != m_bitmapSizeBytes)
        {
            m_bitmapDataCopy = new byte [m_bitmapSizeBytes];
        }

        Marshal.Copy(m_bitmapPtr, m_bitmapDataCopy, 0, m_bitmapDataCopy.Length);
#endif

        m_locked = true;
    }
Exemplo n.º 2
0
    public void Lock()
    {
        if (m_locked)
        {
            throw new Exception("Bitmap already locked.");
        }

        // https://stackoverflow.com/questions/1563038/fast-work-with-bitmaps-in-c-sharp

        Rectangle rect = new Rectangle(0, 0, Width, Height);

        m_bitmapData = BitmapRef.LockBits(rect, ImageLockMode.ReadWrite, BitmapRef.PixelFormat);
        m_bitmapPtr  = m_bitmapData.Scan0;

        int rgbValueLength = IsAlphaBitmap ? 4 : 3;

        int bytes = (Width * Height) * rgbValueLength;

        if (m_rgbValues == null || m_rgbValues.Length != (bytes - 1))
        {
            m_rgbValues = new byte [bytes - 1];
        }

        Marshal.Copy(m_bitmapPtr, m_rgbValues, 0, m_rgbValues.Length);

        m_locked = true;
    }