Exemplo n.º 1
0
        protected void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            bitmap.Dispose();
            byteArray.ReleaseReference();
            disposed = true;

            //Set managed object refs to null if explicitly disposing, so that they can be cleaned up by the GC.
            if (disposing)
            {
                owner  = null;
                bitmap = null;
            }
        }
Exemplo n.º 2
0
        public override void SetImage(Bitmap theBitmap)
        {
            mImage = theBitmap;
            if (theBitmap != null)
            {
                mEditableBitmap = new EditableBitmap(theBitmap);

                //cache data in member variables to decrease overhead of property calls
                //this is especially important with Width and Height, as they call
                //GdipGetImageWidth() and GdipGetImageHeight() respectively in gdiplus.dll -
                //which means major overhead.
                bitmapStride          = mEditableBitmap.Stride;
                bitmapPixelFormatSize = mEditableBitmap.PixelFormatSize;
                bitmapBits            = mEditableBitmap.Bits;
                bitmapWidth           = mEditableBitmap.Bitmap.Width;
                bitmapHeight          = mEditableBitmap.Bitmap.Height;
            }
        }
Exemplo n.º 3
0
        public void SetImage(Bitmap theBitmap)
        {
            if (theBitmap != null)
            {
                // TODO: how to dispose previous image?  if TestSequences have a reference, it should be to a View of this one?
                mEditableBitmap = new EditableBitmap(theBitmap);

                /*
                 * //cache data in member variables to decrease overhead of property calls
                 * //this is especially important with Width and Height, as they call
                 * //GdipGetImageWidth() and GdipGetImageHeight() respectively in gdiplus.dll -
                 * //which means major overhead.
                 * bitmapStride = mEditableBitmap.Stride;
                 * bitmapPixelFormatSize = mEditableBitmap.PixelFormatSize;
                 * bitmapBits = mEditableBitmap.Bits;
                 * bitmapWidth = mEditableBitmap.Bitmap.Width;
                 * bitmapHeight = mEditableBitmap.Bitmap.Height;
                 */
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an <see cref="EditableBitmap"/> as a view on a section of an existing <see cref="EditableBitmap"/>.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="viewArea"></param>
        protected EditableBitmap(EditableBitmap source, Rectangle viewArea)
        {
            owner           = source;
            pixelFormatSize = source.pixelFormatSize;
            byteArray       = source.byteArray;
            byteArray.AddReference();
            stride = source.stride;

            try
            {
                startOffset = source.startOffset + (stride * viewArea.Y) + (viewArea.X * pixelFormatSize);
                bitmap      = new Bitmap(viewArea.Width, viewArea.Height, stride, source.Bitmap.PixelFormat,
                                         (IntPtr)(((int)byteArray.bitPtr) + startOffset));
            }
            finally
            {
                if (bitmap == null)
                {
                    byteArray.ReleaseReference();
                }
            }
        }