前提・実現したいこと
C++/CLI、opencvを用いてボタンを押すと画像をpictureboxに表示させるwindowsフォームアプリケーションの作成をしています。
imreadで画像を読み込んでビットマップにかえて画像を表示させようとしています。
エラーなく実行はできるのですがフォームのボタンを押すと「ハンドルされていない例外が発生しました。使用されたパラメーターが有効ではありません。」というウィンドウが表示されてしまいます。
何か案があれば教えていただきたいです。
発生している問題・エラーメッセージ
Just-In-Time (JIT) デバッグを呼び出すための詳細については、 ダイアログ ボックスではなく、このメッセージの最後を参照してください。 ************** 例外テキスト ************** System.ArgumentException: 使用されたパラメーターが有効ではありません。 場所 System.Drawing.Bitmap..ctor(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0) 場所 test.MyForm.drawImage(PictureBox pic, Mat* mat) 場所 c:\users\aselab\documents\visual studio 2015\projects\test\test\myform.h:行 112 場所 test.MyForm.button1_Click(Object sender, EventArgs e) 場所 c:\users\aselab\documents\visual studio 2015\projects\test\test\myform.h:行 121 場所 System.Windows.Forms.Control.OnClick(EventArgs e) 場所 System.Windows.Forms.Button.OnClick(EventArgs e) 場所 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 場所 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 場所 System.Windows.Forms.Control.WndProc(Message& m) 場所 System.Windows.Forms.ButtonBase.WndProc(Message& m) 場所 System.Windows.Forms.Button.WndProc(Message& m) 場所 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 場所 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 場所 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) ************** 読み込まれたアセンブリ ************** mscorlib アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3324.0 built by: NET472REL1LAST_C コードベース:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll ---------------------------------------- test アセンブリ バージョン:0.0.0.0 Win32 バージョン: コードベース:file:///c:/users/aselab/documents/visual%20studio%202015/Projects/test/Debug/test.exe ---------------------------------------- System アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3353.0 built by: NET472REL1LAST_B コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll ---------------------------------------- System.Windows.Forms アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3324.0 built by: NET472REL1LAST_C コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- System.Drawing アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3190.0 built by: NET472REL1LAST_C コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ---------------------------------------- System.Configuration アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3324.0 built by: NET472REL1LAST_C コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll ---------------------------------------- System.Core アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3324.0 built by: NET472REL1LAST_C コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll ---------------------------------------- System.Xml アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3190.0 built by: NET472REL1LAST_C コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- System.Drawing.resources アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3190.0 built by: NET472REL1LAST_C コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing.resources/v4.0_4.0.0.0_ja_b03f5f7f11d50a3a/System.Drawing.resources.dll ---------------------------------------- System.Windows.Forms.resources アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3190.0 built by: NET472REL1LAST_C コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_ja_b77a5c561934e089/System.Windows.Forms.resources.dll ---------------------------------------- mscorlib.resources アセンブリ バージョン:4.0.0.0 Win32 バージョン:4.7.3190.0 built by: NET472REL1LAST_C コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_ja_b77a5c561934e089/mscorlib.resources.dll ---------------------------------------- ************** JIT デバッグ ************** Just-In-Time (JIT) デバッグを有効にするには、このアプリケーション、 またはコンピューター (machine.config) の構成ファイルの jitDebugging 値を system.windows.forms セクションで設定しなければなりません。 アプリケーションはまた、デバッグを有効にしてコンパイルされなければ なりません。 例: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> JIT デバッグが有効なときは、このダイアログ ボックスで処理するよりも、 ハンドルされていない例外はすべてコンピューターに登録された JIT デバッガーに設定されなければなりません。
該当のソースコード
MyForm.h
c++
1#pragma once 2 3#include "opencv2\opencv.hpp" 4 5using namespace cv; 6 7 8 9namespace test { 10 11 using namespace System; 12 using namespace System::ComponentModel; 13 using namespace System::Collections; 14 using namespace System::Windows::Forms; 15 using namespace System::Data; 16 using namespace System::Drawing; 17 18 /// <summary> 19 /// MyForm の概要 20 /// </summary> 21 public ref class MyForm : public System::Windows::Forms::Form 22 { 23 public: 24 MyForm(void) 25 { 26 InitializeComponent(); 27 // 28 //TODO: ここにコンストラクター コードを追加します 29 // 30 } 31 32 protected: 33 /// <summary> 34 /// 使用中のリソースをすべてクリーンアップします。 35 /// </summary> 36 ~MyForm() 37 { 38 if (components) 39 { 40 delete components; 41 } 42 } 43 private: System::Windows::Forms::PictureBox^ pictureBox1; 44 private: System::Windows::Forms::Button^ button1; 45 protected: 46 47 private: 48 /// <summary> 49 /// 必要なデザイナー変数です。 50 /// </summary> 51 System::ComponentModel::Container ^components; 52 53#pragma region Windows Form Designer generated code 54 /// <summary> 55 /// デザイナー サポートに必要なメソッドです。このメソッドの内容を 56 /// コード エディターで変更しないでください。 57 /// </summary> 58 void InitializeComponent(void) 59 { 60 this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); 61 this->button1 = (gcnew System::Windows::Forms::Button()); 62 (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit(); 63 this->SuspendLayout(); 64 // 65 // pictureBox1 66 // 67 this->pictureBox1->Location = System::Drawing::Point(11, 12); 68 this->pictureBox1->Name = L"pictureBox1"; 69 this->pictureBox1->Size = System::Drawing::Size(225, 241); 70 this->pictureBox1->TabIndex = 0; 71 this->pictureBox1->TabStop = false; 72 // 73 // button1 74 // 75 this->button1->Location = System::Drawing::Point(242, 128); 76 this->button1->Name = L"button1"; 77 this->button1->Size = System::Drawing::Size(75, 23); 78 this->button1->TabIndex = 1; 79 this->button1->Text = L"button1"; 80 this->button1->UseVisualStyleBackColor = true; 81 this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); 82 // 83 // MyForm 84 // 85 this->AutoScaleDimensions = System::Drawing::SizeF(6, 12); 86 this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 87 this->ClientSize = System::Drawing::Size(323, 261); 88 this->Controls->Add(this->button1); 89 this->Controls->Add(this->pictureBox1); 90 this->Name = L"MyForm"; 91 this->Text = L"MyForm"; 92 (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit(); 93 this->ResumeLayout(false); 94 95 } 96#pragma endregion 97 98 private: System::Void drawImage(PictureBox^ pic, Mat mat) { 99 if ((pic->Image == nullptr) || (pic->Width != mat.cols) 100 || (pic->Height != mat.rows)) { 101 pic->Width = mat.cols; 102 pic->Height = mat.rows; 103 Bitmap^ bmpPicBox = gcnew Bitmap(pic->Width, pic->Height); 104 pic->Image = bmpPicBox; 105 } 106 Graphics^g = Graphics::FromImage(pic->Image); 107 Bitmap^ bmp = gcnew Bitmap(mat.cols, mat.rows, mat.step, 108 System::Drawing::Imaging::PixelFormat::Format32bppRgb, IntPtr(mat.data)); 109 g->DrawImage(bmp, 0, 0, mat.cols, mat.rows); 110 pic->Refresh(); 111 delete g; 112 } 113 114 private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 115 Mat input = imread("C:\Users\aselab\Desktop\itigo.jpg", IMREAD_UNCHANGED); 116 drawImage(pictureBox1, input); 117 } 118 }; 119} 120
Source.cpp
c++
1#include "MyForm.h" 2 3using namespace test; 4 5[STAThreadAttribute] 6int main() { 7 MyForm ^ui = gcnew MyForm(); 8 ui->ShowDialog(); 9 return 0; 10}
補足情報(FW/ツールのバージョンなど)
Windows 10
opencv 3.4.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。