如何将base 64编码的图像数据转换为图像

时间:2012-04-19 14:50:34

标签: ruby-on-rails image-processing

我正在使用https://www.stormondemand.com/manage/server/7SA43U.html#network创建serevrs。我以base 64编码图像的形式收集了服务器图形数据。如下所示以哈希格式

{"content_type"=>"image/png", "content"=>"iVBORw0KGgoAAAANSUhEUgAAAg0AAADcCAIAAAB8hwVgAAAaEElEQVR4nO3deXBUZbrH8aeX7Cud\nBFkMGEGQAVkEgwIyClgqm8LgAi5DguWoowMDghvl1VQhFI7eDP8YuDBuXC/CVVApcKoww0UgBDAJ\nW9jJsCaY0GTp7Ok+948Tm9DdebM2nQ7fT1FUn3Pefs/znKT6l3NO0m3QNE0AAGiE0dcFAAA6NHIC\nAKBCTgAAVMgJAIAKOQEAUCEnAMA/2Gy2RYsWzZkzZ+HChWVlZc3ZZLVan3rqqTbul5wAAP+wZs2a\nxMRE/f/PPvusyU25ubnz588vKipq437JCQDwD5mZmQ8++KCIjB8/PiMjo8lNGzdufPPNN00mUxv3\na27j8wHAfxkMuzRttK+raC6r1RoTEyMiFovFarU2uemdd95pl/22LCcMBkO77BUAOogb/6rmd++C\n0eLzifLycm/UoZafn9+9e/cbv98bhgb9HQ36qbCwrPLyu+UGNhgWFtbq58bExFitVv2MwWKxNHNT\n23F/AsDNa+vWO3xdQgskJiamp6eLSHp6+siRI5u5qe3ICQDwD7Nnz969e3dSUlJmZmZycrK+8uWX\nX25sU3sxtOhKmcFg4LqTN9Cgv6NBP7VjR9nYsRFyY687+d39Cc4nAAAq5AQAQIWcAACotMPf2Rk3\nbzZUV9v/8IeWPa2iwvQ//2OfM0dEpLjY9N13YjZrISGOiRMlOLh+zKVLpn/+UxyOgP79pUsX03ff\nSU2NmM32xx6T0FDXSX4b7BgzRuvfv+19AQCkHXKirs5w9aqYzVJRUf/a3RwXLph++kkqKvQl09at\njgce0Hr3lkuXjNu2OSZPrl//88/2adMkNDR4xQqjzeYYMULr08dw8qRx+3bHxImuk/w22PT553Zy\nAgDaSVuvOxmOHtX69HHceafx4EF9jemTT0zffGNas8Zw/nz94oYNxvT0656lafannpLAwPrl4mKt\nd28RkR49DPn5zmH2KVMkOlpExGg0nD+v9ekjItoddxguXnSf"}

如何将此数据转换为图像并显示为图像形式..

提前致谢

1 个答案:

答案 0 :(得分:1)

只需对其进行64位解码并输出即可。

require "base64"

image_data = Base64.decode64("iVBORw0KGgoAAAANSUhEUgAAAg0AAADcCAIAAAB8hwVgAAAaEElEQVR4nO3deXBUZbrH8aeX7Cud\nBFkMGEGQAVkEgwIyClgqm8LgAi5DguWoowMDghvl1VQhFI7eDP8YuDBuXC/CVVApcKoww0UgBDAJ\nW9jJsCaY0GTp7Ok+948Tm9DdebM2nQ7fT1FUn3Pefs/znKT6l3NO0m3QNE0AAGiE0dcFAAA6NHIC\nAKBCTgAAVMgJAIAKOQEAUCEnAMA/2Gy2RYsWzZkzZ+HChWVlZc3ZZLVan3rqqTbul5wAAP+wZs2a\nxMRE/f/PPvusyU25ubnz588vKipq437JCQDwD5mZmQ8++KCIjB8/PiMjo8lNGzdufPPNN00mUxv3\na27j8wHAfxkMuzRttK+raC6r1RoTEyMiFovFarU2uemdd95pl/22LCcMBkO77BUAOogb/6rmd++C\n0eLzifLycm/UoZafn9+9e/cbv98bhgb9HQ36qbCwrPLyu+UGNhgWFtbq58bExFitVv2MwWKxNHNT\n23F/AsDNa+vWO3xdQgskJiamp6eLSHp6+siRI5u5qe3ICQDwD7Nnz969e3dSUlJmZmZycrK+8uWX\nX25sU3sxtOhKmcFg4LqTN9Cgv6NBP7VjR9nYsRFyY687+d39Cc4nAAAq5AQAQIWcAACotMPf2Rk3\nbzZUV9v/8IeWPa2iwvQ//2OfM0dEpLjY9N13YjZrISGOiRMlOLh+zKVLpn/+UxyOgP79pUsX03ff\nSU2NmM32xx6T0FDXSX4b7BgzRuvfv+19AQCkHXKirs5w9aqYzVJRUf/a3RwXLph++kkqKvQl09at\njgce0Hr3lkuXjNu2OSZPrl//88/2adMkNDR4xQqjzeYYMULr08dw8qRx+3bHxImuk/w22PT553Zy\nAgDaSVuvOxmOHtX69HHceafx4EF9jemTT0zffGNas8Zw/nz94oYNxvT0656lafannpLAwPrl4mKt\nd28RkR49DPn5zmH2KVMkOlpExGg0nD+v9ekjItoddxguXnSf")