Пример #1
0
        // Control events----------------------------------------------------------------------------
        private void PhotoBox_Paint(object sender, PaintEventArgs e)
        {
#if USE_GDI
            if (_hUsingMemDc == IntPtr.Zero)
            {
                return;
            }
#else
            if (_usingMemBitmap == null)
            {
                return;
            }
#endif
            Graphics gScreen = this.CreateGraphics();
#if USE_GDI
            IntPtr hDc = gScreen.GetHdc();
            Win32GDISupport.BitBlt(hDc, _usingBitmapPosition.X, _usingBitmapPosition.Y, _usingBitmapSize.Width, _usingBitmapSize.Height,
                                   _hUsingMemDc, 0, 0, Win32GDISupport.TernaryRasterOperations.SRCCOPY);
            //int result =Win32GDISupport.GetLastError();
            //Trace.WriteLine("Area repainted... result: " + result + " Pos: " + _usingBitmapPosition.ToString() + " Size: " + _usingBitmapSize.ToString());
            gScreen.ReleaseHdc();
#else
            gScreen.DrawImage(_usingMemBitmap, _usingBitmapOffset.Width, _usingBitmapOffset.Height);
#endif
            gScreen.Dispose();
            _canEraseBkgd = true;
        }
Пример #2
0
 public void FinalizeGDI()
 {
     if (_hFirstMemDc != IntPtr.Zero)
     {
         Win32GDISupport.DeleteDC(_hFirstMemDc);
     }
     if (_hSecondMemDc != IntPtr.Zero)
     {
         Win32GDISupport.DeleteDC(_hSecondMemDc);
     }
 }
Пример #3
0
 public void InitializeGDI()
 {
     if (_hFirstMemDc == IntPtr.Zero || _hSecondMemDc == IntPtr.Zero)
     {
         Graphics g   = this.CreateGraphics();
         IntPtr   hDc = g.GetHdc();
         if (_hFirstMemDc == IntPtr.Zero)
         {
             _hFirstMemDc = Win32GDISupport.CreateCompatibleDC(hDc);
         }
         if (_hSecondMemDc == IntPtr.Zero)
         {
             _hSecondMemDc = Win32GDISupport.CreateCompatibleDC(hDc);
         }
         g.ReleaseHdc();
     }
 }
Пример #4
0
        private void ScrollPhoto(int offsetX, int offsetY)
        {
            Rectangle clientRect = ClientRectangle;
            // check if the moved bitmap will exceed the confine of client area
            int x = _usingBitmapPosition.X, y = _usingBitmapPosition.Y;
            int bitmapWidth, bitmapHeight;

#if USE_GDI
            bitmapWidth  = _usingBitmapSize.Width;
            bitmapHeight = _usingBitmapSize.Height;
#else
            bitmapWidth  = _usingMemBitmap.Width;
            bitmapHeight = _usingMemBitmap.Height;
#endif
            if (bitmapWidth > clientRect.Width)
            {
                x = _usingBitmapPosition.X + offsetX;
                if (x < clientRect.Width - bitmapWidth)
                {
                    x = clientRect.Width - bitmapWidth;
                }
                else if (x > 0)
                {
                    x = 0;
                }
            }
            if (bitmapHeight > clientRect.Height)
            {
                y = _usingBitmapPosition.Y + offsetY;
                if (y < clientRect.Height - bitmapHeight)
                {
                    y = clientRect.Height - bitmapHeight;
                }
                else if (y > 0)
                {
                    y = 0;
                }
            }
            offsetX = x - _usingBitmapPosition.X;
            offsetY = y - _usingBitmapPosition.Y;
            if (offsetX == 0 && offsetY == 0)
            {
                return;
            }

            Win32GDISupport.ScrollWindow(this.Handle, offsetX, offsetY, ref clientRect, ref clientRect);
            _canEraseBkgd = false;

            UpdatePhotoPosition(new Size(offsetX, offsetY));
            // if photo list should be updated, then set this event
            UpdatePhotoShowPointers();
            if (PhotoListNeedUpdate() && !_isBitmapUpdated)
            {
                _photoListUpdateEvent.Set();
            }

            //// Performance measurement
            //_scrollOffset.Width += offsetX;
            //_scrollOffset.Height += offsetY;
            //_scrollCount++;
            //int milSeconds = _scrollWatch.Elapsed.Milliseconds;
            //if (milSeconds > 0)
            //{
            //    StringBuilder sb = new StringBuilder();
            //    sb.AppendFormat("Scroll: X-{0} pix/s Y-{1} pix/s {2} times/s", offsetX * 1000 / milSeconds,
            //        offsetY * 1000 / milSeconds, _scrollCount * 1000 / milSeconds);
            //    Trace.WriteLine(sb.ToString());
            //}
        }
