标签: picturebox

如何在Picturebox上获取滚动条

我有PictureBox picture.

我用:

picture.Size = bmp.Size;
picture.Image = bmp;
Run Code Online (Sandbox Code Playgroud)

假设有两个整数maxWidthmaxHeigth.
我希望picture在其大小超过maxWidth和/或时添加垂直/水平滚动条maxHeight.我怎样才能做到这一点?

c# scroll scrollbar picturebox winforms

62
推荐指数
2
解决办法
7万
查看次数

使图像适合PictureBox

using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
    myDatabaseConnection.Open();
    using (SqlCommand SqlCommand = new SqlCommand("Select Photo from Employee where EmpID LIKE '%' + @EmpID + '%' ", myDatabaseConnection))
    {
        SqlCommand.Parameters.AddWithValue("@EmpID", textBox1.Text);
        DataSet DS = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter(SqlCommand);
        adapter.Fill(DS, "Images");

        var imagesTable = DS.Tables["Images"];
        var imagesRows = imagesTable.Rows;
        var count = imagesRows.Count;

        if (count <= 0)
            return;
        var imageColumnValue =
            imagesRows[count - 1]["Image"];
        if (imageColumnValue == DBNull.Value)
            return;

        var data = (Byte[])imageColumnValue;
        using (var stream = new MemoryStream(data)) …
Run Code Online (Sandbox Code Playgroud)

c# image picturebox winforms

48
推荐指数
6
解决办法
13万
查看次数

39
推荐指数
5
解决办法
14万
查看次数

新Bitmap(filePath)锁定的免费文件

我有一个PictureBox的图像指向某个文件"A".在执行时我想将PictureBox的图像更改为另一个"B"但我收到以下错误:

"mscorlib.dll中出现'System.IO.IOException'类型的第一次机会异常附加信息:进程无法访问文件"A",因为它正由另一个进程使用."

我将Image设置如下:

pbAvatar.Image = new Bitmap(filePath);
Run Code Online (Sandbox Code Playgroud)

如何解锁第一个文件?

c# image file picturebox

38
推荐指数
5
解决办法
4万
查看次数

图片框上的图像清晰

如何清除图片框上的绘图图像?以下对我没有帮助:

pictbox.Image = null;
pictbox.Invalidate();
Run Code Online (Sandbox Code Playgroud)

请帮忙.

编辑

private void pictbox_Paint(object sender, PaintEventArgs e) 
{ 
     Graphics g = e.Graphics; 
     vl.Draw(g, ref tran.realListForInsert); 
} 

public void Draw(Graphics g, ref List<double> arr) 
{ 
    g.DrawRectangle(new Pen(Brushes.Red, 3), nodeArr[Convert.ToInt32(templstName)].pict.Location.X, nodeArr[Convert.ToInt32(templstName)].pict.Location.Y, 25, 25); 
    g.DrawRectangle(new Pen(Brushes.Green, 3), nodeArr[Convert.ToInt32(templstArgName)].pict.Location.X, nodeArr[Convert.ToInt32(templstArgName)].pict.Location.Y, 25, 25); 
    nodeArr[Convert.ToInt32(templstName)].text.Text = arr[Convert.ToInt32(templstArgName)].ToString(); 
    arr[Convert.ToInt32(templstName)] = arr[Convert.ToInt32(templstArgName)]; 
} 
Run Code Online (Sandbox Code Playgroud)

.net c# picturebox winforms

37
推荐指数
6
解决办法
16万
查看次数

打印图像c#.net

我在PictureBox中有一个图像,我想打印它.没有格式化,没有任何东西,只需打印它.

我一直在Google上搜索,但我什么都没有,只有人打印表格或文字或报告.

private string imgSrc;

    public string ImgSrc
    {
        get { return imgSrc; }
        set { imgSrc = value; }
    }

    public Id_Manager()
    {
        ImgSrc = "D:\\Foto.jpg";

        InitializeComponent();
        idPicture.Load(this.ImgSrc);
    }
Run Code Online (Sandbox Code Playgroud)

显然图像会发生变化,但现在我只对打印图像感兴趣.为了以防万一,我将URL保存在属性中.有帮助吗?

c# printing image picturebox

32
推荐指数
2
解决办法
7万
查看次数

从资源加载图像

我想加载这样的图像:

void info(string channel)
{
    //Something like that
    channelPic.Image = Properties.Resources.+channel
}
Run Code Online (Sandbox Code Playgroud)

因为我不想这样做

void info(string channel)
{
    switch(channel)
    {
        case "chan1":
            channelPic.Image = Properties.Resources.chan1;
            break;
        case "chan2":
            channelPic.Image = Properties.Resources.chan2;
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

这样的事情可能吗?

c# resources image picturebox

29
推荐指数
3
解决办法
13万
查看次数

将PictureBox的图像从我的资源更改为图像?

如何从我的资源中将PictureBox图像设置为图像?

(我想这没有成功:pictuerbox.Image = "img_location";)

c# resources image picturebox winforms

26
推荐指数
3
解决办法
16万
查看次数

如何使PictureBox使用最近邻重采样?

我正在使用StretchImage,因为该框可以使用分割器调整大小.看起来默认是某种平滑的双线性滤波,导致我的图像模糊并具有莫尔条纹.

.net c# gdi+ picturebox winforms

24
推荐指数
2
解决办法
1万
查看次数

正确的方式来配置Image/Bitmap和PictureBox

我正在尝试开发Windows Mobile 6(在WF/C#中)应用程序.只有一个表单,表单上只有一个PictureBox对象.在它上面我绘制所有想要的控件或我想要的任何东西.

我正在做两件事.绘制自定义形状并从.png文件加载位图.

下一行在加载时锁定文件(这是一种不受欢迎的情况):

Bitmap bmp = new Bitmap("file.png");
Run Code Online (Sandbox Code Playgroud)

所以我使用另一种方式加载位图.

public static Bitmap LoadBitmap(string path) {
    using (Bitmap original = new Bitmap(path))
    {
        return new Bitmap(original);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我想要慢得多,但我不知道有什么更好的方法来加载图像,同时快速释放文件锁.

现在,在绘制图像时,我使用的方法是:

public void Draw() {
    Bitmap bmp = new Bitmap(240,320);
    Graphics g = Graphics.FromImage(bmp);

    // draw something with Graphics here.
    g.Clear(Color.Black);
    g.DrawImage(Images.CloseIcon, 16, 48);
    g.DrawImage(Images.RefreshIcon, 46, 48);
    g.FillRectangle(new SolidBrush(Color.Black), 0, 100, 240, 103);

    pictureBox.Image = bmp; 
}
Run Code Online (Sandbox Code Playgroud)

然而,这似乎是某种内存泄漏.如果我继续这么做,应用程序最终会崩溃.

因此,我有3个问题:

1.)在不锁定文件的情况下从文件加载位图的更好方法是什么?

2.)需要在Draw()函数中手动处理哪些对象(以及以何种顺序),因此没有内存泄漏且没有抛出ObjectDisposedException?

3.)如果pictureBox.Image设置为bmp,就像代码的最后一行一样,pictureBox.Image.Dispose()只会处理与维护pictureBox.Image或底层Bitmap相关的资源吗?

c# graphics dispose image picturebox

23
推荐指数
2
解决办法
6万
查看次数

标签 统计

c# ×10

picturebox ×10

image ×7

winforms ×5

.net ×3

resources ×2

dispose ×1

file ×1

gdi+ ×1

graphics ×1

loadimage ×1

printing ×1

scroll ×1

scrollbar ×1