发 帖  
原厂入驻New
申请华秋企业认证 多层板首单免费打样!
30s提交资料,10分钟通过审核(免费赔付+顺丰包邮)>>立即报名
[问答] 如何在C代码中转换图形图像(* .bmp,* .jpg等)(而不是通过工具)
951 C代码 转换器
分享
我见过类似的帖子,但从来没有一个图形转换器实际位置的答案。我使用USB连接到我的董事会(拇指/闪存),其中包含一个图像文件。我想/需要采取这个图像文件,并更新我的董事会,使它使用这个图像文件作为溅射SCRE。因此,我在Flash中存储它。我不需要USB帮助——我可以自动检测设备,我可以读取文件。我不需要帮助编程内部闪存(我要么使用闪存驱动器,要么使用NVM模块和谐)。我需要帮助的是如何采取一个标准窗口*.bmp,*.jpg等文件,并将其转换为microchip/HORLL(源代码)期望的格式。当你将图像导入到图形作曲器中时,它会经历一些转换过程,并在\StasyCyFig \debug \Frase\gfx\GFxAsAsET.cS类型中生成一个结构。这始终是GFXUIGIMASSETSET,并且该结构的一部分是指向图像数据的指针。数据部分与原始图像文件完全不同,并且大小也不同(字节)。图形作曲家使用的转换器代码可以用于我们的源代码中吗?(如果是这样,我会在哪里找到它?)或者,将图像文件转换成这些GFXIIVIEWASESET结构的转换过程是什么?谢谢,凯文

以上来自于百度翻译


      以下为原文

    I have seen similar posts about this, but never an answer of where a Graphics converter actually is located.

I am using a USB connection to my board (thumb/flashdrive) that contains an image file.
I want/need to take this image file and update my board so that it uses this image file as a Splash screen - thus store it in Flash.

I don't need help with USB - I have that working - I can auto detect the device, and I can read the file.
I don't need help with programming internal Flash (I'll either use the flash driver, or maybe use the NVM module in HARMony).

What I do need help with is how to take a standard Windows *.bmp, *.jpg, etc. file and convert it into the format that microchip/Harmony (source code) expects.
When you import an image into the Graphics Composer - it goes through some conversion process and generates a structure in \system_config\default\framework\gfx\gfx_assets.c
The type of this is always  GFXU_ImageAsset  - and one piece of this structure is a pointer to the data of the image.  
The data section is definitely dIFferent than the original image file - and is a different size (in bytes) as well.

Is the Converter code that the Graphics Composer uses available for us to use in our source code? (if so where would I find it?)
or...
What is the conversion process for converting image files into these GFXU_ImageAsset structures?

Thanks,
Kevin
0
2018-9-3 16:30:14   评论 分享淘帖 邀请回答

相关问题

19个回答
我能够阅读BMP(易)和JPG(复杂但可行的通过图书馆)…但是我不太确定你想要的输出格式:我过去看了一下它…如果你知道它是怎样的,那么一旦你在内存中有了解码后的位图,你就可以很容易地将它写入其他格式(特别是“容易”)。

以上来自于百度翻译


      以下为原文

    I am able to read BMP (easy) and JPG (complicated but doable via libraries)... but am not so sure about the output format you're asking for: I took some quick look at it in the past... no more.
 
If you know "how" it is, then - once you have the decoded bitmap in memory, you can easily write it into other formats (especially "easy" such as those).
2018-9-3 16:38:46 评论

举报

