Software/Programming2012. 8. 10. 22:10

제가 프로그램을 짜고있는데 커머파일은 되는데 실행할때 에러가 나서요ㅠㅠ

 

제 프로그램의 내용은 이미지 파일 두개를 연속으로 열고 그 후에 지정된 폴더에 있는 이미지 파일을 연속적으로 여는건데요

 

문제는 이미지 파일 두개를 연속으로 열때는 문제가 없는데 그 후에 지정된 폴더내에 있는 이미지 파일을 연속적으로 열려고 할때 에러가 난다는 겁니다. 에러의 내용은

 

 

 

이거구요ㅠㅠ

 

그림 맨위에 gray in light.bmp 파일이 첫번째로 open한 파일의 이름입니다.

 

이미지 파일 두개를 오픈하는 소스는 다음과 같구요

 

BOOL CWinColorDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
 if (!CDocument::OnOpenDocument(lpszPathName))
  return FALSE;
 //1번째 이미지 파일
 // TODO: Add your specialized creation code here
 CFile hFile;
 hFile.Open(lpszPathName,CFile::modeRead | CFile::typeBinary);
 hFile.Read(&dibHf,sizeof(BITMAPFILEHEADER)); // 파일 헤드를 읽음
 if(dibHf.bfType!=0x4D42)
 {
  AfxMessageBox("Not BMP file!!");
  return FALSE;
 } //이 파일이 BMP파일인지 검사. 0x4d42=='BM'
 hFile.Read(&dibHi,sizeof(BITMAPINFOHEADER)); //"영상정보의 Header"를 읽는다. 
 if(dibHi.biBitCount!=8 && dibHi.biBitCount!=24)
 {
  AfxMessageBox("Gray/True Color Possible!!");
  return FALSE;
 }
 if(dibHi.biBitCount==8)
  hFile.Read(palRGB,sizeof(RGBQUAD)*256);

 // 메모리 할당 (바뀐 부분)
 int ImgSize;
 if(dibHi.biBitCount==8) ImgSize = hFile.GetLength()-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-256*sizeof(RGBQUAD);
 else if(dibHi.biBitCount==24) ImgSize = hFile.GetLength()-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER);
 m_InImg = new unsigned char [ImgSize]; //dibHi.biSizeImage

 m_OutImg = new unsigned char [ImgSize];
 
 hFile.Read(m_InImg, ImgSize);

 height = dibHi.biHeight;
 width = dibHi.biWidth;
 
 if(dibHi.biBitCount==24){} //return TRUE;
 // 영상데이터 대입
 
 int i,j,index;
 int rwsize = WIDTHBYTES(dibHi.biBitCount*width);
 for( i=0; i<height; i++)
 {
  index = i*rwsize;
  for(j=0; j<width; j++)
   m_InImg[index+j] = (unsigned char)palRGB[(int)m_InImg[index+j]].rgbBlue;
 }
   
 
 hFile.Close();
 

 //2번째 이미지 파일
 CFile h1File;
 CFileDialog dlg(TRUE);
 if (dlg.DoModal() == IDOK )
 {
  CString lpszPathName2 = dlg.GetPathName();
  h1File.Open(lpszPathName2,CFile::modeRead | CFile::typeBinary);
  h1File.Read(&dibHf1,sizeof(BITMAPFILEHEADER)); // 파일 헤드를 읽음

  if(dibHf1.bfType!=0x4D42)
  {
   AfxMessageBox("Not BMP file!!"); return FALSE;
  } //이 파일이 BMP파일인지 검사. 0x4d42=='BM'
  h1File.Read(&dibHi1,sizeof(BITMAPINFOHEADER)); //"영상정보의 Header"를 읽는다. 
  if(dibHi1.biBitCount!=8 && dibHi1.biBitCount!=24)
  {
   AfxMessageBox("Gray/True Color Possible!!");
   return FALSE;
  }
  
  if(dibHi1.biBitCount==8)
   h1File.Read(palRGB,sizeof(RGBQUAD)*256);

  // 메모리 할당 (바뀐 부분)
  int ImgSize1;
  if(dibHi1.biBitCount==8) ImgSize1 = h1File.GetLength()-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-256*sizeof(RGBQUAD);
  else if(dibHi1.biBitCount==24) ImgSize1 = h1File.GetLength()-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER);
  m_InImg1 = new unsigned char [ImgSize1]; //dibHi1.biSizeImage
  m_OutImg1 = new unsigned char [ImgSize1];


        h1File.Read(m_InImg1, ImgSize1);

  height1 = dibHi1.biHeight;
  width1 = dibHi1.biWidth;

 
  h1File.Close();
 
  //return TRUE;

  // 영상데이터1 대입
  
  int i1,j1,index1;
  int rwsize1 = WIDTHBYTES(dibHi1.biBitCount*width1);
  for(i1=0; i1<height1; i1++)
  {
   index1 = i1*rwsize1;
   for(j1=0; j1<width1; j1++)
    m_InImg1[index1+j1] = (unsigned char)palRGB[(int)m_InImg1[index1+j1]].rgbBlue;
  }

 }
 //if(dibHi1.biBitCount==24) //return TRUE;

 return TRUE;
}

 

