Esempio n. 1
0
        private void DrawBitmapToDesktop(SourceBitmap bitmap)
        {
            gDesktop.DrawImageFitOutside(bitmaps[0].Bitmap, allScreen.AdjustedVirtualDesktop);

            bitmap.Save();
            bitmap.Apply();
        }
Esempio n. 2
0
        private void DrawBitmapToDesktop(SourceBitmap bitmap, int screenNumber)
        {
            Rectangle screen = allScreen.AllScreens[screenNumber].AdjustedBounds;
            int bitmapWidth = bitmap.Bitmap.Width;
            int bitmapHeight = bitmap.Bitmap.Height;

            if (s.IsNotStretch
                && (bitmapWidth < screen.Width || bitmapHeight < screen.Height))
            {
                int srcX;
                int srcWidth;
                int srcY;
                int srcHeight;
                if (bitmapWidth <= screen.Width)
                {
                    srcX = 0;
                    srcWidth = bitmapWidth;
                }
                else //bitmapWidth > bounds.Width
                {
                    srcX = (bitmapWidth - screen.Width) / 2;
                    srcWidth = screen.Width;
                }
                if (bitmapHeight <= screen.Height)
                {
                    srcY = 0;
                    srcHeight = bitmapHeight;
                }
                else //bitmapHeight > bounds.Height
                {
                    srcY = (bitmapHeight - screen.Height) / 2;
                    srcHeight = screen.Height;
                }
                Rectangle src = new Rectangle(srcX, srcY, srcWidth, srcHeight);

                //get edge color
                Color bgColor;
                try
                {
                    const int pickingPointNum = 5;
                    int R = 0;
                    int G = 0;
                    int B = 0;
                    for (int x = 0; x < pickingPointNum; x++)
                    {
                        var c = bitmap.Bitmap.GetPixel(((srcWidth - 1) / pickingPointNum) * x + srcX, srcY);
                        R += c.R;
                        G += c.G;
                        B += c.B;

                        c = bitmap.Bitmap.GetPixel(((srcWidth - 1) / pickingPointNum) * x + srcX, srcY + srcHeight - 1);
                        R += c.R;
                        G += c.G;
                        B += c.B;
                    }
                    for (int y = 1; y < pickingPointNum - 1; y++)
                    {
                        var c = bitmap.Bitmap.GetPixel(srcX, ((srcHeight - 1) / pickingPointNum) * y + srcY);
                        R += c.R;
                        G += c.G;
                        B += c.B;

                        c = bitmap.Bitmap.GetPixel(srcX + srcWidth - 1, ((srcHeight - 1) / pickingPointNum) * y + srcY);
                        R += c.R;
                        G += c.G;
                        B += c.B;
                    }
                    R /= pickingPointNum * 4 - 4; //2n + 2*(n - 2)
                    G /= pickingPointNum * 4 - 4;
                    B /= pickingPointNum * 4 - 4;

                    bgColor = Color.FromArgb(R, G, B);
                }
                catch
                {
                    bgColor = Color.Black;
                }

                using (var brush = new SolidBrush(bgColor))
                {
                    gDesktop.FillRectangle(brush, screen);
                }

                gDesktop.DrawImage(bitmap.Bitmap, (screen.Width - srcWidth) / 2 + screen.X, (screen.Height - srcHeight) / 2 + screen.Y, src, GraphicsUnit.Pixel);
            }
            else
            {
                gDesktop.DrawImageFitOutside(bitmap.Bitmap, screen);
            }

            bitmap.Save();
            bitmap.Apply();
        }
Esempio n. 3
0
        public void AddBitmap(SourceBitmap bitmap)
        {
            if (gDesktop == null
                || CanAddAnotherBitmap == false)
            {
                throw new InvalidOperationException();
            }

            if (bitmap.CheckResolutionLowerLimit())
            {
                if (bitmap.CheckStretchForMultiScreen()
                    || s.IsEachScreenEachSource == false)
                {
                    bitmaps.Clear();
                    bitmaps.Add(bitmap);

                    CanAddAnotherBitmap = false;
                }
                else
                {
                    if (bitmaps.Count < allScreen.AllScreens.Length)
                    {
                        bitmaps.Add(bitmap);
                    }

                    if (bitmaps.Count >= allScreen.AllScreens.Length)
                    {
                        CanAddAnotherBitmap = false;
                    }
                }
            }
        }