无法显示比 CDC 区域更高分辨率的位图

发布于 2024-09-01 09:02:09 字数 1815 浏览 3 评论 0原文

大家好,亲爱的专家和专家程序员。

我不会从我是一个新手开始,对图像编程不太了解,但不幸的是,这些都是事实:(

我正在尝试从位图指针 *ImageData 分辨率显示图像 1392x1032。我试图以分辨率或大小 627x474 的区域绘制它。

然而,反复尝试似乎没有效果。当我将创建的位图图像从 *ImageData 宽度和高度更改为分辨率或大小约为 627x474 时,它就起作用了

。在尝试了各种论坛和谷歌的所有可能解决方案后,我真的不知道如何解决这个问题。

pDC 是 CDC*,memDC 是在早期方法中初始化的 CDC 这里未初始化的任何内容都在其他方法中初始化。

这是我的代码,亲爱的谦虚的大师。请为我提供尤达和欧比旺为卢克·天行者提供的指导。

void DemoControl::ShowImage( void *ImageData )
{


    int Width; //Width of Image From Camera
    int Height; //Height of Image From Camera

    int m_DisplayWidth = 627 ;//width of rectangle area to display
    int m_DisplayHeight = 474;//height of rectangle area to display

    GetImageSize( &Width, &Height ) ; //this will return Width = 1392, Height 1032

    CBitmap bitmap;

    bitmap.CreateBitmap(Width,Height,32,1,ImageData);

    CBitmap* pOldBitmap = memDC.SelectObject((CBitmap*)&bitmap);

    pDC->BitBlt(22, 24, 627, 474, &memDC, 0, 0, SRCCOPY);

    memDC.SelectObject((CBitmap*)pOldBitmap);

    ReleaseDC(pDC);

}

好吧,这里有一些额外的部分,

我想我应该解释一下流程是如何进行的。

(a) 一个类(假设为 DemoTestingDlg 类)将如下所示将 CDC 传递给另一个类(假设为 DemoControl 类)

m_Demo = new DemoControl ; 

m_Demo->Initialisation( this, this->GetDC() ) ; 

(b) 在 DemoControl 类中

bool DemoControl::Initialization( CDemoTestingDlg m_FormControl, CDC m_StaticDisplay ) {

          pDC = m_StaticDisplay ; 
          memDC.CreateCompatibleDC(pDC); 

}

pDC 和 memDC 在标头中是这样的:

CDC* pDC ; CDC memDC; 

(c) 如果假设捕获了图像,则图像指针将传递给 DemoTestingDlg 类,该类随后将调用 Demo Control 类中的 showImage 方法,该方法是该方法我在问题中写道。我做对了吗?

注意:如果我们说它们具有相同的大小(我指的是 CDC 和位图),它确实会显示图像,所以我的印象是我的 CDC 指针已正确传递

Hi there dear gurus and expert coders.

i am not gonna start with im a newbie and don't know much about image programming but unfortunately those are the facts :(

I am trying to display an image from a bitmap pointer *ImageData which is of resolution
1392x1032. I am trying to draw that at an area of resolution or size 627x474.

However, repeated trying doesnt seem to work. It works when I change the bitmap image I created from *ImageData width and height to resolution or size of around 627x474

I really do not know how to solve this after trying all possible solutions from various forums and google.

pDC is a CDC* and memDC is a CDC initialized in an earlier method
Anything uninitialized here was initialized in other methods.

Here is my code dear humble gurus. Do provide me with guidance Yoda and Obi-Wan provided to Luke Skywalker.

void DemoControl::ShowImage( void *ImageData )
{


    int Width; //Width of Image From Camera
    int Height; //Height of Image From Camera

    int m_DisplayWidth = 627 ;//width of rectangle area to display
    int m_DisplayHeight = 474;//height of rectangle area to display

    GetImageSize( &Width, &Height ) ; //this will return Width = 1392, Height 1032

    CBitmap bitmap;

    bitmap.CreateBitmap(Width,Height,32,1,ImageData);

    CBitmap* pOldBitmap = memDC.SelectObject((CBitmap*)&bitmap);

    pDC->BitBlt(22, 24, 627, 474, &memDC, 0, 0, SRCCOPY);

    memDC.SelectObject((CBitmap*)pOldBitmap);

    ReleaseDC(pDC);

}

Ok heres some additional parts

I think i should explain how the flow goes.

(a) A class (lets say DemoTestingDlg class) will pass the CDC as below to another class (lets say DemoControl class)

m_Demo = new DemoControl ; 

m_Demo->Initialisation( this, this->GetDC() ) ; 

(b) At the DemoControl class

bool DemoControl::Initialisation( CDemoTestingDlg m_FormControl, CDC m_StaticDisplay ) {

          pDC = m_StaticDisplay ; 
          memDC.CreateCompatibleDC(pDC); 

}

pDC and memDC is as such in the header:

CDC* pDC ; CDC memDC; 

(c) If lets say an image is captured, the image pointer is passed to the DemoTestingDlg class which will subsequently call a showImage method in the Demo Control Class which is the method I wrote in the question. Am i doing it right?

Note: It did show an image if lets say they are of the same size (by they i mean the CDC and bitmap) so i was under the impression that my CDC pointer was passed correctly

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦慕雪 2024-09-08 09:02:09

StretchBlt 是你的朋友:)