폴더내에 있는 이미지 파일을 연속적으로 오픈하는 부분은 다음과 같습니다.

 

void CWinColorDoc::OnBatchAccumhist()
{
 // TODO: Add your command handler code here
/* CFileDialog dlg(TRUE);
 if (dlg.DoModal() == IDOK )
 {
 */
 CFileFind find; //file 검색을 위한 클래스
  CString path1 = "C:\\temp1\\*.bmp"; //원하는 폴더경로 지정
 CString fname;
 CString pname;

 int pWorking = find.FindFile((LPCTSTR)path1);//원하는 폴더 경로에  조건에 맞는 파일이 있으면 1, 없으면 0

  if (pWorking==0) {

   AfxMessageBox("파일이 없습니다.");

  }

  while(pWorking)
  {
   pWorking = find.FindNextFile(); //다음 파일 찾기
   fname = find.GetFileName(); //파일 이름 넘겨주기
   pname = find.GetFilePath(); //파일 경로 넘겨주기


 
   CFile h2File;//원하는 파일이 있을 경우 파일을 읽어들이기 위한 함수

   // CString lpszPathName3 = dlg.GetPathName();

    h2File.Open(pname,CFile::modeRead | CFile::typeBinary);

    h2File.Read(&dibHf2,sizeof(BITMAPFILEHEADER)); // 파일 헤드를 읽음

    h2File.Read(&dibHi2,sizeof(BITMAPINFOHEADER)); //"영상정보의 Header"를 읽는다.
   
     if(dibHi2.biBitCount!=8 && dibHi2.biBitCount!=24)
     {
      AfxMessageBox("Gray/True Color Possible!!");
    
     }

     if(dibHi2.biBitCount==8)

      h2File.Read(palRGB,sizeof(RGBQUAD)*256);


     // 메모리 할당 (바뀐 부분)
     double ImgSize=0.0;

         if(dibHi2.biBitCount==8)
       ImgSize = h2File.GetLength() -sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-256*sizeof(RGBQUAD);
      else if(dibHi2.biBitCount==24)
       ImgSize = h2File.GetLength()-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER);
   
      m_InImg2 = new unsigned char [ImgSize]; //dibHi.biSizeImage
    
      h2File.Read(m_InImg2, ImgSize);

      height2 = dibHi2.biHeight;
      width2 = dibHi2.biWidth;
    
      //if(dibHi2.biBitCount==24){} //return TRUE;
   
      // 영상데이터 대입  
   
      int i,j,index;
      int rwsize = WIDTHBYTES(dibHi2.biBitCount*width2);

      for( i=0; i<height2; i++)
      {
       index = i*rwsize;
       for(j=0; j<width2; j++)
        m_InImg2[index+j] = (unsigned char)palRGB[(int)m_InImg2[index+j]].rgbBlue;
      }
   

      OnAccFeatHisto();

      if (find.IsDirectory()) //디렉토리가 있으면
      {
       CString ffilename = pname+"\\";

       AfxMessageBox(ffilename);
       //fileopen. fullfilename
       // fclose
      } else { //디렉토리가 없으면-bmp 파일이면                                                        
       CString ffilename = pname;
       AfxMessageBox(ffilename);
       //fileopen. fullfilename                                                                                                                                                  
       //OnAcchisto();
       // fclose
      } 
   
      h2File.Close();
         delete m_InImg2;   
   }
  
  
// } 
 
}

Posted by 십자성군