我正在设计一个简单的图片浏览器,能够进行一些基本的图像处理.目前我的问题PictureBox是TabPage始终保持居中,并保持图片框的宽度和大小与其显示的图片相同.到目前为止,我没有成功.
我有以下代码,我在表单构造函数中调用它来将其定位在中心.它第一次使图片框居中:
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 == null) return;
//Resize image according to width
picBoxView.Image = ImageMethods.ResizeImage(picBoxView.Image.Tag.ToString(), width, height, false);
picBoxView.Location = new Point(xPoint, yPoint);
picBoxView.Width = width;
picBoxView.Height = height; …Run Code Online (Sandbox Code Playgroud) 我有一个装有图片的图片框,我想在单击图像时读取位置(如图片框中的x,y); 这可能吗 ?更重要的是,当我鼠标悬停时,我可以读取这些坐标(点数)吗?
我知道我必须使用给定的事件(鼠标单击和鼠标悬停),但不知道如何读取鼠标指针恰好是的坐标.
我是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();
}
Run Code Online (Sandbox Code Playgroud)
虽然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[] lutTempConversion = lut as float[];
int lngWidthIrImage = im.GetLength(0);
int lngHeightIrImage = im.GetLength(1);
using (Bitmap bmp = new Bitmap(lngWidthIrImage, lngHeightIrImage)) {
[...many operation on bitmap pixel...]
// Bitmap …Run Code Online (Sandbox Code Playgroud) 我有点问题.
假设我在pictureBox上写了一个椭圆,然后点击一个按钮.我想要pictureBox刷新自己.
我试过了PictureBox.Invalidate(),但不能成功.我最诚挚的问候...
可能重复:
图像分为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 = img5;
pictureBox6.Image = img6;
pictureBox7.Image = img7;
pictureBox8.Image = img8;
pictureBox9.Image = img9;
Run Code Online (Sandbox Code Playgroud)
这是一个示例图像为您:

这是我的Picture Puzzle类项目的一部分.我已经完成了photoshop图片,现在想动态剪切.
提前致谢.
我目前正在与AForge合作,并有一个新的帧事件,将帧作为位图发布到图片框中.它有90%的时间很棒......除非我在winform上捣乱.更改组合框,移动窗口或任何类似的风险会导致Picturebox从视频切换到大红色X.下面的代码示例:
private void connectButton_Click(object sender, EventArgs e)
{
try
{
cam = new VideoCaptureDevice(captureDevices[CameraSelectComboBox.SelectedIndex].MonikerString);
cam.NewFrame -= Handle_New_Frame; //Just to avoid the possibility of a second event handler being put on
cam.NewFrame += new AForge.Video.NewFrameEventHandler(Handle_New_Frame);
cam.Start();
}
catch
{
MessageBox.Show("An error has occured with connecting to the specified webcam. The application will now close!");
Application.Exit();
}
}
private void Handle_New_Frame(object sender, NewFrameEventArgs eventArgs)
{
try
{
if (bitmap != null)
bitmap.Dispose(); //Without this, memory goes nuts
bitmap = new Bitmap(eventArgs.Frame);
} …Run Code Online (Sandbox Code Playgroud) 我有两个问题:
1)我有一个PictureBox,它的Dock设置为Fill.当我调整大小时,Form我无法在PictureBox扩展的部分创建图形.问题是什么?
2)我想转换是在创建的图形PictureBox来Bitmap并将其保存为*.jpg或*.BMP.我怎样才能做到这一点?
我需要鼠标指针在PictureBox上的精确位置.
我使用PictureBox的MouseMove事件.
在这个PictureBox上,我使用"缩放"属性来显示图像.
获取原始(未经处理)图像上鼠标位置的正确方法是什么?
有没有办法找到比例因子并使用它?
我认为需要使用imageOriginalSize/imageShowedSize来检索此比例因子.
我用这个函数:
float scaleFactorX = mypic.ClientSize.Width / mypic.Image.Size.Width;
float scaleFactorY = mypic.ClientSize.Height / mypic.Image.Size.Height;
Run Code Online (Sandbox Code Playgroud)
是否可以使用此值来获取光标在图像上的正确位置?
在我的Winforms应用程序中,它通过Linq连接到数据库到SQL我将图像(总是*.png)保存到一个如下所示的表:
CREATE TABLE [dbo].[Images] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Bild] IMAGE NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
Run Code Online (Sandbox Code Playgroud)
在我可以存储图片之前,我必须将其转换byte[]为以及我是这样做的:
public static byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
using (MemoryStream ms = new MemoryStream())
{
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
}
Run Code Online (Sandbox Code Playgroud)
之后,如果我想将这个相同的图像加载到我的应用程序中的PictureBox,我将使用此方法将其转换回来:
public static Image ByteArrayToImage(byte[] byteArrayIn)
{
using (MemoryStream ms = new MemoryStream(byteArrayIn))
{
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}
Run Code Online (Sandbox Code Playgroud)
它确实有效,当我尝试在Picturebox中显示数据库中的图像时,会出现唯一的问题.
所以当我将这个Image加载到数据库时:

后来我尝试显示它.它突然看起来像这样:
我已经尝试了PictureBox的所有可能的SizeMode设置(Normal,Stretchimage,AutoSize,CenterImage,Zoom),它仍然看起来像这样.
以下是我如何将图像从数据库加载到pictureBox:
首先,我通过id检索属于集合的所有图像:
public static ImageList GetRezeptImages(int rezeptId)
{
using (CookBookDataContext …Run Code Online (Sandbox Code Playgroud) 在我的代码中,我从一个带有指向非托管对象的指针的相机中检索帧,对它进行一些计算然后我在一个图片框控件上显示它.
在我进一步介绍这个应用程序的所有细节之前,我想确保这个过程的基本代码是好的.特别是我想:
- 尽量减少执行时间并避免不必要的操作,例如复制超出必要的图像.我想只保留必要的操作
- 了解每一帧的计算过程中的延迟是否会对图像的显示方式产生不利影响(即,如果它没有按照我的预期打印)或者某些图像被跳过
- 防止出现更严重的错误,例如由于内存或线程管理或图像显示.
为此,我设置了几个实验代码行(如下),但我无法解释我发现的结果.如果你有OpenCv的可执行文件,你可以自己尝试一下.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
public partial class FormX : Form
{
private delegate void setImageCallback();
Bitmap _bmp;
Bitmap _bmp_draw;
bool _exit;
double _x;
IntPtr _ImgBuffer;
bool buffercopy;
bool copyBitmap;
bool refresh;
public FormX()
{
InitializeComponent();
_x = 10.1;
// set experimemental parameters
buffercopy = false;
copyBitmap = false;
refresh = true;
}
private void buttonStart_Click(object sender, EventArgs e)
{
Thread camThread = new …Run Code Online (Sandbox Code Playgroud) c# ×10
picturebox ×10
winforms ×5
bitmap ×2
image ×2
.net ×1
aforge ×1
camera ×1
coordinates ×1
memory-leaks ×1
mouse ×1
mouseover ×1
opencv ×1
png ×1
zoom ×1