且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建bmp图像文件以顺序表示所有颜色

更新时间:2022-03-12 04:46:33

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

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



完成后关闭文件,然后你可以继续讨论你将要遇到的下一个问题...文件名耗尽... 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.