不确定如何做到这一点,但我用MLA编码了类似的函数。在MLA中,有低级别的调用将单个像素放在屏幕上;设置颜色以设置像素的颜色,并将像素添加到像素和指定的X和Y位置。我假设和声有相似的功能。最容易处理的图形格式是BMP。文件格式很简单,由三个部分组成,即头部的PaleTIT位图。头部给出了像X和Y的图像尺寸和其他两个部分的起始地址的信息。调色板部分是一个颜色列表,调色板中的每个颜色的索引由位图部分引用。例如,假设调色板中的索引3是蓝色的,索引5是绿色的,位图部分中的序列3、3、5、3给出三个蓝色像素和一个绿色像素。代码非常简单。1)从头部2得到高度和宽度。从头部3得到调色板的起始地址。他为位图中的每一个像素从位图4的循环开始位图的地址。5)获得位图条目(调色板索引)6)查找调色板表7中的颜色)将像素放在屏幕上,最好使用256色位图,这意味着调色板有256个条目和8位索引,因此位图中的每个条目是8位值。TTECHE/BMP/BMPFILFATAT.HTM对文件格式细节有很好的描述。

以上来自于百度翻译


      以下为原文

    Not sure how to do this in Harmony, but I coded a similar function using MLA.  In MLA there is are low level calls to put single pixels on the screen; SetColor to set the color of a pixel, and PutPixel to add a pixel and a specified x and y location).   I am assuming Harmony has similar functions.   
 
The easiest graphics format to deal with is BMP.  The file format is simple, consisting of three parts 
A header
A Palette
A Bitmap.
 
The header gives information like the x and y dimensions of the image, and the start addresses of the other two sections.   The palette section is a list of colors and the index of each color in the palette is referenced by the bitmap section.  For example, say that index 3 in the palette is blue , and index 5 is green, the sequence 3,3,5,3 in the bitmap section with give three blue pixels and one green pixel.  
 
The code is pretty simple
 
1) Get the height and width from  the header
2) Get the start address of the palette from the header
3) Get the start address of the bitmap from the header
4) Loop for each pixel in the bitmap.
      5) Get a bitmap entry (palette index)
      6) Look up the color in the palette table
      7) Put the pixel on the screen
 
Its best to stick with a 256 color bitmap, which means the palette has 256 entries and an 8 bit index, so each entry in the bitmap is an 8 bit value.
 
http://www.dragonwins.com/domains/getteched/bmp/bmpfileformat.htm  has a very good description of the file format details.
 
 
2018-9-3 16:51:05 评论

举报

也许和声使用塞格位图转换器工具。相关的SEGGER文档可能有助于输出格式。

以上来自于百度翻译


      以下为原文

    Maybe Harmony uses the Seger Bitmap Converter Tool.
The associated Segger documentation might help with the output format
   Attached Image(s)

2018-9-3 17:10:48 评论

举报

我理解Windows *.bmp文件的格式,而且是的,我可以在屏幕上绘制单个像素(我不打算这样做)。(而不是试图粗鲁)-但是说你可以很容易地读BMP,但没有告诉我更多关于这并没有真正帮助我回答我的问题。我要求的代码,现有的微芯片和谐图形作曲家使用时,你添加一个新的“图像资产”到项目。这个工具已经TAKES在任何类型的图像中(*.bmp,*.jpg等),它创建了格式/Strut GFXIIGIMAEASETE格式的源代码。是否有人知道哪里有代码来执行这个相同的函数?谢谢,

