이런 mfc! CBitmap을 Bitblt 하는 법

MyAbby의 이미지

안녕하세요.

비트맵 파일을 분석하는 프로그램을 개발 중에 있습니다.
비트맵 파일을 열어서, 비트맵 파일헤더, 인포헤더, 비트맵 데이터를 차례로 읽고 그걸로 CBitmap을 만든 다음 다이얼로그에 Bitblt 하고 싶은데요.
비트맵 로드하고 CBitmap 까지 잘 만들어 지는데, 그걸 Bitblt하지를 못하고 있습니다...

void CBMPLoaderDlg::drawBitmapFromPath(CString path)
{
    CFile file;
    BITMAPFILEHEADER bfh;
    BITMAPINFOHEADER bih;
    BYTE* bits = NULL;
 
    CBitmap bm;
    CDC *clientDC;
    CDC memDC;
 
    try
    {
        if(! file.Open(path, CFile::modeRead))
            throw "File not found";
 
        if(file.Read(&bfh, sizeof(BITMAPFILEHEADER)) < sizeof(BITMAPFILEHEADER))
            throw "Not bmp file";
        if(file.Read(&bih, sizeof(BITMAPINFOHEADER)) < sizeof(BITMAPINFOHEADER))
            throw "Not bmp file";
        bits = new BYTE[bih.biSizeImage];
        if(file.Read(bits, bih.biSizeImage) < bih.biSizeImage)
            throw "Not bmp file";
 
        if(! bm.CreateBitmap(bih.biWidth, bih.biHeight, bih.biPlanes, bih.biBitCount, bits))
            throw "Could not create bitmap";
        clientDC = this->GetDC();
        memDC.CreateCompatibleDC(clientDC);
        memDC.SelectObject(bm);
 
        clientDC->BitBlt(0, 0, bih.biWidth, bih.biHeight, &memDC, 0, 0, SRCCOPY);
    }
    catch(char *e)
    {
        TRACE("%s\n", e);
    }
}

Bitblt작업은 OnPaint에서 해야하는 건 잘 알고 있습니다. 질문하려고 만든 코딩이구요.
실행해 보면 절때로 예외를 던지지 않습니다. 전부 TRUE 를 반환하구요. 근데 다이얼로그에는 아무런 변화가 없습니다.
저 clientDC로 다른 도형이나 텍스트를 출력해 보면 잘 작동합니다. 꼭 저 bm만 출력이 안됩니다. SRCCPY를 WHITENESS같은 걸로 바꿔보면 비트맵 크기대로 출력이 되구요.
Cbitmap에 이상이 있는 건 아닌 거 같아요. CBitmap::GetBitmapBits 로 지정해준 버퍼를 받으면 들어간 값이 잘 나옵니다. GetBitmap도 마찬가지이구요.

LoadImage나 CBitmap::LoadBitmap 메서드를 사용하는 방법도 있는건 잘 앏니다. 나중에 저 로드한 비트맵 버퍼를 직접 분석하고 수정해야 하기 때문에 꼭 매모리에 로드된 비트맵을 출력하는 방법이 필요해요.

도와줍쇼..

mirheekl의 이미지

혹시 FALSE를 리턴한다면 GetLastError가 궁금해집니다.

--

MyAbby의 이미지

TRUE인데 출력이 없다는게 좀 짜증이 나네요..

지금 구현하려는 거는 CreateDIBitmap으로 해결했습니다. HBITMAP으로 출력하면 잘 되요.
아마 CBitmap이 Device-Independent가 아닌가 봅니다.

... 그럼 FALSE라도 반환하지. 윈도우 그렇게 좋은게 아닌가 봅니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.