编辑:好的你如何获得pDC?你的函数什么时候被调用?窗体 OnPaint 还是 DrawItem?

这是我通过覆盖 CStatic 中的 DrawItem 调用执行的 StretchBlt。

HDC hBitmapDC   = CreateCompatibleDC( pDrawItemStruct->hDC );

HBITMAP hBitmap = GetBitmap();
HGDIOBJ hOld    = SelectObject( hBitmapDC, (HGDIOBJ)hBitmap );

StretchBlt( pDrawItemStruct->hDC, pDrawItemStruct->rcItem.left, pDrawItemStruct->rcItem.top, pDrawItemStruct->rcItem.right, pDrawItemStruct->rcItem.bottom,
            hBitmapDC, 0, 0, 4, 4, SRCCOPY );

SelectObject( hBitmapDC, hOld );
DeleteObject( hBitmapDC );

它没有使用 MFC 类将 4x4 位图拉伸到更大的空间,但工作得很好。我的猜测是,您这样做不是为了响应 WM_PAINT/WM_DRAWITEM 和/或使用了错误的 DC。

重新编辑您的编辑:然后您是否从 OnPaint 或 DrawItem 调用内部调用 DrawImage?

我本以为你最好不要缓存该 CDC,并在每次想要绘制它时传递 CDC。

StretchBlt is your friend :)

Edit: OK how do you get pDC? When is your function called? Form OnPaint or DrawItem?

This is a StretchBlt I do from a DrawItem call in an overriden CStatic.

HDC hBitmapDC   = CreateCompatibleDC( pDrawItemStruct->hDC );

HBITMAP hBitmap = GetBitmap();
HGDIOBJ hOld    = SelectObject( hBitmapDC, (HGDIOBJ)hBitmap );

StretchBlt( pDrawItemStruct->hDC, pDrawItemStruct->rcItem.left, pDrawItemStruct->rcItem.top, pDrawItemStruct->rcItem.right, pDrawItemStruct->rcItem.bottom,
            hBitmapDC, 0, 0, 4, 4, SRCCOPY );

SelectObject( hBitmapDC, hOld );
DeleteObject( hBitmapDC );

Its not using the MFC classes to stretch a 4x4 bitmap into a larger space but works perfectly. My guess is that you aren't doing it in response to a WM_PAINT/WM_DRAWITEM and/or are using the wrong DC.

Edit re your edit: Do you then call DrawImage from inside an OnPaint or DrawItem call?

I would have thought you are better off not cacheing that CDC and passing the CDC in each time you wish to draw it.

女皇必胜 2024-09-08 09:02:09

“来自分辨率为 1392x1032 的位图指针 *ImageData”

不,不是,它的大小 1392x1032。分辨率是每距离离散视觉单位的数量。

无论如何,如上所述,您需要发布更多代码。至少显示 OnPaint()。你在哪里实例化 CPaintDC?创建一个新项目并将所有代码放入其中,以便您拥有一个显示问题的最小测试集。如果您使用 StretchBlt() 代替您现在使用的 BitBlt(),您似乎大致处于正确的轨道上。

"from a bitmap pointer *ImageData which is of resolution 1392x1032"

No it isn't, it's of size 1392x1032. Resolution is the amount of discrete visual units per distance.

Anyway as was mentioned above, you need to post more code. Show at least OnPaint(). Where are you instantiating the CPaintDC? Make a new project and put all your code in there, so that you have a minimal test set that exhibits the problem. You seem to be roughly on the right track, if you use StretchBlt() in place of the BitBlt() you're using now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文