qq_44882950 2019-04-19 21:58 采纳率: 0%
浏览 253

求助大佬,,,将程序数据写入bmp图片并保存到任意盘

#include
#include
#include
#include
#include
#include

typedef long BOOL;
typedef long LONG;
typedef unsigned char BYTE;
typedef unsigned long DWORD;
typedef unsigned short WORD;

typedef struct
{
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BMPFILEHEADER_T;

struct BMPFILEHEADER_S
{
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
};

typedef struct
{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BMPINFOHEADER_T;

typedef struct XET
{
float x;
float dx, ymax;
XET* next;
}AET, NET;

struct point
{
float x;
float y;
};

void generateBmp(BYTE * pData, int width, int height, char * filename) //创建bmp文件
{
int size = width * height * 3;
BMPFILEHEADER_T bfh;
bfh.bfType = 0X4d42;
bfh.bfSize = size
+ sizeof(BMPFILEHEADER_T)
+ sizeof(BMPINFOHEADER_T)
;
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = bfh.bfSize - size;

BMPINFOHEADER_T bih;
bih.biSize = sizeof(BMPINFOHEADER_T);
bih.biWidth = width;
bih.biHeight = height;
bih.biPlanes = 1;
bih.biBitCount = 24;
bih.biCompression = 0;
bih.biSizeImage = size;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;

FILE * fp = fopen(filename, "wb");
if (!fp) return;
fwrite(&bfh, 1, sizeof(BMPFILEHEADER_T), fp);
fwrite(&bih, 1, sizeof(BMPINFOHEADER_T), fp);
fwrite(pData, 1, size, fp);
fclose(fp);

}

int main()
{

struct
{
    BYTE b;
    BYTE g;
    BYTE r;
} pRGB[240][320];
memset(pRGB, 0, sizeof(pRGB));


const int POINTNUM = 6;
point polypoint[POINTNUM] = { 20,30,70,10,130,50,130,110,70,70,20,90, };

void PolyScan();
{
    int MaxY = 0;
    int i;
    for (i = 0; i < POINTNUM; i++)
    {
        if (polypoint[i].y > MaxY)
            MaxY = polypoint[i].y;
    }


    AET *pAET = new AET;
    pAET->next = NULL;

    NET *pNET[1024];
    for (i = 0; i <= MaxY; i++)
    {
        pNET[i] = new NET;
        pNET[i]->next = NULL;
    }
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1, 0, 1);
    glBegin(GL_POINTS);


    for (i = 0; i < MaxY; i++)              //扫描建立NET表
    {
        for (int j = 0; j < POINTNUM; j++)
        {
            if (polypoint[j].y == i)
            {
                if (polypoint[(j - 1 + POINTNUM) % POINTNUM].y > polypoint[j].y)
                {
                    NET *p = new NET;
                    p->x = polypoint[j].x;
                    p->ymax = polypoint[(j - 1 + POINTNUM) % POINTNUM].y;
                    p->dx = (polypoint[(j - 1 + POINTNUM) % POINTNUM].x - polypoint[j].x) / (polypoint[(j - 1 + POINTNUM) % POINTNUM].y - polypoint[j].y);
                    p->next = pNET[i]->next;
                    pNET[i]->next = p;
                }
                if (polypoint[(j + 1 + POINTNUM) % POINTNUM].y > polypoint[j].y)
                {
                    NET *p = new NET;
                    p->x = polypoint[j].x;
                    p->ymax = polypoint[(j + 1 + POINTNUM) % POINTNUM].y;
                    p->dx = (polypoint[(j + 1 + POINTNUM) % POINTNUM].x - polypoint[j].x) / (polypoint[(j + 1 + POINTNUM) % POINTNUM].y - polypoint[j].y);
                    p->next = pNET[i]->next;
                    pNET[i]->next = p;
                }
            }
        }
    }
    for (i = 0; i <= MaxY; i++)    //建立更新活性边表
    {
        NET *p = pAET->next;
        while (p)
        {
            p->x = p->x + p->dx;
            p = p->next;
        }


        AET *tq = pAET;             //AET按照X值从小到大排序
        p = pAET->next;
        tq->next = NULL;
        while (p)
        {
            while (tq->next && p->x >= tq->next->x)
                tq = tq->next;
            NET *s = p->next;
            p->next = tq->next;
            tq->next = p;
            p = s;
            tq = pAET;
        }


        AET *q = pAET;              //从AET中删除ymax == i的结点
        p = q->next;
        while (p)
        {
            if (p->ymax == i)
            {
                q->next = p->next;
                delete p;
                p = q->next;
            }
            else
            {
                q = q->next;
                p = q->next;
            }
        }


        p = pNET[i]->next;          //将NET中的新点加入AET,并用插入法按X值递增排序
        q = pAET;
        while (p)
        {
            while (q->next && p->x >= q->next->x)
                q = q->next;
            NET *s = p->next;
            p->next = q->next;
            q->next = p;
            p = s;
            q = pAET;
        }


        p = pAET->next;               //颜色填充         
        while (p && p->next)
        {
            for (float j = p->x; j <= p->next->x; j++)
            {
                glVertex2i(static_cast<int>(j), i);
            }
            p = p->next->next;
        }
    }
    glEnd();
    glFlush();
}

void init();
{
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0, 200, 0, 200);

}

int main(int argc, char* argv);
{
    glutInit(&argc, &argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(800, 800);
    glutCreateWindow(" OpenGL ");

    init();
    glutDisplayFunc(PolyScan);
    glutMainLoop();
}

generateBmp((BYTE*)pRGB, 320, 240, "f:\\rgb.bmp");

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 求数学坐标画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站