【问题标题】:Get image size from base64 in C# [duplicate]在C#中从base64获取图像大小[重复]
【发布时间】:2017-06-03 12:20:16
【问题描述】:

如何在 C# 中从base64 获取图像大小

有可能吗?

【问题讨论】:

  • 完全取决于您使用的图像格式。请更具体
  • @Rob 是 PNG 和 JPG
  • @Gigabyte 你可以猜到答案,当然。但这只是一个猜测,这是一个问题。从原始帖子中,以下内容是未知的:为什么 base64 很重要? (问题可能是如何将 base64 读入图像格式)。您使用的是什么图像格式?你说的大小是什么意思?方面?文件大小?

标签: c# image base64


【解决方案1】:

不直接,因为它取决于 Base64 字符串中编码的数据/格式。 一个粗略的方法是(代码未测试):

byte[] image = Convert.FromBase64String("Your Base64 string here");
using (var ms = new MemoryStream(image))
{
    Image img = Image.FromStream(ms);
    return new Tuple<int, int>(img.Width, img.Height); // or some other data container
}

注意:图像类来自System.Drawing。 另请参阅MSDN System.Drawing.Image class' documentation 文档。

【讨论】:

  • 是什么让您认为这是尺寸而不是尺寸?如果那是他所追求的,OP 应该知道指定尺寸而不是尺寸。
  • @JeremyThompson 你说得对,我的速度有点太快了。将相应更新。
猜你喜欢
  • 2014-04-30
  • 1970-01-01
  • 1970-01-01
  • 2015-02-07
  • 2012-02-24
  • 2018-04-10
  • 2018-05-30
  • 2020-03-14
  • 2011-12-15
相关资源
最近更新 更多