以上来自于百度翻译


      以下为原文

    I understand the format of windows *.bmp files and such - and yes I could plot individual pixels on the screen (I'm not going to do that).  
And (not trying to be rude) - but saying you can easily read BMP, but not telling me much more about that doesn't really help me answer my question.
 
I'm asking for the code that the existing Microchip Harmony Graphics Composer uses when you add a new "Image Asset" to the project.
This tool already takes in any type of image (*.bmp, *.jpg, etc) and it creates the source code that is in the format of the type/struct  GFXU_ImageAsset.
 
Does anyone know where there is code to perform this same function?
 
Thanks,
2018-9-3 17:26:38 评论

举报

图像资产转换发生在图形作曲工具中,它在Java中,在和声C代码中不可用。库在运行时不进行资产生成/转换。

以上来自于百度翻译


      以下为原文

    The image asset conversion happens in the Graphics Composer tool, which is in Java and is not available in the Harmony C code. The library does not do asset generation/conversion at run-time.
 
 
2018-9-3 17:42:55 评论

举报

另外,当没有可用的C代码自动从图像文件创建GFXIIVIAsSeSt结构时,应该很容易编写一个代码。代码需要定义和生成图像文件的二进制数据作为UTI88T字节数组,创建一个GFXIMAIGASESET结构描述了图像文件(格式、尺寸、颜色模式、压缩等),并设置了数据地址指针的GFXUIMAICASSET结构指向二进制数据。

以上来自于百度翻译


      以下为原文

    To add, while there is no available C code that automatically creates a GFXU_ImageAsset structure from an image file, it should be fairly easily to write one.
 
The code will need to define and generate the binary data of the image file as a uint8_t byte array, create a GFXU_ImageAsset structure that describes the image file (format, dimensions, color mode, compression, etc.) and set the data address pointer of the GFXU_ImageAsset structure to point to the binary data.
2018-9-3 18:02:32 评论

举报

这就是我的意思。那么,哦,我们从哪里开始呢?你能阅读BMP文件,还是我们应该从基本的信息?我想我有一个C源,把1位单色BMP转换成C数组,可以作为初学者使用。

以上来自于百度翻译


      以下为原文

   


This is what I meant. So, @OP, where could we start? Can you read a BMP file as well or should we start from the basic infos - headers etc?
I think I have a C source that converts a 1-bit monochrome BMP into a C array, could be useful as a starter
2018-9-3 18:21:47 评论

举报

DarioGCan,你分享…?

以上来自于百度翻译


      以下为原文

    @DarioG

 
Can you share that ..?
2018-9-3 18:34:42 评论

举报

当然,它是Windows的C++。我发布了这个函数,它包括两个选项:“翻转”(明显的含义)和“FAI ARAYUNICOC”,它应该是一个数组而不是许多更小的数组——这被认为是将一组BMP文件转换成C数组。阳离子!

以上来自于百度翻译


      以下为原文

    Sure
It's C++ for Windows. I'm posting this function which does it all, including a couple of options: "flipped" (obvious meaning) and "fai ArrayUnicoC" which should make one single array instead of many smaller ones - this was thought for converting a bunch of BMP files into C arrays.
 
Hope it helps and check back for clarifications!

int CFlashIconsDoc::ExportBmp(const char *n,DWORD mode,BOOL isLast,BYTE *pByte,DWORD pStart,DWORD *pLen) {
    DWORD col[256], row[256];
    CFile f1;
    CStdioFile f2;
    BITMAPFILEHEADER bmf;
    BITMAPINFOHEADER bmh;
    register int i,j,x,y;
    int x3,myWidth,myMask;
    int retVal;
    BYTE ch;
    static int Cnt;
    CListView *v=(CListView *)getView();
    LV_ITEM myLV;

    myLV.mask=LVIF_TEXT;
    myLV.iItem=0;
    myLV.iSubItem=0;            // settato di volta in volta
    myLV.pszText="";            // settato di volta in volta
    myLV.lParam = 0;
    myLV.iImage = 0;


    BOOL flipped = TRUE;

    if(pLen)
        *pLen=0;

    f1.Open(n,CFile::modeRead);
    f2.Open(theApp.bTipoCodice ? "c:\\icondump.c" : "c:\\icondump.asm",mode ? CFile::modeWrite : CFile::modeCreate | CFile::modeWrite);
    if(mode) {
        f2.Seek(0,CFile::end);
        Cnt++;
        }
    else {
        Cnt=0;
        if(faiArrayUnicoC) {
            CString S;
            S.Format("const rom unsigned char Font[] = {                                      \n");        //lascio spazi per tornare dopo a riempire...
            f2.WriteString(S);
            }
        }

    myLV.iItem=v->GetListCtrl().GetItemCount();
    myLV.iSubItem=0;            // settato di volta in volta
    myLV.pszText=(char *)n;            // settato di volta in volta
    v->GetListCtrl().InsertItem(&myLV);

    f1.Read(&bmf,sizeof(BITMAPFILEHEADER));
    f1.Read(&bmh,sizeof(BITMAPINFOHEADER));

    CString S;
    S.Format("BITMAP: %ux%u %u %u %u", bmh.biWidth, bmh.biHeight, bmh.biPlanes, bmh.biBitCount, bmh.biClrUsed);        //** DEBUG!
    myLV.iItem=v->GetListCtrl().GetItemCount();
    myLV.iSubItem=1;
    myLV.pszText=(char *)(const char *)S;
    v->GetListCtrl().InsertItem(&myLV);


    if(theApp.bTipoCodice) {
        if(faiArrayUnicoC) {
//            S.Format("const rom unsigned char Font[] = {\t\t\t// %s",n);            // NO! va spostato sopra, fuori dal loop di lista
            S.Format("// %s",n);
            }
        else
            S.Format("const rom unsigned char Icon%02u[] = {\t\t\t// %s",Cnt,n);
        }
    else
        S.Format("Icon%02u:\t\t\t; %s",Cnt,n);
    f2.WriteString(S);
    if(theApp.bTipoCodice) {
        if(faiArrayUnicoC)
            f2.WriteString("\n{");
        S.Format("\n\t// dim. X*Y, in byte: %u,%u\t\t\n", (bmh.biWidth +7)/ 8,bmh.biHeight);
        }
    else
        S.Format("\n\tdt %u,%u\t\t; dim. X*Y, in byte\n", (bmh.biWidth +7)/ 8,bmh.biHeight);
    f2.WriteString((LPCTSTR)S);
    if(pByte) {
        pByte[pStart++]=(bmh.biWidth +7) / 8;
        pByte[pStart++]=bmh.biHeight;
        if(pLen)
            (*pLen)+=2;
        }

    f1.Seek(sizeof(BITMAPFILEHEADER) + bmf.bfOffBits,CFile::begin);
    j = bmh.biClrUsed;
    if(j > 0) {
        for(i=0; i<bmh.biClrUsed; i++) {
            f1.Read(&col,4);
            }
        }

    f1.Seek(bmf.bfOffBits,CFile::begin);


    if(flipped) {

        myWidth=bmh.biWidth/8;
        myWidth+=3;
        myWidth &= 0xfffffffc;        // DWORD align

        f1.Seek(bmf.bfOffBits+bmh.biHeight*myWidth,CFile::begin);

        switch(bmh.biBitCount*bmh.biPlanes) {
            case 1:
                myMask=0;
                i=8-bmh.biWidth-(bmh.biWidth/8) *8;
                i &= 7;
                while(i--) {
                    myMask <<= 1;            // entra 0
                    myMask |= 1;            // entra 1
                    }

                for(y=0; y<bmh.biHeight; y++) {
                    f1.Seek(bmf.bfOffBits + ((bmh.biHeight-1 - y) * myWidth),CFile::begin);

                    if(theApp.bTipoCodice)
                        f2.WriteString("\t");
                    else
                        f2.WriteString("\tdt ");
                    x3 = 0;
                    for(x=0; x<bmh.biWidth; x+=8) {
                        f1.Read(&ch,1);
                        if(x >= (bmh.biWidth /*- 1  2009??? */ - 8))            // rattoppa l'ultimo byte
                            ch |= myMask;
                        S.Format("0x%02X",~ch & 255);
                        f2.WriteString(S);
                        
                        if(pByte) {
                            pByte[pStart++]=~ch;
                            if(pLen)
                                (*pLen)++;
                            }

                        if(theApp.bTipoCodice) {
                            f2.WriteString(",");
                            }
                        else {
                            if(x < (bmh.biWidth /* - 1  2009 ???*/ - 8)) {
                                f2.WriteString(",");
                                }
                            }
                        }
                    //ci sono 2 byte di troppo, x ogni riga... il DWORD-ALIGN!
                    for(; x<(myWidth*8); x+=8)
                        f1.Read(&ch,1);
                    if(theApp.bTipoCodice)
                        f2.WriteString("\n");
                    else
                        f2.WriteString("\n");
                    }
                if(theApp.bTipoCodice) {
                    if(faiArrayUnicoC)
                        f2.WriteString("\t},\n");
                    else
                        f2.WriteString("\t};\n");
                    }
                else
                    f2.WriteString("\n");

                retVal=1;
                break;
 
            case 4:
            case 8:
            case 24:
            default:
                S="Formato colore non supportato!";
                myLV.iItem=v->GetListCtrl().GetItemCount();
                myLV.iSubItem=1;
                myLV.pszText=(char *)(const char *)S;
                v->GetListCtrl().InsertItem(&myLV);
                retVal=0;
                break;
            }
        }

    else {

        myWidth=bmh.biWidth/8;
        myWidth+=3;
        myWidth &= 0xfffffffc;        // DWORD align

        switch(bmh.biBitCount*bmh.biPlanes) {
            case 1:
                myMask=0xffffffff;
                i=(((bmh.biWidth+7)/8)*8-(bmh.biWidth*8)) /8;
                while(i--) {
                    myMask <<= 1;            // entra 0
                    }

                for(y=0; y< bmh.biHeight ; y++) {
                    if(theApp.bTipoCodice)
                        f2.WriteString("\t{ ");
                    else
                        f2.WriteString("\tdt ");
                    x3 = 0;
                    for(x=0; x< bmh.biWidth; x+=8) {
                        f1.Read(&ch,1);
                        ch &= myMask;
                        S.Format("0x%02X",~ch & 255);
                        f2.WriteString(S);

                        if(pByte) {
                            pByte[pStart++]=~ch;
                            if(pLen)
                                (*pLen)++;
                            }

                        if(x < (bmh.biWidth - 1 - 8)) {
                            if(theApp.bTipoCodice)
                                f2.WriteString("\t, ");
                            else
                                f2.WriteString(",");
                            }

                        }
                    //ci sono 2 byte di troppo, x ogni riga... il DWORD-ALIGN!
                    for(; x<(myWidth*8); x+=8)
                        f1.Read(&ch,1);

                    if(theApp.bTipoCodice)
                        f2.WriteString("\t}");
                    else
                        f2.WriteString("\n");
                    }
                retVal=1;
                break;
            case 4:
            case 8:
            case 24:
            default:
                S="Formato colore non supportato!";
                myLV.iItem=v->GetListCtrl().GetItemCount();
                myLV.iSubItem=1;
                myLV.pszText=(char *)(const char *)S;
                v->GetListCtrl().InsertItem(&myLV);
                retVal=0;
                break;
            }
        }    // flipped


    if(isLast) {
        if(theApp.bTipoCodice) {            
            if(faiArrayUnicoC) {
                f2.WriteString("};");            // NO! va spostato sopra, fuori dal loop di lista
                f2.Seek(0,CFile::begin);
                S.Format("const rom unsigned char Font[%u][%u] = {",Cnt+1,(bmh.biWidth +7)/ 8 * bmh.biHeight);            // vado a completare sopra...
                // naturalmente la cosa dei Font ASSUME "icone" tutte uguali!!
                f2.WriteString(S);
                }
            }
        }

    f2.WriteString("\n");
    f2.Close();
    f1.Close();

    return retVal;
    }

 
2018-9-3 18:49:05 评论

举报

@ DarioG…谢谢更新……我正在尝试打印图片的值、大小和名称。我已经尝试并能够读取图像ButtTable的BMP头来读取图像的像素值。图像比特深度:1图像属性:1填充我已经丢失…请更新…TS9

以上来自于百度翻译


      以下为原文

    @DarioG ...
 
Thanks for update...
I am trying to print Hex Values , Size and Name of Image .
I have tried and  able to read Bmp Header of Image but unable to read pixel value of image .
 
Image Bit-depth    :    1

 
Image Attributes   :    
 
Padding I have missing ....
 
 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct BitMap
{
short Type;
long Size;
short Reserve1;
short Reserve2;
long OffBits;
long biSize;
long biWidth;
long biHeight;
short biPlanes;
short biBitCount;
long biCompression;
long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
long biClrUsed;
long biClrImportant;
} Header;
int main( void )
{
int Horizontal= 0 ,Vertical = 0 ;
unsigned char pixelValue =0 ;
FILE *BMPFile = fopen ("9601.bmp", "r");
if (BMPFile == NULL)
return;
fread(&Header.Type, sizeof(Header.Type), 1, BMPFile);
fread(&Header.Size, sizeof(Header.Size), 1, BMPFile);
fread(&Header.Reserve1, sizeof(Header.Reserve1) , 1, BMPFile);
fread(&Header.Reserve2, sizeof(Header.Reserve2) , 1, BMPFile);
fread(&Header.OffBits, sizeof(Header.OffBits), 1, BMPFile);
fread(&Header.biSize, sizeof(Header.biSize), 1, BMPFile);
fread(&Header.biWidth, sizeof(Header.biWidth), 1, BMPFile);
fread(&Header.biHeight, sizeof(Header.biHeight) , 1, BMPFile);
fread(&Header.biPlanes, sizeof(Header.biClrUsed), 1, BMPFile);
fread(&Header.biBitCount, sizeof(Header.biBitCount), 1, BMPFile);
fread(&Header.biCompression, sizeof(Header.biCompression), 1, BMPFile);
fread(&Header.biSizeImage, sizeof(Header.biSizeImage), 1, BMPFile);
fread(&Header.biXPelsPerMeter, sizeof(Header.biXPelsPerMeter), 1, BMPFile);
fread(&Header.biYPelsPerMeter, sizeof(Header.biYPelsPerMeter), 1, BMPFile);
fread(&Header.biClrUsed, sizeof(Header.biClrUsed), 1, BMPFile);
fread(&Header.biClrImportant, sizeof(Header.biClrImportant), 1, BMPFile);
printf("\nType:%hd and Type in %x\n", Header.Type,Header.Type);
printf("Size:%ld\n", Header.Size);
printf("Reserve1:%hd\n", Header.Reserve1);
printf("Reserve2:%hd\n", Header.Reserve2);
printf("OffBits:%ld\n", Header.OffBits);
printf("biSize:%ld\n", Header.biSize);
printf("Width:%ld\n", Header.biWidth);
printf("Height:%ld\n", Header.biHeight);
printf("biPlanes:%hd\n", Header.biPlanes);
printf("biBitCount:%hd\n", Header.biBitCount);
printf("biCompression:%ld\n", Header.biCompression);
printf("biSizeImage:%ld\n", Header.biSizeImage);
printf("biXPelsPerMeter:%ld\n", Header.biXPelsPerMeter);
printf("biYPelsPerMeter:%ld\n", Header.biYPelsPerMeter);
printf("biClrUsed:%ld\n", Header.biClrUsed);
printf("biClrImportant:%ld\n\n", Header.biClrImportant);

for(Vertical = 0 ; Vertical < Header.biHeight ; Vertical ++)
{
for(Horizontal = 0 ; Horizontal < Header.biWidth ; Horizontal++)
{
fread(&pixelValue, sizeof(pixelValue), 1, BMPFile);
printf("%x ",pixelValue) ; ;
}
// Padding in Missing Here
printf("\n") ;
}
fclose(BMPFile);
return 0;
}

 
Please Update..
 
--
TS9
2018-9-3 18:58:44 评论

举报

对不起,你被困在哪里?你得到的头信息正确,你不能得到像素数据?在1x1中,每个像素有一个比特…

以上来自于百度翻译


      以下为原文

    Sorry, where are you stuck at?
 
You got the Header info correctly, and you are not able to get pixel data? In 1x1, there is one bit per pixel...
2018-9-3 19:06:50 评论

举报

@ DarioG…感谢更新…我附上我的代码(检查PC),图像1-BPP和它的输出在十六进制编辑器.. C程序应该匹配的HEX编辑器..它不匹配我的程序…再次感谢……TS9

以上来自于百度翻译


      以下为原文

    @DarioG ...
 
Thanks for update...

I am attaching my code (checking in PC) , Image 1-bpp  and It's output in hex editor ..
The C program should match with hex editor ..
It is not matching with mine program.. Thanks Again ..
 
--
TS9
2018-9-3 19:17:07 评论

举报

@ DarioG…感谢更新…我附上我的代码(检查PC),图像1-BPP和它的输出在十六进制编辑器.. C程序应该匹配的HEX编辑器..它不匹配我的程序…再次感谢……TS9

以上来自于百度翻译


      以下为原文

    @DarioG ...
 
Thanks for update...

I am attaching my code (checking in PC) , Image 1-bpp  and It's output in hex editor ..
The C program should match with hex editor ..
It is not matching with mine program.. Thanks Again ..
 
--
TS9
   Attachment(s)

ReadBitmap in C.zip (56.94 KB) - downloaded 10 times
2018-9-3 19:31:31 评论

举报

好的,为了使事情“更正确”,你应该处理单个像素,即比特(因为这是一个单色位图),因此用一个面具,0x80…0x40…0x20…等等,但是为了重新创建那个HEX文件,上面应该工作。让我检查一下…

以上来自于百度翻译


      以下为原文

    Ok,
well, to make things "more correct" you should be dealing with single pixels i.e. bits (since this is a monochrome bitmap) and hence ANDing the value with a mask, 0x80.. 0x40.. 0x20... and so on.
 
But just to recreate that HEX file, the aboce should work. let me check...
2018-9-3 19:49:49 评论

举报

你能从C代码中张贴“实际输出”吗?

以上来自于百度翻译


      以下为原文

    Can you post the "actual output" from your C code?
 
2018-9-3 20:09:36 评论

举报

@ DarioG…再次感谢更新…请检查附件…我得到不想要的位(像素)连同相关的数据…-TS9

以上来自于百度翻译


      以下为原文

    @DarioG ...
Thanks for update...Again .. 
 
Please Check the attachment... I am getting unwanted bits(pixels) along with relevant data...
--
TS9
   Attachment(s)

ReadBitmap in C_Output.zip (168.76 KB) - downloaded 8 times
2018-9-3 20:20:16 评论

举报

啊JA,在BITMAPFILHEAD和BITMAPIN表头之后得到了调色板!通常一个4字节的数组(R,G,B,额外)重复的颜色总数:在你的情况下,8字节。你必须阅读或跳过它。当然,您应该只使用来自BITMAPFILHEADER结构的信息,它将告诉您实际像素的起始位置。

以上来自于百度翻译


      以下为原文

    Ah ja, got it
After BITMAPFILEHEADER and BITMAPINFOHEADER there is Palette!
Usually an array of 4 byte (R, G, B, extra) repeated for the total number of colors: in your case, 8 bytes.
You have to read or skip it. To be sure, you should just use the information in the
bfOffBits

from the BITMAPFILEHEADER struct, which will tell you where the actual pixel begin
2018-9-3 20:29:48 评论

举报

再次感谢…我没有得到…你能更新或指导我修改代码吗?如果可能的话,在十六进制编辑器中获得精确的输出,如1个BPP图像TS9

以上来自于百度翻译


      以下为原文

    Thanks again...

I am not getting actually..
Can you update or guide me modification in code ? If possible...

To get exact output as in hex editor for 1 bpp image

Thanks TS9
2018-9-3 20:44:03 评论

举报

以上来自于百度翻译


      以下为原文

   
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct BitMap
{
                  short     Type;
                  long      Size;
                  short     Reserve1;
                  short     Reserve2;
                  long      OffBits;
                  long      biSize;
                  long      biWidth;
                  long      biHeight;
                  short     biPlanes;
                  short    biBitCount;
                  long      biCompression;
                  long      biSizeImage;
                  long      biXPelsPerMeter;
                  long      biYPelsPerMeter;
                  long      biClrUsed;
                  long      biClrImportant;
                } Header;
int main( void )
{
                    int Horizontal= 0 ,Vertical = 0 ;
                    unsigned char pixelValue =0 ;

                  FILE *BMPFile = fopen ("3.bmp", "r");
                    if (BMPFile == NULL)
                            return;
              fread(&Header.Type,                  sizeof(Header.Type), 1, BMPFile);
              fread(&Header.Size,                    sizeof(Header.Size), 1, BMPFile);
              fread(&Header.Reserve1,         sizeof(Header.Reserve1) , 1, BMPFile);
              fread(&Header.Reserve2,         sizeof(Header.Reserve2) , 1, BMPFile);
              fread(&Header.OffBits,             sizeof(Header.OffBits), 1, BMPFile);
              fread(&Header.biSize,                sizeof(Header.biSize), 1, BMPFile);
              fread(&Header.biWidth,            sizeof(Header.biWidth), 1, BMPFile);
              fread(&Header.biHeight,           sizeof(Header.biHeight) , 1, BMPFile);

              fread(&Header.biPlanes,                           sizeof(Header.biClrUsed),  1, BMPFile);
              fread(&Header.biBitCount,                      sizeof(Header.biBitCount), 1, BMPFile);
              fread(&Header.biCompression,              sizeof(Header.biCompression), 1, BMPFile);
              fread(&Header.biSizeImage,                    sizeof(Header.biSizeImage), 1, BMPFile);
              fread(&Header.biXPelsPerMeter,         sizeof(Header.biXPelsPerMeter), 1, BMPFile);
              fread(&Header.biYPelsPerMeter,         sizeof(Header.biYPelsPerMeter), 1, BMPFile);

              fread(&Header.biClrUsed,                        sizeof(Header.biClrUsed), 1, BMPFile);
              fread(&Header.biClrImportant,             sizeof(Header.biClrImportant),  1, BMPFile);

              printf("\nType:%hd   and Type in  %x\n", Header.Type,Header.Type);
              printf("Size:%ld\n", Header.Size);
              printf("Reserve1:%hd\n", Header.Reserve1);
              printf("Reserve2:%hd\n", Header.Reserve2);
              printf("OffBits:%ld\n", Header.OffBits);
              printf("biSize:%ld\n", Header.biSize);
              printf("Width:%ld\n", Header.biWidth);
              printf("Height:%ld\n", Header.biHeight);
              printf("biPlanes:%hd\n", Header.biPlanes);
              printf("biBitCount:%hd\n", Header.biBitCount);
              printf("biCompression:%ld\n", Header.biCompression);
              printf("biSizeImage:%ld\n", Header.biSizeImage);
              printf("biXPelsPerMeter:%ld\n", Header.biXPelsPerMeter);
              printf("biYPelsPerMeter:%ld\n", Header.biYPelsPerMeter);
              printf("biClrUsed:%ld\n", Header.biClrUsed);
              printf("biClrImportant:%ld\n\n", Header.biClrImportant);


                for(Vertical = 0 ;    Vertical <  Header.biHeight ;  Vertical ++)
                 {
                        for(Horizontal = 0 ; Horizontal <  Header.biWidth ;  Horizontal++)
                      {
                              fread(&pixelValue, sizeof(pixelValue), 1, BMPFile);
                              printf("%x   ",pixelValue) ; ;
                      }
                      // Padding in Missing Here
                       printf("\n")  ;
                 }
                fclose(BMPFile);

  return 0;
}

 
2018-9-3 20:57:52 评论

举报

只有小组成员才能发言,加入小组>>

57个成员聚集在这个小组

加入小组

创建小组步骤

关闭

站长推荐 上一条 /10 下一条

快速回复 返回顶部 返回列表