首先說,這是一個重複的問題,但不是相同的問題。
當我運行我的代碼時,顯示此消息,但沒有錯誤。調試斷言失敗與rgbConverted.cpp
#pragma once
using namespace System::Drawing;
ref class rgbConvert
{
private:
System::Drawing::Bitmap^ grayImage;
System::Drawing::Bitmap^ bainaryImage;
System::Drawing::Bitmap^ rgbImage;
int xsize;
int ysize;
bool **BArray;
int **GrayArray;
int **binary;
FILE *fp;
static float coef01 = (float)0.2989;
static float coef02 = (float)0.5870;
static float coef03 = (float)0.1140;
public:
rgbConvert(System::Drawing::Bitmap^ im)
{
rgbImage = im;
xsize = rgbImage->Height;
ysize = rgbImage->Width;
}
rgbConvert(int height, int width)
{
xsize = height;
ysize = width;
}
int** getGrayImageArray()
{
GrayArray = new int * [xsize];
for (int i = 0; i < xsize; i++)
{
GrayArray[i] = new int[ysize];
}
for(int i = 0; i < this->xsize; i++)
{
for (int j = 0; j < this->ysize; j++)
{
System::Drawing::Color^ clr = this->rgbImage->GetPixel(j, i);
int pixel = clr->ToArgb();
//int alpha = (pixel >> 24) & 0xff;// no need here
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
int grayC = int(coef01*red + coef02*green + coef03*blue);
GrayArray[i][j] = grayC;
}// inner for*/
}
return GrayArray;
}
void getGrayImageArray (int** gArray)
{
this->GrayArray = gArray;
}
bool** GetBinaryArray(int level)
{
BArray = new bool * [xsize];
for (int i = 0; i < xsize; i++)
{
BArray[i] = new bool[ysize];
}
binary = new int * [xsize];
for (int i = 0; i < xsize; i++)
{
binary[i] = new int[ysize];
}
fp=fopen("C:\\binary.txt","w");
int grayC;
for (int xVal = 0; xVal < xsize; xVal++)
{
for(int yVal = 0; yVal < ysize; yVal++)
{
grayC = GrayArray[xVal][yVal];
if (grayC >= level)
{
BArray[xVal][yVal] = true;
binary[xVal][yVal] = 1;
fprintf(fp,"%d",binary[xVal][yVal]);
}
else
{
BArray[xVal][yVal] = false;
binary[xVal][yVal] = 0;
fprintf(fp,"%d",binary[xVal][yVal]);
}
}// inner for*/
}
fclose(fp);
return BArray;
}
};
當我按下重試,則斷點表示此行。
fprintf(fp,"%d",binary[xVal][yVal]);
如果我刪除這些行,然後在主程序中顯示斷點。
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
斷點顯示在return 0
此行。
有文件被成功打開?您確實需要檢查可能失敗的函數中的錯誤。 –
先生,我的程序運行時沒有任何錯誤。但out.doc文件沒有創建。 –
如果程序運行沒有錯誤,那麼你的崩潰是什麼?你是否在問崩潰(可能是因爲文件沒有打開),或者文件沒有被創建(這可能是因爲同樣的原因)?檢查一下'fopen'回來了! –