如何创建bmp图像文件以顺序表示所有颜色 [英] How to create bmp image files to represent all colors sequentially

查看:94
本文介绍了如何创建bmp图像文件以顺序表示所有颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码,我正在尝试创建1000个bmp图像来表示一些颜色。我正在从循环值中写入像素值。此代码的输出只生成508个图像,如果我设置任何for循环它再次只生成508个图像。

我的主要目标是创建16581375所有颜色的图像。

所以请帮助我。



我尝试过的事情:



below is my code in that i'm trying to create 1000 bmp images to represent some colors. i'm writing pixel values from loop values. output of this code generate only 508 images, if i set any for loop it again generate only 508 images.
my main goal is to create 16581375 images of all colors.
so please help me for this.

What I have tried:

#include<stdio.h>
#include<conio.h>

void main()
{
    FILE *fp,*pt;
    unsigned char b=66,c=77,aa[54],x=0,jjj=0,jjjj=0,jjjjj=0,buf[1000];
    unsigned short int d=0,v=1,u=24,o=16973;
    unsigned int g,k=0;
    unsigned long siz=102,i=0,r=0,n=0,s=0,l=1200054,h=54,e=54,f=40,q=4,w=4,a=0,z=0,m=200,ss=0,sss=0;//h=16581375,siz=497441304,w=10
    //printf("%c",b);
    i=0;

   for(i=0;i<10;i++)
    {

        for(r=0;r<10;r++)
        {

            for(n=0;n<10;n++)
           {
               //str=ss+str+stdr;
               sprintf(buf,"all%d.bmp",ss);
               fp=fopen(buf,"wb");
               fwrite(&b,sizeof(char),1,fp);
               fwrite(&c,sizeof(char),1,fp);
               fwrite(&siz,sizeof(long),1,fp);
               fwrite(&d,sizeof(short int),1,fp);
               fwrite(&d,sizeof(short int),1,fp);
               fwrite(&e,sizeof(long),1,fp);
               fwrite(&f,sizeof(long),1,fp);
               fwrite(&q,sizeof(long),1,fp);
               fwrite(&w,sizeof(long),1,fp);
               fwrite(&v,sizeof(short int),1,fp);
               fwrite(&u,sizeof(short int),1,fp);
               fwrite(&z,sizeof(long),1,fp);
               fwrite(&z,sizeof(long),1,fp);
               fwrite(&a,sizeof(long),1,fp);
               fwrite(&a,sizeof(long),1,fp);
               fwrite(&z,sizeof(long),1,fp);
               fwrite(&z,sizeof(long),1,fp);
               for(s=0;s<16;s++)
               {
                 fwrite(&i,sizeof(char),1,fp);
                 fwrite(&r,sizeof(char),1,fp);
                 fwrite(&n,sizeof(char),1,fp);

              }
              ss++;

            }

        }

     }

    getch();
}

推荐答案

如果我读了你,你想为每个可能的颜色创建一个位图文件可以包含。这不一定是个问题,但它不适合你的原因是你的文件句柄用完了。

因为你完成文件后没有关闭文件,系统无法自动释放句柄以便重复使用,而且你用完了,所以你的应用程序停止正常工作。



完成后关闭文件,然后你可以继续讨论你将要遇到的下一个问题...文件名耗尽... 64K是FAT32的每个文件夹的最大文件数限制,300,000是exFAT的限制,因为你的8.3文件名用完了,搜索时间在扩展的文件名的顶部。您可以使用单独的文件夹来解决此问题,但是......然后您遇到了下一个问题:磁盘空间。

每个146字节的16777216个文件已经足够糟糕了:2,449,473,536个字节,但由于每个文件都是一个单独的文件,因此每个文件都需要一个分配单元存储,并且每个单元的可能性为4096字节。所以你需要至少68,719,476,736个字节来存储它们......
If I read you right, you want to create a file for each of the possible colours that a bitmap can contain. That's not necessarily a problem, but the reason it doesn't work for you is that you are running out of file handles.
Because you don't close your files when you are finished with them, the system can't automatically release the handle for reuse, and you run out, so your app stops working properly.

Close your file when you are finished with it, and you can move on to the next problem you are going to meet ... running out of file names ... 64K is a max files-per-folder limit for FAT32, 300,000 is a limit for exFAT as you run out of 8.3 filenames, and search times go through the roof on the extended ones. You can get round this with separate folders, but ... then you meet the next problem: disk space.
16777216 files at 146 bytes each is bad enough: 2,449,473,536 bytes, but since each is a separate file, they will take an allocation unit each to store, and the chances are that each unit is 4096 bytes. So you will need at least 68,719,476,736 bytes free to store them...


Quote:

my main目标是创建16581375所有颜色的图像。

my main goal is to create 16581375 images of all colors.



整个想法对我来说非常错误。

只是因为目录没有排序,找到一个文件涉及顺序读取所有文件名,直到找到您要查找的1。 我担心为每个请求动态构建文件会更快。


The whole idea look very wrong to me.
Just because a directory is not sorted, finding a file involve reading sequentially all file names until you find the 1 you looking for. I fear it will be faster to build the file on fly for each request.

引用:

此代码的输出只生成508个图像

output of this code generate only 508 images



可能你应该学习如何写入文件。


May be you should learn how to write in files.

fp=fopen(buf,"wb");



在C中,您必须关闭您打开的内容。


In C, you must close what you opened.


这篇关于如何创建bmp图像文件以顺序表示所有颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