当前位置: 首页>>代码示例>>C#>>正文


C# Drawing.Rect类代码示例

本文整理汇总了C#中System.Drawing.Rect的典型用法代码示例。如果您正苦于以下问题:C# Rect类的具体用法?C# Rect怎么用?C# Rect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Rect类属于System.Drawing命名空间,在下文中一共展示了Rect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MeasureString

        /// <summary>
        /// Measure a multiline string
        /// </summary>
        public static Size MeasureString(Graphics gr, Font font, string text, int width)
        {
            if (text == null) return new Size(1, 1);

            Rect bounds = new Rect() { Left = 0, Right = width, Bottom = 1, Top = 0 };
            IntPtr hDc = gr.GetHdc();
            try
            {
                int flags = DTCALCRECT | DTWORDBREAK;
                IntPtr controlFont = font.ToHfont();
                IntPtr originalObject = SelectObject(hDc, controlFont);
                try
                {
                    DrawText(hDc, text, text.Length, ref bounds, flags);
                }
                finally
                {
                    SelectObject(hDc, originalObject); // Release resources
                }
            }
            finally
            {
                gr.ReleaseHdc(hDc);
            }

            return new Size(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
        }
开发者ID:SeregaPru,项目名称:metrohome65,代码行数:30,代码来源:StringHelpers.cs

示例2: GetHearthstoneRect

        public static Rectangle GetHearthstoneRect(bool dpiScaling)
        {
            // Returns the co-ordinates of Hearthstone's client area in screen co-ordinates
            var hsHandle = GetHearthstoneWindow();
            var rect = new Rect();
            var ptUL = new Point();
            var ptLR = new Point();

            GetClientRect(hsHandle, ref rect);

            ptUL.X = rect.left;
            ptUL.Y = rect.top;

            ptLR.X = rect.right;
            ptLR.Y = rect.bottom;

            ClientToScreen(hsHandle, ref ptUL);
            ClientToScreen(hsHandle, ref ptLR);

            if(dpiScaling)
            {
                ptUL.X = (int)(ptUL.X / Helper.DpiScalingX);
                ptUL.Y = (int)(ptUL.Y / Helper.DpiScalingY);
                ptLR.X = (int)(ptLR.X / Helper.DpiScalingX);
                ptLR.Y = (int)(ptLR.Y / Helper.DpiScalingY);
            }

            return new Rectangle(ptUL.X, ptUL.Y, ptLR.X - ptUL.X, ptLR.Y - ptUL.Y);
        }
开发者ID:JulioCL,项目名称:Hearthstone-Deck-Tracker,代码行数:29,代码来源:User32.cs

示例3: ocr

        public static string ocr(Bitmap CropedPrescription, int x, int y, int width, int height)
        {
            string text;

            // var PrescriptionImage = CropedPrescription;
            using (var engine = new TesseractEngine(@"C:\Program Files\Tesseract-OCR\tessdata\", "kor", EngineMode.Default))
            {
                engine.SetVariable("tessedit_char_whitelist", "0123456789-."); // 숫자와 . - 만 인식하도록 설정

                var roi = new Rect(x, y, width, height); // region of interest 좌표를 생성하고
                //     using (var img = Pix.LoadFromFile(PrescriptionImage))
                //      {
                using (var page = engine.Process(CropedPrescription, roi, PageSegMode.SingleLine))
                {
                    text = page.GetText();
                    System.IO.File.WriteAllText(@"C:\Program Files\PLOCR\textrecognition.html", text);  // 인식한 글자를 html 형식으로 저장한다.

                //    text = TextProcess.RemoveWhiteSpace(text);

                    //      Console.WriteLine("인식한 문자: \n{0}\n", text);
                    //   Console.Read();
                }
                //         }
            }

            return text;
        }
开发者ID:linuxbank,项目名称:DocumentAnalysis,代码行数:27,代码来源:OcrEngine.cs

示例4: GetVisibleImage

 public virtual Bitmap GetVisibleImage()
 {
     var compatibleDeviceContext = IntPtr.Zero;
     var deviceContext = IntPtr.Zero;
     IntPtr bitmap = IntPtr.Zero;
     Image img;
     try
     {
         deviceContext = GetWindowDC(windowHandle);
         var rect = new Rect();
         GetWindowRect(windowHandle, ref rect);
         int width = rect.right - rect.left;
         int height = rect.bottom - rect.top;
         compatibleDeviceContext = CreateCompatibleDC(deviceContext);
         bitmap = CreateCompatibleBitmap(deviceContext, width, height);
         IntPtr @object = SelectObject(compatibleDeviceContext, bitmap);
         BitBlt(compatibleDeviceContext, 0, 0, width, height, deviceContext, 0, 0, srccopy);
         SelectObject(compatibleDeviceContext, @object);
     }
     finally
     {
         DeleteDC(compatibleDeviceContext);
         ReleaseDC(windowHandle, deviceContext);
         img = Image.FromHbitmap(bitmap);
         DeleteObject(bitmap);
     }
     using (img) return new Bitmap(img);
 }
开发者ID:EDOlsson,项目名称:White,代码行数:28,代码来源:DisplayedItem.cs

示例5: Capture

        public Bitmap Capture(enmScreenCaptureMode screenCaptureMode = enmScreenCaptureMode.Window)
        {
            Rectangle bounds;

            if (screenCaptureMode == enmScreenCaptureMode.Screen)
            {
            bounds = Screen.GetBounds(Point.Empty);
            CursorPosition = Cursor.Position;
            }
            else
            {
            var foregroundWindowsHandle = GetForegroundWindow();
            var rect = new Rect();
            GetWindowRect(foregroundWindowsHandle, ref rect);
            bounds = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
            CursorPosition = new Point(Cursor.Position.X - rect.Left, Cursor.Position.Y - rect.Top);
            }

            var result = new Bitmap(bounds.Width, bounds.Height);

            using (var g = Graphics.FromImage(result))
            {
            g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
            }

            return result;
        }
开发者ID:Luigifan,项目名称:Skynet,代码行数:27,代码来源:Screenshot.cs

示例6: Notice

 public Notice(Point p, int duration, string txt)
     : base(Game.game, txt)
 {
     pos = p;
     life = duration;
     text = txt;
     float splits = txt.Length / 20f;
     if (splits > 1)
     {
         int upper = (int)Math.Ceiling(splits - 1); //if the number is an integer, take away one, otherwise if there's a decimal portion have it remain
         for (int i = 1; i <= upper; i++)
         {
             int position = i * 20;
             text = text.Insert(position, "\n");
             numberOfLines++;
         }
     }
     texture = new Text(new Size(1024, 768), p);
     texture.textFont = new Font("Myriad Pro", 14);
     texture.Line = text;
     texture.Shadow = false;
     bg = new Rect(new Rectangle(pos, new Size(270 , numberOfLines * 22)));
     bg.Colour = Color.Gray;
     bg.Alpha = .9f;
 }
开发者ID:Zhangerr,项目名称:pulse,代码行数:25,代码来源:Notice.cs

示例7: WndProc

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_SIZING && m.HWnd.Equals(this.Handle))
            {
                Rect r = new Rect();
                r = (Rect)Marshal.PtrToStructure(m.LParam, r.GetType());

                double width = r.Right - r.Left;
                double height = r.Bottom - r.Top;

                if (height / width > aspect_ratio((int)width))
                    width = height / aspect_ratio((int)width);
                else
                    height = width * aspect_ratio((int)width);

                if (m.WParam.ToInt32() == WMSZ_TOP || m.WParam.ToInt32() == WMSZ_TOPLEFT || m.WParam.ToInt32() == WMSZ_TOPRIGHT)
                    r.Top = r.Bottom - (int)height;
                else
                    r.Bottom = r.Top + (int)height;

                if (m.WParam.ToInt32() == WMSZ_LEFT || m.WParam.ToInt32() == WMSZ_TOPLEFT || m.WParam.ToInt32() == WMSZ_BOTTOMLEFT)
                    r.Left = r.Right - (int)width;
                else
                    r.Right = r.Left + (int)width;

                Marshal.StructureToPtr(r, m.LParam, true);
            }

            base.WndProc(ref m);
        }
开发者ID:improvedk,项目名称:Multi-Table-Helper,代码行数:30,代码来源:EditQuadrant.cs

示例8: downloadAvatar

        //first downloadasync didn't work until window was moved for no reason, then threading context issues... ;_;
        /// <summary>
        /// temporarily disabled until avatars are sorted
        /// </summary>
        public void downloadAvatar()
        {
            if (Account.currentAccount != null)
            {
                //if (!string.IsNullOrWhiteSpace(Account.currentAccount.AvatarUrl))
                //{
                avatar = null;
                done = false;
                Thread t = new Thread(new ThreadStart(downloadThread));
                t.IsBackground = true;
                t.Start();
                //   }
            }
            #region obsolete

            /* wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
                wc.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(wc_DownloadFileCompleted);
                wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);

                Console.WriteLine("starting d/l");
              //  HttpWebRequest req = HttpWebRequest.Create("");

                wc.DownloadFileAsync(new Uri("http://rep.ulse.net/uploads/profile/photo-323.gif"), Path.GetTempPath() + "pulsetempavi.jpg");

                Console.WriteLine("started async," + wc.IsBusy);
                //        Console.WriteLine("done downloading avatar");
                //          Image i = Image.FromFile(Path.GetTempPath() + "pulsetempavi.jpg");
                //            avatar = new Rect(new Rectangle(Utils.getMX(800), 10, i.Width, i.Height), Path.GetTempPath() + "pulsetempavi.jpg");
              */
            #endregion
        }
开发者ID:Zhangerr,项目名称:pulse,代码行数:35,代码来源:MenuScreen.cs

示例9: HitObject

 public HitObject(Game game, int offset, Point location)
 {
     this.location = location;
     this.approach = offset - (1200 - (approach * 100));
     texture = new Rect(new Rectangle(location.X - 100, location.Y - 100, 200, 200), Skin.skindict["circle"]);
     approachTexture = new Rect(new Rectangle(location.X - 200, location.Y - 200, 400, 400), Skin.skindict["app"]);
 }
开发者ID:Zhangerr,项目名称:pulse,代码行数:7,代码来源:HitObject.cs

示例10: GetOKBounds

 protected Rect GetOKBounds( )
 {
     IntPtr hwndOK = GetDlgItem ( dia.Handle, 0x0001 );
     Rect retVal = new Rect ( );
     GetWindowRect ( hwndOK, retVal );
     return retVal;
 }
开发者ID:camalot,项目名称:droidexplorer,代码行数:7,代码来源:ExtensionPanel.cs

示例11: SubImage

		/// <summary>
		/// Extracts a rectangular portion of the original image.
		/// </summary>
		/// <param name="bm">The original Bitmap.</param>
		/// <param name="rect">The rectangular portion to extract.</param>
		/// <returns>A new Bitmap containing the selected area.</returns>
		public static Bitmap SubImage(this Bitmap bm, Rect rect)
		{
			return SubImage(bm,
				MathF.RoundToInt(rect.X),
				MathF.RoundToInt(rect.Y),
				MathF.RoundToInt(rect.W),
				MathF.RoundToInt(rect.H));
		}
开发者ID:arajar,项目名称:duality,代码行数:14,代码来源:ExtMethodsBitmap.cs

示例12: GetRememberBounds

 protected Rect GetRememberBounds( )
 {
     IntPtr hwndSysCred = GetDlgItem ( dia.Handle, 0x03EA );
     IntPtr hwndRemember = GetDlgItem ( hwndSysCred, 0x03EF );
     Rect retVal = new Rect ( );
     GetWindowRect ( hwndRemember, retVal );
     return retVal;
 }
开发者ID:camalot,项目名称:droidexplorer,代码行数:8,代码来源:ExtensionPanel.cs

示例13: AdjustSize

 private void AdjustSize()
 {
     var rect = new Rect();
     if (GetClientRect(_parentHandle, ref rect) != 0)
     {
         Size = new Size(rect.Right - rect.Left, rect.Bottom - rect.Top);
     }
 }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:8,代码来源:DockableWindowHost.cs

示例14: GetCGContextForNSView

		internal static CocoaContext GetCGContextForNSView (IntPtr handle) {
			IntPtr graphicsContext = objc_msgSend (objc_getClass ("NSGraphicsContext"), sel_registerName ("currentContext"));
			IntPtr ctx = objc_msgSend (graphicsContext, sel_registerName ("graphicsPort"));
			Rect bounds = new Rect ();

			objc_msgSend_stret (ref bounds, handle, sel_registerName ("bounds"));

			return new CocoaContext (ctx, (int) bounds.size.width, (int) bounds.size.height);
		}
开发者ID:davidwaters,项目名称:mono,代码行数:9,代码来源:macFunctions.cs

示例15: MoveMouseToWoWCoords

        public static bool MoveMouseToWoWCoords(float x, float y, float z)
        {
            var pseudoVec = new Vector3D(x, y, z); //not really a vector. its the location we want to click
            IntPtr hwnd = ProcessManager.WowProcess.WindowHandle; //windowhandle for getting size
            var camera = new CameraInfo();
            //Read information
            uint pAddr2 =
                ProcessManager.WowProcess.ReadUInt((ProcessManager.WowProcess.ReadUInt(
                    ProcessManager.GlobalOffsets.CameraPointer)) +
                        ProcessManager.GlobalOffsets.CameraOffset);
            var bCamera = new byte[68];
            bCamera = ProcessManager.WowProcess.ReadBytes(pAddr2, 68);

            //Convert bytes to usable data
            camera.Pos = new Vector3D(BitConverter.ToSingle(bCamera, 8),
                                    BitConverter.ToSingle(bCamera, 12),
                                        BitConverter.ToSingle(bCamera, 16));
            camera.ViewMat = new Matrix(BitConverter.ToSingle(bCamera, 20),
                BitConverter.ToSingle(bCamera, 24), BitConverter.ToSingle(bCamera, 28),
                BitConverter.ToSingle(bCamera, 32), BitConverter.ToSingle(bCamera, 36),
                BitConverter.ToSingle(bCamera, 40), BitConverter.ToSingle(bCamera, 44),
                BitConverter.ToSingle(bCamera, 48), BitConverter.ToSingle(bCamera, 52));
            camera.Foc = BitConverter.ToSingle(bCamera, 64);
            //Get windoesize
            var rc = new Rect();
            GetClientRect(hwnd, ref rc);

            //Vector camera -> object
            Vector3D Diff = pseudoVec - camera.Pos;

            if ((Diff*camera.ViewMat.getFirstColumn) < 0)
            {
                return false;
            }

            Vector3D View = Diff * camera.ViewMat.inverse();
            var Cam = new Vector3D(-View.Y, -View.Z, View.X);

            float fScreenX = (rc.right - rc.left)/2.0f;
            float fScreenY = (rc.bottom - rc.top)/2.0f;
            //Aspect ratio
            float fTmpX = fScreenX/(float) Math.Tan(((camera.Foc*44.0f)/2.0f)*Deg2Rad);
            float fTmpY = fScreenY/(float) Math.Tan(((camera.Foc*35.0f)/2.0f)*Deg2Rad);

            var pctMouse = new Point();
            pctMouse.X = (int) (fScreenX + Cam.X*fTmpX/Cam.Z);
            pctMouse.Y = (int) (fScreenY + Cam.Y*fTmpY/Cam.Z);

            if (pctMouse.X < 0 || pctMouse.Y < 0 || pctMouse.X > rc.right || pctMouse.Y > rc.bottom)
            {
                return false;
            }

            ProcessManager.CommandManager.MoveMouse(pctMouse.X, pctMouse.Y);
            return true;
        }
开发者ID:iwaitu,项目名称:babbot,代码行数:56,代码来源:GametoScreenCoord.cs


注:本文中的System.Drawing.Rect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。