×

Loading...
Ad by
  • 予人玫瑰,手有余香:加拿大新天地工作移民诚聘求职顾问&行业导师!
Ad by
  • 予人玫瑰,手有余香:加拿大新天地工作移民诚聘求职顾问&行业导师!

我只改了两个和源bmp文件大小相关的参数。

原来显示320*240bmp用的代码。
StretchDIBits(hDC,
0, 0,
giWindowWidth,
giWindowHeight,
0, 0,
320, 240,
DIB_PBITS((PDIB)Images[OffScreen].pDib),
(LPBITMAPINFO)Images[OffScreen].pDib,
DIB_RGB_COLORS,
SRCCOPY );
稍微改了一下source bmp文件的大小的参数。新的是这样,iWindowWidth, giWindowHeight这两个参数是当前的窗口大小。
StretchDIBits(hDC,
0, 0,
giWindowWidth,
giWindowHeight,
0, 0,
640, 480,
DIB_PBITS((PDIB)Images[OffScreen].pDib),
(LPBITMAPINFO)Images[OffScreen].pDib,
DIB_RGB_COLORS,
SRCCOPY );
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 头痛,请熟悉bitmap显示的大侠帮我分析分析。最近在改一个很老的小游戏,用borland C++ 4.5写的。原来显示320*240的bmp,现在要改为显示640*480的bmp,可是改了以后,发现显示出来的图片颜色极其难看。
    我看老程序里用了象StretchDIBits, CopyDIBBits之类的函数。我只是先改了一下和图像大小相关的参数,结果颜色就一片混乱。这回是什么原因呢?是调色板出了问题吗?可是我还没有改和调色板有关的代码,显示320*240的bmp还是正常的。
    • 8-bit bitmap or 24-bit? I know a little about 8-bit.
      • 谢谢,是8-bit的。
        • what parameters did you change?
          • 我只改了两个和源bmp文件大小相关的参数。
            原来显示320*240bmp用的代码。
            StretchDIBits(hDC,
            0, 0,
            giWindowWidth,
            giWindowHeight,
            0, 0,
            320, 240,
            DIB_PBITS((PDIB)Images[OffScreen].pDib),
            (LPBITMAPINFO)Images[OffScreen].pDib,
            DIB_RGB_COLORS,
            SRCCOPY );
            稍微改了一下source bmp文件的大小的参数。新的是这样,iWindowWidth, giWindowHeight这两个参数是当前的窗口大小。
            StretchDIBits(hDC,
            0, 0,
            giWindowWidth,
            giWindowHeight,
            0, 0,
            640, 480,
            DIB_PBITS((PDIB)Images[OffScreen].pDib),
            (LPBITMAPINFO)Images[OffScreen].pDib,
            DIB_RGB_COLORS,
            SRCCOPY );
            • okay, the question is: did you make any changes to your source bitmap file -- Images[OffScreen].pDib ? It should be a 640*480 bitmap image.
              Its dimension should be the same as used in StretchDIBits.

              My 2 cents is:

              instead of using hardcoded 640 and 480 here, use

              ((LPBITMAPINFO)Images[OffScreen].pDib)->bmiHeader.biWidth
              and
              ((LPBITMAPINFO)Images[OffScreen].pDib)->bmiHeader.biHeight

              So that they will always agree with each other.

              When you want to change the bitmap image's dimension, just do the modification at one place.
            • Does it help? How did you solve it?
              • 还没有搞定。:(
                昨天后来我把那个显示出来巨难看的图片用屏幕拷贝截下来,和源bmp比较了一下,发现用的palette差别很大。我想也许是设置的palette有问题。请问320和640这两种不同分辨率的bmp图片,读取和设置palette的时候有区别吗?它们都是8-bit的。象StretchDIBits之类的函数,会自己读取和设置palette吗?谢谢。
                • the pallette info doesn't differ. The pallette for 8-bit bitmap file is defined in RGBQUAD bmiColors[]. bmiColors has 256 entries. If I were you, I would copy the old pallete into the new one and see the result.
                  • 刚才试着把源bmp的palette替换掉显示错误的那个bmp的palette,显示出来的图片仍然很难看。会是什么原因呢?
                    • can you send me the original bmp (the small one) and the new bmp (the big one)?
                      • Can you give me your email please? I will attach those bmps to you.
                        • .
                          it's
                          wanglixia99@yahoo.com
                      • Check your email please. Thank you very much.
    • up
    • 320*240的显示与640*480的显示不同,这就是为什么最早的游戏(仙剑,金庸等)都是比较模糊的。并不是只改参数或者色彩表就能解决的,还要看显卡的,因为属于SVGA,而不是标准VGA(不过现在的显卡肯定都可以了)。
      • 能告诉我要注意那几方面的东西吗?谢谢。
    • 你可以检查一下调色板的位数设置。
      我不知道你的BMP是多少色的。在VGA模式下,640X480不能支持256色以上。但是如果使用SVGA,那默认的颜色位数为6bits。你可以用8bits的试一下(当然要先check SVGA的设置,因为有时某些SVGA驱动里位数是固定的)。