| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1143 人关注过本帖
标题:问题在哪里
取消只看楼主 加入收藏
sunnyboy1983
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-2-7
收藏
 问题点数:0 回复次数:3 
问题在哪里
以下代码在一些显示器能运行!但一些会出现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
sunnyboy1983
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-2-7
收藏
得分:0 
#define  VBE640X480X24K   0X114这样修改后问题仍然存在

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

2008-05-17 09:55
快速回复:问题在哪里
数据加载中...
 
   



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

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