Пример #5
0
        private void CreateOffScreenBitmap(ref IntPtr hMemDc)
        {
            int bitmapWidth = 0, bitmapHeight = 0;
            //Caculate the cached bitmap size
            LinkedListNode <Photo> node = _photos.First;
            Photo photo;

            do
            {
                photo         = node.Value;
                bitmapWidth   = System.Math.Max(bitmapWidth, photo.Width);
                bitmapHeight += photo.Height + PhotoInterval;
            } while ((node = node.Next) != null);

            if (hMemDc == _hFirstMemDc)
            {
                _firstBitmapSize.Width  = bitmapWidth;
                _firstBitmapSize.Height = bitmapHeight;
            }
            else
            {
                _secondBitmapSize.Width  = bitmapWidth;
                _secondBitmapSize.Height = bitmapHeight;
            }
            // Create bimap
            Graphics g         = this.CreateGraphics();
            IntPtr   hDc       = g.GetHdc();
            IntPtr   hBitmap   = Win32GDISupport.CreateCompatibleBitmap(hDc, bitmapWidth, bitmapHeight);
            IntPtr   hOldBimap = Win32GDISupport.SelectObject(hMemDc, hBitmap);

            if (hOldBimap != IntPtr.Zero)
            {
                Win32GDISupport.DeleteObject(hOldBimap);
            }
            IntPtr hPhotoDc = Win32GDISupport.CreateCompatibleDC(hDc);

            g.ReleaseHdc();
            //g.FillRectangle(_bkgdBrush, 0, 0, bitmap.Width, bitmap.Height);

            Graphics gMem = Graphics.FromHdc(hMemDc);

            node = _photos.First;
            Rectangle rectPhoto    = Rectangle.Empty;
            PointF    textLocation = new PointF(100, 100);

            do
            {
                photo          = node.Value;
                rectPhoto.Size = photo.Size;
                IntPtr hPhoto;
                if (photo is ManagedPhoto)
                {
                    hPhoto = photo.GetBitmap().GetHbitmap();
                }
                else if (photo is NativePhoto)
                {
                    hPhoto = photo.GetHBitmap();
                }
                else
                {
                    throw new NotSupportedException("Native bitmap is not supported by the photo class");
                }
                Win32GDISupport.SelectObject(hPhotoDc, hPhoto);
                Win32GDISupport.SetStretchBltMode(hMemDc, Win32GDISupport.StretchBltMode.HALFTONE);
                Win32GDISupport.StretchBlt(hMemDc, rectPhoto.X, rectPhoto.Y, rectPhoto.Width, rectPhoto.Height,
                                           hPhotoDc, 0, 0, photo.UnZoomWidth, photo.UnZoomHeight, Win32GDISupport.TernaryRasterOperations.SRCCOPY);
                if (photo is ManagedPhoto)
                {
                    Win32GDISupport.DeleteObject(hPhoto);
                }

                //gMem.DrawImage(photo.Bitmap, rectPhoto);
                gMem.DrawString(photo.Number.ToString(), SystemFonts.DefaultFont, Brushes.White, textLocation);
                textLocation.Y += rectPhoto.Height + PhotoInterval;
                rectPhoto.Y    += rectPhoto.Height + PhotoInterval;
            } while ((node = node.Next) != null);
            Win32GDISupport.DeleteDC(hPhotoDc);
            gMem.Dispose();
            Trace.WriteLine("++++++Bitmap created, photo number " + _photos.First().Number +
                            " to " + _photos.Last().Number);
            GC.Collect();
        }
Пример #6
0
 override public void Dispose()
 {
     Win32GDISupport.DeleteObject(_hBitmap);
 }