简体   繁体   English

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

[英]Can't Display Bitmap of Higher Resolution than CDC area

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. 我正在尝试从分辨率为1392x1032的位图指针* ImageData显示图像。 I am trying to draw that at an area of resolution or size 627x474. 我试图将其绘制在分辨率或大小为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 当我将我创建的位图图像从* ImageData的宽度和高度更改为分辨率或大小约为627x474时,它将起作用

I really do not know how to solve this after trying all possible solutions from various forums and google. 在尝试了各种论坛和Google的所有可能解决方案之后,我真的不知道如何解决此问题。

pDC is a CDC* and memDC is a CDC initialized in an earlier method Anything uninitialized here was initialized in other methods. pDC是CDC *,而memDC是在较早方法中初始化的CDC。此处未初始化的所有内容都已通过其他方法初始化。

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) (a)一个类(比如说DemoTestingDlg类)将把CDC传递给另一个类(比如说DemoControl类)

m_Demo = new DemoControl ; 

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

(b) At the DemoControl class (b)在DemoControl课上

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

          pDC = m_StaticDisplay ; 
          memDC.CreateCompatibleDC(pDC); 

} }

pDC and memDC is as such in the header: pDC和memDC在标头中是这样的:

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. (c)如果假设捕获了图像,则将图像指针传递给DemoTestingDlg类,该类随后将在Demo Control类中调用showImage方法,该方法是我在问题中编写的方法。 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 注意:如果确实说它们具有相同的大小(确实是CDC和位图),那么它确实显示了图像,因此我的印象是CDC指针正确传递了

StretchBlt is your friend :) StretchBlt是你的朋友:)

Edit: OK how do you get pDC? 编辑:确定如何获得pDC? When is your function called? 什么时候调用函数? Form OnPaint or DrawItem? 表单OnPaint或DrawItem?

This is a StretchBlt I do from a DrawItem call in an overriden CStatic. 这是我从重写的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 );

Its not using the MFC classes to stretch a 4x4 bitmap into a larger space but works perfectly. 它没有使用MFC类将4x4位图扩展到更大的空间,但是效果很好。 My guess is that you aren't doing it in response to a WM_PAINT/WM_DRAWITEM and/or are using the wrong DC. 我的猜测是您不是为了响应WM_PAINT / WM_DRAWITEM而这样做,或者是使用了错误的DC。

Edit re your edit: Do you then call DrawImage from inside an OnPaint or DrawItem call? 编辑后再编辑:然后从OnPaint或DrawItem调用中调用DrawImage吗?

I would have thought you are better off not cacheing that CDC and passing the CDC in each time you wish to draw it. 我本以为您最好不要缓存该CDC,并在每次希望绘制它时都传递CDC。

"from a bitmap pointer *ImageData which is of resolution 1392x1032" “来自分辨率为1392x1032的位图指针* ImageData”

No it isn't, it's of size 1392x1032. 不,不是, 尺寸为 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(). 至少显示OnPaint()。 Where are you instantiating the CPaintDC? 您在哪里实例化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. 如果您使用StretchBlt()代替现在使用的BitBlt(),则您似乎处于正确的轨道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM