作者共发了5篇帖子。 内容转换:不转换▼
 
点击 回复
433 4
【C语言程序】Nokia5110液晶位图取码程序
一派护法 十九级
1楼 发表于:2016-8-5 17:08
#include <stdio.h>
#include <Windows.h>

int main(void)
{
    BITMAP bmp;
    FILE *fp;
    HBITMAP hbmp;
    HDC hdc, hdcMem;
    int x, y, i;
    unsigned char dat;

    hbmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), TEXT("img.bmp"), IMAGE_BITMAP, (int)NULL, (int)NULL, LR_LOADFROMFILE);
    if (hbmp == NULL)
    {
        puts("打开位图失败");
        return 0;
    }

    GetObject(hbmp, sizeof(bmp), &bmp);
    if (bmp.bmWidth == 84 && bmp.bmHeight == 48)
    {
        hdc = GetDC(NULL);
        hdcMem = CreateCompatibleDC(hdc);
        ReleaseDC(NULL, hdc);
        SelectObject(hdcMem, hbmp);

        fopen_s(&fp, "data.c", "w");
        if (fp != NULL)
        {
            fputs("const unsigned char img[][84] = {\n", fp);
            for (y = 0; y < 6; y++)
            {
                fputs("\t{", fp);
                for (x = 0; x < 84; x++)
                {
                    dat = 0;
                    for (i = 0; i < 8; i++)
                    {
                        dat >>= 1;
                        if (GetPixel(hdcMem, x, y * 8 + i) < 0x000010)
                            dat |= 0x80;
                    }
                    if (dat == 0)
                        fputs("0x00", fp);
                    else
                        fprintf(fp, "%#04x", dat);
                    if (x != 83)
                        fputs(", ", fp);
                }
                if (y == 5)
                    fputs("}\n", fp);
                else
                    fputs("},\n", fp);
            }
            fputs("};", fp);
            fclose(fp);
            puts("取码成功!");
        }
        else
            puts("打开c文件失败!");
        DeleteDC(hdcMem);
    }
    else
        puts("图像的尺寸必须为84x48!");
    DeleteObject(hbmp);
    return 0;
}
一派护法 十九级
2楼 发表于:2016-8-5 17:11
【使用方法】
创建一个Visual Studio工程,类型为Win32控制台程序(空项目),然后新建一个Source.c的源文件,将代码复制进去后保存。然后把一张尺寸为84x48的bmp位图放在Source.c所在的文件夹,编译运行程序即可得到data.c文件,其中的内容就是取码得到的内容。
一派护法 十九级
3楼 发表于:2016-8-5 17:13
注意:图像必须是黑白的,尺寸必须为84x48,且格式必须为bmp格式(不能为jpg等其他格式),否则将无法取码!
一派护法 十九级
4楼 发表于:2016-8-5 17:15
【运行结果】
一派护法 十九级
5楼 发表于:2016-8-5 17:16
【生成的C语言代码】

回复帖子

内容:
用户名: 您目前是匿名发表
验证码:
(快捷键:Ctrl+Enter)
 

本帖信息

点击数:433 回复数:4
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2016-8-5 17:16
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。