MFC 이미지 띄우고나서 현재 픽처컨트롤 띄운 이미지 저장한 뒤 다시 자동으로 원래 이미지 띄울때 오류가 생깁니다

GyeongIn Bae@Google의 이미지

Debug Assertion Failed!

Program: D:\mfcEx\MPCReport\MFCApplication1\Debug\MFCPictureTest.exe
File: d:\program files\microsoft visual studio 12.0\vc\atlmfc\include\atlimage.h
Line: 1607

Expression: hBitmap == m_hBitmap

라는 오류가 뜨면서 프로그램디버깅이 멈춰버립니다

코드중간에
cImage.StretchBlt(pDC->m_hDC, x1, y1, x2, y2, 0, 0, cImage.GetWidth(), cImage.GetHeight(), SRCCOPY);
에서 오류가 일어났고 저장 자체는 재대로 되고 좌표값에는 오류가 없는걸 확인했습니다 아마 pDC->m_hDC 에서 오류가 일어나는것 같네요
그냥 파일 열기만 계속하면 이상이없으나 파일을 저장한뒤에 저 코드가 실행되면 오류가 발생합니다
구글 뒤져보다가 답답해서 올립니다 ㅠㅠ 참고 코드 올려드립니다

 
void CMFCApplication1Dlg::pictureLoad(){
	if (oldCheckImageOp!=90)
		cImage.Destroy();
	HRESULT hr = cImage.Load(filePath);
 
	if (FAILED(hr)) //이미지 로드 안되었을때
	{
		return;
	}
	checkImageOp = 19;
}
 
void CMFCApplication1Dlg::remakePic(){
	oldCheckImageOp = checkImageOp;
	if (checkImageOp == 19){
		x1 = 0; y1 = 0; x2 = rcx; y2 = rcy;
		ox1 = 0; oy1 = 0; ox2 = cImage.GetWidth(); oy2 = cImage.GetHeight();
	}
	if (checkImageOp == 2){
		if (y2 != -rcy){
			y1 += rcy; y2 -= rcy * 2;
			oy1 += cImage.GetHeight(); oy2 -= cImage.GetHeight() * 2;
		}
		else{
			y1 -= rcy; y2 += rcy * 2;
			oy1 -= cImage.GetHeight(); oy2 += cImage.GetHeight() * 2;
		}
	}
	if (checkImageOp == 3){
		if (x2 != -rcx){
			x1 += rcx - 1; x2 -= rcx * 2;
			ox1 += cImage.GetWidth(); -1; ox2 -= cImage.GetWidth() *2;
		}
		else{
			x1 -= rcx+1; x2 += rcx * 2;
			ox1 -= cImage.GetWidth(); +1; ox2 += cImage.GetWidth() * 2;
		}
	}
	if (checkImageOp == 4){
 
	}
	if (checkImageOp == 5){
 
	}
	checkImageOp = 99;
}
 
void CMFCApplication1Dlg::openPicture(){
 
	if (checkImageOp == 0)
		return;
	if (checkImageOp == 1){
 
		pictureLoad();
	}
	CDC * pDC;
	CRect cRect;
	pDC = m_Picture.GetDC(); 
 
	m_Picture.GetClientRect(cRect);
 
	CBrush cbWhite(RGB(255, 255, 255));
	pDC->FillRect(cRect, &cbWhite); 
 
 
	pDC->SetStretchBltMode(COLORONCOLOR);
	if (checkImageOp != 99){
		remakePic();
	}
 
	//test
	cImage.StretchBlt(pDC->m_hDC, x1, y1, x2, y2, 0, 0, cImage.GetWidth(), cImage.GetHeight(), SRCCOPY);//에러
 
 
	ReleaseDC(pDC);	
 
}
 
void CMFCApplication1Dlg::savePicture(){
 
	testcImage.Create(cImage.GetWidth(), cImage.GetHeight(), 32);
	/*pDC->DeleteDC();*/
	cImage.Destroy();
 
	HRESULT hr = makeNewImage.Load(filePath);
 
	if (FAILED(hr)) //이미지 로드 안되었을때
	{
		return;
	}
 
	HDC hProcessDC = makeNewImage.GetDC();
	HDC hDC = testcImage.GetDC();
 
	SetStretchBltMode(hDC, COLORONCOLOR);
	makeNewImage.StretchBlt(hDC, ox1, oy1, ox2, oy2, 0, 0, testcImage.GetWidth(), testcImage.GetHeight(), SRCCOPY);
 
 
	testcImage.ReleaseDC();
	testcImage.Save(savefilePath);
	makeNewImage.ReleaseDC();
	testcImage.Destroy(); makeNewImage.Destroy();
 
	//ReleaseDC(pDC);
 
	DeleteDC(hProcessDC);
	DeleteDC(hDC);
 
 
	checkImageOp = 1;
	oldCheckImageOp = 90;
	PictureopenDlg();
	openPicture(); //에러
 
 
}

GyeongIn Bae@Google의 이미지

쓸대없이 Destroy,DeleteDC 한거랑 Destroy 위치 등등 다시 지우고 고치니까 되네요 이거하느라 오늘 반나절 보냈네요 ㅠㅠ

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.