如何减少文件的大小......在java中
可能的重复:
在 Java 中调整图像大小 - 任何开源库?
InputStream is = new FileInputStream(file);
long length = file.length();
// if (length > Integer.MAX_VALUE) {
// File is too large
// }
byte[] bytes = new byte[(int) length];
如果我输入大图像....它应该接受但尺寸应该减小
Possible Duplicate:
Resize an image in Java - Any Open Source Library ?
InputStream is = new FileInputStream(file);
long length = file.length();
// if (length > Integer.MAX_VALUE) {
// File is too large
// }
byte[] bytes = new byte[(int) length];
if i enter large image....it should accept but size should be reduced
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该使用缓冲区并以缓冲区大小增量读取数据,否则当数据很大时可能会出现问题。
其次,正如其他用户所建议的,您应该使用压缩,或者,由于我们正在讨论图像,如果您处于内存非常有限的环境中,您始终可以将其下采样作为最后一个资源。
First, you should use a buffer and read the data in buffer-size increments, otherwise you will probably have problems when the data is big.
Second, as suggested by other users, you should use compression, or, since we are talking about images, you can always downsample it as a last resource, if you are in a very memory constrained environment.