我正在尝试打开一张图片并将其显示在图片框中但获得例外。
我使用visual studio 2017 c ++ CLI。
我在开头包含这些库
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#pragma managed
#include <Windows.h>
#include <conio.h>
cv::Mat img; cv::Mat imgThresh;
LPRCNN.exe中的0x00007FF9582E5D43(comctl32.dll)抛出异常: 0xC0000005:访问冲突读取位置0xFFFFFFFFB2BEB41A。 发生
private: System::Void btnBrowse_Click(System::Object^ sender, System::EventArgs^ e) {
//Stream;
Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = Directory::GetCurrentDirectory();
openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
if ((myStream = openFileDialog1->OpenFile()) != nullptr)
{
file_path_temp = (openFileDialog1->FileName);
txtImgUrl->Text = file_path_temp;
IntPtr pointer_temp = Marshal::StringToHGlobalAnsi(file_path_temp);
const char* input_location = static_cast<const char*>(pointer_temp.ToPointer());
cv::Mat imgOriginalScene = cv::imread(input_location, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
if (!imgOriginalScene.empty())
{
cvtColor(imgOriginalScene, img, CV_RGB2RGBA);
cv::imwrite("temp/temp.bmp", imgOriginalScene);
System::Drawing::Graphics^ graphics = PicBoxCar->CreateGraphics();
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap("temp/temp.bmp");
System::Drawing::RectangleF rect(0, 0, (float)PicBoxCar->Width, (float)PicBoxCar->Height);
graphics->DrawImage(b, rect);
delete b;
}
else
MessageBox::Show("Cannot open this image please choose another one !!", "Path:");
myStream->Close();
}
}
}