在C ++中调整文件大小 [英] Resizing a file in C++

查看:159
本文介绍了在C ++中调整文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很惊讶地说我还没有找到关于如何使用C ++标准库调整文件大小的合理解决方案.必须从原始文件中读取数据,然后将其写入另一个文件中,这似乎完全是愚蠢而浪费的.我只是想要一个调整大小的方法,该方法将截断超出该大小的数据...有什么作用吗?

I am surprised to say that I have not found a reasonable solution on how to resize a file using C++ standard libraries. It seems completely stupid and wasteful to have to read in the data from the original file, and then write it into a different file. I simply want a resize method that will chop off the data that goes beyond that size... Is there anything that does this?

如果我必须使用上面说明的方法,那么我用来读取/写入的缓冲区应该有多大?我显然不能一次读取整个文件,因为我在这里处理相当大的文件.

If I do have to use the method I explained above, how large should my buffer be that I'm using to read/write? I obviously can't read the whole file in at once, because I am working with rather large files here.

推荐答案

即使不使用高级语言,在不加载完整图像的情况下调整文件大小也是一项非常复杂的任务,它主要是图像处理SDK(例如

File resize without loading full image is pretty complex task even for higher level languages, it’s mostly a feature of image processing SDKs like Image Magick.

如果对调整尺寸大小或支持的格式没有特殊要求,我想Mark的答案将是最简单的方法.否则,您需要包括图形格式库并手动实现一些调整大小算法(或也使用一些lib).

If there are no specific requirements for resize quality or supported formats I guess Mark’s answer will be the easiest way. Otherwise you need to include graphics format libraries and implement some resize algorithm manually (or use some lib too).

这篇关于在C ++中调整文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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