我搜索以获取C#中图像的文件大小(以字节为单位):
我在base64字符串中获取图像,但在这种格式中,我觉得它无法获得文件大小.
所以我在像这样的图像对象中进行转换:
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(imageSrc);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image imageObj = Image.FromStream(ms, true);
Run Code Online (Sandbox Code Playgroud)
但我无法获得文件大小.我可以有尺寸或类型,但不能有文件大小.
你对此有所了解吗?
您已经拥有图像的大小(以字节为单位),您可以这样得到它:
imageBytes.Length
据我所知,您不希望将其转换为其他格式,只需保存即可,因此您可以将字节直接保存到文件中,这是最简单的解决方案:
File.WriteAllBytes(string yourpath, byte[] yourbytes)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11579 次 |
| 最近记录: |