小编Oza*_*_AB的帖子

"此BackgroundWorker表示它不会报告进度." - 为什么?

我是这个背景工作者的新手
我已经阅读了一些关于如何创建一个
这就是它产生的文章

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        Bitmap imgbox = new Bitmap(pictureBox.Image);

        int imgHeight = imgbox.Height;
        int imgWidth = imgbox.Width;

        int counter = 1;

        MinMaxWidth = imgWidth - 50;
        MaxWidth = imgWidth;

        try
        {
            Color c;
            //Color c2;

            for (int i = 0; i < imgbox.Width; i++)
            {
                for (int j = 0; j < imgbox.Height; j++)
                {
                    c = imgbox.GetPixel(i, j);
                    string cn = c.Name;
                    counter++;
                    backgroundWorker1.ReportProgress(counter);
                }
            }
            MessageBox.Show("SUCESSFULLY DONE");
        }
        catch (Exception ex) { …
Run Code Online (Sandbox Code Playgroud)

c# backgroundworker

32
推荐指数
1
解决办法
3万
查看次数

覆盖现有图像

我有这个代码

    private void saveImage()
    {
        Bitmap bmp1 = new Bitmap(pictureBox.Image);
        bmp1.Save("c:\\t.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
        // Dispose of the image files.
        bmp1.Dispose();
    }
Run Code Online (Sandbox Code Playgroud)

我已经在我的驱动器"c:\"上有一个图像t.jpg. 我希望每次程序运行时都用新图像替换它.但是GDI +错误显示 我怎么能解决它?

c# image bitmap

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

无法将类型'System.Drawing.Image'隐式转换为'System.Drawing.Bitmap'

声明了一个位图

private Bitmap img1 = null;  
private Bitmap img2 = null;  
Run Code Online (Sandbox Code Playgroud)

openFileDialog中选择后,图像将被推送.
选定的图像被放置在一个数组中.

imgName = openFD.FileNames;
Run Code Online (Sandbox Code Playgroud)

然后按钮1显示这些图像.

pictureBox1.Image = Image.FromFile(imgName[0]);  
pictureBox2.Image = Image.FromFile(imgName[1]);
Run Code Online (Sandbox Code Playgroud)

我用这个替换了button1代码

img1 = Image.FromFile(imgName[0]);  
img2 = Image.FromFile(imgName[1]);
Run Code Online (Sandbox Code Playgroud)

但是会发生错误

无法将类型'System.Drawing.Image'隐式转换为'System.Drawing.Bitmap'

我试着将代码更改为img1 = Bitmap.FromFile(imgName[0]);.但仍然有同样的错误.
有任何建议如何纠正或做到这一点?

.net c# bitmap

5
推荐指数
1
解决办法
3万
查看次数

TargetInvocationException未处理 - c#

我真的无法弄清楚发生了什么以及它为什么会一直发生
异常被调用的目标抛出.

代码在frm5中运行

那么错误显示在
Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace BlueStitch
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }
    }
}  
Run Code Online (Sandbox Code Playgroud)

它是在线 Application.Run(new frmMain());

它说 TargetInvocationException was unhandled - Exception has been thrown by the target of an invocation.

这个例外

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Parameter is …
Run Code Online (Sandbox Code Playgroud)

c# winforms

5
推荐指数
1
解决办法
9406
查看次数

SQL Server字符串填充插入空格 - 为什么?

当我试图将一些数据插入SQL Server时,有这些额外的字符

例如我textBox1.text == "SAMPLE"
当时这是代码

string qry = "insert into FinalImages (FinalImageName, Date) values(@FinalImageName, @Date)";

SqlConnection c = new SqlConnection(c_string);
//Initialize SqlCommand object for insert
SqlCommand SqlCom = new SqlCommand(qry, c);

SqlCom.Parameters.Add(new SqlParameter("@FinalImageName", SqlDbType.Char, 40)).Value = textBox1.Text;
SqlCom.Parameters.Add(new SqlParameter("@Date", SqlDbType.Char, 40)).Value = DateTime.Now.ToString("MM/dd/yyyy");
Run Code Online (Sandbox Code Playgroud)

但是当我在表中检查记录是这样的时候"SAMPLE ",它添加 了34个空格字符
应该是什么错误?

c# sql-server sqldatatypes

4
推荐指数
3
解决办法
4254
查看次数

清除PictureBox - c#

我想修改这个PictureBox数组项目.我想放一个重置按钮,而不是清除PictureBox Array它创建的所有
更多可能表格将从头开始再次为空.

这是它的一些代码;

        // Function to add PictureBox Controls
    private void AddControls(int cNumber)
    {
        imgArray = new System.Windows.Forms.PictureBox[cNumber]; // assign number array 
        for (int i = 0; i < cNumber; i++)
        {
            imgArray[i] = new System.Windows.Forms.PictureBox(); // Initialize one variable
        }
        // When call this function you determine number of controls
    }  

    private void ImagesInFolder()
    {
        FileInfo FInfo;
        // Fill the array (imgName) with all images in any folder 
        imgName = Directory.GetFiles(Application.StartupPath  + @"\Images");
        // …
Run Code Online (Sandbox Code Playgroud)

c# winforms

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