标题:问题在哪里
只看楼主
sunnyboy1983
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-2-7
 问题点数:0 回复次数:8 
问题在哪里
以下代码在一些显示器能运行!但一些会出现out of range(超出范围)错误·请高手指点:(图片名为logo是BMP类型)
#include <dos.h>
#include <stdio.h>
#include <mem.h>
#include <alloc.h>
#include <stdlib.h>
#include <conio.h>

#define  VBE800X600X64K   0X114
#define RGB(r,g,b) ((((unsigned int)(r)>>3)<<11) + (((unsigned int)(g)>>2)<<5) + ((b)>>3))
#define SCREEN_WIDTH 800L
#define SCREEN_HIGH  600L
#define VARM_GRAPH_800_600_256(x,y)    (((unsigned long)y<<9L)+((unsigned long)y<<8L)+((unsigned long)y<<5L)+((unsigned long)(x)))
#define VARM_GRAPH_800_600_16M(x,y)    (((((unsigned long)y<<9L)+((unsigned long)y<<8L)+((unsigned long)y<<5L))<<1L) + (((unsigned long)x)<<1L))
#define PALETTE_READ  0x3C7
#define PALETTE_WRITE 0x3C8
#define PALETTE_DATA  0x3C9


typedef struct tagBITMAPFILEHEADER
{
    unsigned int bfType;
    unsigned long bfSize;
    unsigned int Reserved1;
    unsigned int reserved2;
    unsigned long bfOffset;
}BITMAPFILEHEADER;


typedef struct tagBITMAPINFOHEADER
{
    unsigned long biSize;
    unsigned long biWidth;
    unsigned long biHeight;
    unsigned int biPlanes;
    unsigned int biBitCount;
    unsigned long biCompression;
    unsigned long biSizeImage;
    unsigned long biXpolsPerMeter;
    unsigned long biYpelsPerMeter;
    unsigned long biClrUsed;
    unsigned long biClrImportant;
}BITMAPINFOHEADER;

typedef struct tagRGBQUAD
{
    unsigned char Blue;
    unsigned char Green;
    unsigned char Red;
    unsigned char Reserved;
}RGBQUAD;

typedef struct  tagRGB16M
{
  unsigned char Blue;
  unsigned char Green;
  unsigned char Red;
}RGB16M;

int  g_cur_vbe_page = 0;


void _Cdecl InitGraph(unsigned int mode)
{
  _AX = 0x4f02;
  _BX = mode;
  __int__(0x10);
  if(_AH != 0)
   {
    puts("Can't Initialize the graphics mode!");
    exit(1);
   }
}



void _Cdecl CloseGraph(void)
{
  _AX = 0x4f02;
  _BX = 0x03;
  __int__(0x10);
}



void _Cdecl set_vbe_page(int page)
{
    if (g_cur_vbe_page != page)
    {
        _BX = 0;
        _DX = g_cur_vbe_page = page;
        _AX = 0x4F05;
        __int__(0x10);
    }
}



void PutPixel16M(int x,int y,int Color)
{
    int page;
    char far *videoptr = (char far *)0xa0000000L;
    long addr = VARM_GRAPH_800_600_16M(x,y);/*移动xy*/

    if (x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HIGH)
    {
    page = (int)(addr >> 16);
        set_vbe_page(page);
    *(videoptr + (unsigned int)(addr & 0xFFFF))= Color & 0xFF;
    *(videoptr + (unsigned int)(addr & 0xFFFF)+1)= Color>>0x08;
    }
}

void Show_BMP(char *File_Name,int k)/*k为缩小倍数*/
{
    int i, j,width ;

    register BITMAPFILEHEADER *FileHead;
    register BITMAPINFOHEADER *InfoHead;
    FILE *fp;

    if ((FileHead = (BITMAPFILEHEADER *)malloc(sizeof(BITMAPFILEHEADER))) == NULL)
        return;
    if ((InfoHead = (BITMAPINFOHEADER*)malloc(sizeof(BITMAPINFOHEADER))) == NULL)
        return;
    if ((fp = fopen(File_Name,"rb")) == NULL)
    {
        printf("BMP File not exist ...");
        return;
    }
    fread(FileHead,sizeof(BITMAPFILEHEADER),1,fp);
    if (FileHead->bfType!='BM')
    {
        printf("BMP File type Error ...");
        fclose(fp);
        return;
    }
    fread(InfoHead,sizeof(BITMAPINFOHEADER),1,fp);
    if (InfoHead->biCompression !=0 || (InfoHead->biBitCount!=8 && InfoHead->biBitCount!=24))
    {
        printf("BMP File not Support Compression type ...");
        fclose(fp);
        return;
    }
    width =((int)InfoHead->biWidth+3)/4*4;
    if ((int)InfoHead->biBitCount == 24)
    {
        register RGB16M *buffer;
        if ((buffer = malloc(width*sizeof(RGB16M))) == NULL)
        {
            fclose(fp);
            return;
        }
    for (j = (int)InfoHead->biHeight-1 ; j >= 0 ; j--)
        {
            fread(buffer,width,sizeof(RGB16M),fp);
            for (i = 0 ; i < width ; i++)
        PutPixel16M(i/k,j/k,RGB(buffer[i].Red,buffer[i].Green,buffer[i].Blue));/*缩放*/
        }

    }
    free(FileHead);
    free(InfoHead);
    fclose(fp);
}




void main(void)
{
    InitGraph(VBE800X600X64K);
    Show_BMP("logo.BMP",1);/*图像大小为800*600没有缩小*/
getch();/*按回车显示下一幅图片*/

    CloseGraph();
}
搜索更多相关主题的帖子: include define unsigned int RGB 
2008-05-13 15:57
sunnyboy1983
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-2-7
得分:0 
编译没问题,运行也没错误。就是显示不出图片。只是显示器显示:超出范围

2008-05-14 09:53
kk4868
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-6-3
得分:0 
显示器的过频保护,很常见的硬件问题。目前没有很好的解决办法。
建议调低分辨率,640*480或者320*200

2008-05-14 13:20
sunyboy1983
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-2-23
得分:0 
请问上楼在程序里怎样改变频率?
2008-05-15 09:35
kk4868
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-6-3
得分:0 
#define  VBE800X600X64K   0X114
这一行,换个显示模式吧
这个是调整屏幕分辨率
调整刷新率的话,非常麻烦的,别想了

2008-05-15 13:56
sunnyboy1983
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-2-7
得分:0 
#define  VBE640X480X24K   0X114这样修改后问题仍然存在

2008-05-15 22:11
kk4868
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-6-3
得分:0 
楼上的,你那相当于什么都没改。。。模式号啊!!!

2008-05-16 10:39
sunnyboy1983
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-2-7
得分:0 
TRY320X200X256    0X013
这样行吗?

2008-05-17 09:55
kk4868
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-6-3
得分:0 
可以的,用这个模式基本不会超频率
建议试一下640*480*256
模式号自己查去

2008-05-17 17:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-214092-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.210087 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved