【解決方法】 system.argumentexception パラメータの解決方法が無効です。 system.drawing.bitmap..ctor(int32 幅、int32 高さ、pixelformat 形式) で

プログラミングQA


i have a project that captures images by basler camera and for this i have a onimagegrabbed Function that grabs image. while running my project in any cpu it i did not getting any error. but when i turned to x86 , project runs but after 2 or 3 seconds I am getting exception message " system.argumentexception parameter is not valid. at system.drawing.bitmap..ctor(int32 width, int32 height, pixelformat format) ."

スクリーンショット-65 — ImgBB[^]

コンソールタブにもこのメッセージを表示する

Exception thrown: 'System.ArgumentException' in System.Drawing.dll

私が試したこと:

private void OnImageGrabbed(object sender, ImageGrabbedEventArgs e)
        {
            bool invokeRequired = base.InvokeRequired;
            if (invokeRequired)
            {
                base.BeginInvoke(new EventHandler<ImageGrabbedEventArgs>(this.OnImageGrabbed), new object[]
                {
                    sender,
                    e.Clone()
                });
            }
            else
            {
                try
                {
                    this.grabResult = e.GrabResult;
                    bool isValid = this.grabResult.IsValid;
                    if (isValid)
                    {
                        bool flag = !this.stopWatch.IsRunning || this.stopWatch.ElapsedMilliseconds > 33L;
                        if (flag)
                        {
                            this.stopWatch.Restart();
                            Bitmap bitmap =  new Bitmap(this.grabResult.Width, this.grabResult.Height, PixelFormat.Format32bppRgb);
                            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
                            this.converter.OutputPixelFormat = PixelType.BGRA8packed;
                            IntPtr scan = bitmapData.Scan0;
                            this.converter.Convert(scan, (long)(bitmapData.Stride * bitmap.Height), this.grabResult);
                            bitmap.UnlockBits(bitmapData);
                            object obj = this.lockObject;
                            lock (obj)
                            {
                                Bitmap bitmap2 = this.DisplayWindow.Image as Bitmap;
                                bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                                this.gb = this.CreateNonIndexedImage(bitmap);
                                this.DisplayWindow.Image = bitmap;
                                bool flag3 = bitmap2 != null;
                                if (flag3)
                                {
                                    bitmap2.Dispose();



                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    e.DisposeGrabResultIfClone();
                }
            }
        }
the line:150 is " Bitmap bitmap = new Bitmap(this.grabResult.Width, this.grabResult.Height, PixelFormat.Format32bppRgb);"

解決策 1

わかりません: コンストラクターに渡す 3 つのパラメーターの 1 つが無効です。つまり、どれが無効であるかを判断する前に、これらの値が正確に何であるかを確認する必要があります。 どうして.

だから、それはあなた次第になるでしょう。
幸いなことに、何が起こっているのかを調べるのに役立つツール、デバッガーを利用できます。 使い方がわからない場合は、Google で「Visual Studio デバッガー」を検索すると、必要な情報が得られます。

エラー行にブレークポイントを置き、デバッガーでコードを実行します。 ブレークポイントに到達したときのパラメーター値を調べ、有効な値の範囲と照合します。 どちらが間違っているかがわかったら、コードとデータを見て、何が起こるべきかを手動で判断できます。 次に、各行を 1 ステップ実行して、予想どおりの動作を確認します。 そうでない場合は、問題が発生したときであり、後戻りして (またはもう一度実行して詳しく調べて) 原因を突き止めることができます。

申し訳ありませんが、私たちはあなたにそれを行うことはできません – 新しい (そして非常に便利な) スキルを学ぶ時が来ました: デバッグ!

コメント

タイトルとURLをコピーしました