Tag: picturebox

c#picturebox内存释放问题

我是C#的新手。 我必须在工作线程中重复刷新GUI图片框。 从使用GetImage方法轮询驱动程序的相机获取图像,该方法检索要显示的图像。 即使我使用指令“using”分配位图并显式调用GC,内存似乎永远不会被释放。 工作线程是这样的: while (true) { // request image with IR signal values (array of UInt16) image = axLVCam.GetImage(0); lut = axLVCam.GetLUT(1); DrawPicture(image, lut); //GC.Collect(); } 虽然DrawPicture方法是类似的 public void DrawPicture(object image, object lut) { […] // We have an image – cast it to proper type System.UInt16[,] im = image as System.UInt16[,]; float[] […]

如何在PictureBox上捕获鼠标坐标?

我是c#的新手。 我在图片框上有一个图像,我想在图像上绘制一个矩形来捕捉我将绘制的矩形的X,Y坐标和宽度/高度(对照图片框上的图像)。 我知道我必须在pictureBox1_MouseEnter..etc上做点什么。 但我不知道从哪里开始。 private void pictureBox1_MouseEnter(object sender, EventArgs e) { Rectangle Rect = RectangleToScreen(this.ClientRectangle); } 如果有人能给我示例代码,我将不胜感激。 谢谢。

如何检索WinForms PictureBox的缩放系数?

我需要鼠标指针在PictureBox上的精确位置。 我使用PictureBox的MouseMove事件。 在这个PictureBox上,我使用“缩放”属性来显示图像。 获取鼠标在原始(未经处理)图像上的位置的正确方法是什么? 有没有办法找到比例因子并使用它? 我认为需要使用imageOriginalSize / imageShowedSize来检索此比例因子。 我用这个函数: float scaleFactorX = mypic.ClientSize.Width / mypic.Image.Size.Width; float scaleFactorY = mypic.ClientSize.Height / mypic.Image.Size.Height; 是否可以使用此值来获取光标在图像上的正确位置?

使TextBox透明

我在我的表单中有一个TextBox,我想让它变成透明并显示一个PictureBox中的图片,在它后面,但我怎么能这样做? 谢谢。

在图片框中显示图标

我想在图片框中显示icon file 。 我正在使用此代码来设置图像。 pictureBox1.Image = new Icon(openFileDialog.FileName, new Size(48, 48)).ToBitmap(); 但我得到了这个例外。 System.ArgumentOutOfRangeException: Requested range extends past the end of the array. at System.Runtime.InteropServices.Marshal.CopyToNative(Object source, Int32 startIndex, IntPtr destination, Int32 length) at System.Runtime.InteropServices.Marshal.Copy(Byte[] source, Int32 startIndex, IntPtr destination, Int32 length) at System.Drawing.Icon.ToBitmap() 如何克服这个问题? 谢谢。

将图像切成9块C#

可能重复: 图像分为9个部分 虽然我用Google搜索足够,但遗憾的是没有找到帮助。 此代码项目教程也无法满足我的实际需要。 我在WinForm中有一个Image和9 PictureBox。 Image img = Image.FromFile(“media\\a.png”); // a.png has 312X312 width and height // some code help, to get // img1, img2, img3, img4, img5, img6, img7, img8, img9 // having equal width and height // then… pictureBox1.Image = img1; pictureBox2.Image = img2; pictureBox3.Image = img3; pictureBox4.Image = img4; pictureBox5.Image = […]

从父级在PictureBox上画一条线

我有一个PictureBox作为UserControl 。 我在主窗体上添加了此User Control 。 现在我必须按一个按钮并在用户控件上创建一行。 在我的项目中,每次按下此按钮,我都要向用户发送两个PointF(x和y)的控制参数,并绘制一条新线,此外还有现有线。 到目前为止,我加载了图片框时的Paint事件。 private void pictureBox1_Paint(object sender, PaintEventArgs e) { Pen graphPen = new Pen(Color.Red, 2); PointF pt1D = new PointF(); PointF pt2D = new PointF(); pt1D.X = 0; pt1D.Y = 10; pt2D.X = 10; pt2D.Y = 10; e.Graphics.DrawLine(graphPen, pt1D, pt2D); }

在C#中更快地反转图像

我正在使用WinForms。 我的表格中有一个图片框。 当我在图片框中打开图片时,我可以通过点击按钮来回反转颜色,但我的代码非常慢。 如何提高性能。 private void Button1_Click(object sender, System.EventArgs e) { Bitmap pic = new Bitmap(PictureBox1.Image); for (int y = 0; (y <= (pic.Height – 1)); y++) { for (int x = 0; (x <= (pic.Width – 1)); x++) { Color inv = pic.GetPixel(x, y); inv = Color.FromArgb(255, (255 – inv.R), (255 – inv.G), (255 […]

保持PictureBox在容器内居中

我正在设计一个简单的图片浏览器,能够进行一些基本的图像处理。 目前我遇到的问题是始终将PictureBox保持在TabPage内部,并保持PictureBox的宽度和大小与其显示的图片相同。 到目前为止,我没有成功。 我有以下代码,我在表单构造函数中调用它来将其定位在中心。 它第一次使图片框居中: private void SetPictureBoxOriginalSizeAndLocation(bool makeImageNull = false, DockStyle dockStyle = DockStyle.None) { if (makeImageNull) picBoxView.Image = null; picBoxView.Dock = dockStyle; var xPoint = tabImageView.Location.X + ((splitContainer.Panel2.Width / 2) / 2); var yPoint = tabImageView.Location.Y; var width = tabImageView.Width / 2; var height = (tabImageView.Height / 2) – toolStripImageView.Height; if (picBoxView.Image == […]

使用两种forms缩放

我的项目中有多个表单。 Form1包含一个显示jpeg的pictureBox。 在Form2中,我有一个trackBar,我想控制Form1中图像的缩放级别。 为了简单起见,我只需要2或3个缩放级别。 我在Designer视图中将pictureBox设置为public。 但是,当我尝试在Form2中引用pictureBox时,它表示它不存在。 下面是我用来在Form1中调用Form2的代码 Form2 dataWindow = new Form2(); dataWindow.ShowDialog(); 总之,我需要帮助的两件事是: 1)从单独的表单更改pictureBox1的属性。 2)创建简单的缩放公式。