本文介绍了如何在VB.NET中将大字节数组转换为base 64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前已经问过这个问题,但我没有得到答案。我试图从oracle获取blob数据并读取它,而不是将我的Byte数组转换为base 64,这样我可以在我的网页中显示我的图像。但问题是我的blob非常庞大,每个数组字节长度超过1 500 000,因此转换失败并显示图像图标而不是真实图像。如果我无法将大量数据转换为base64,还有另一种获取图像并显示它们的方法吗?帮助非常感谢!



我尝试过:



你可以查看上面提到的链接

I have asked this question before but I got no answer. I am trying to get blob data from oracle and read it, than converting my Byte Array to base 64 so I can display later my image in my web page. But the problem is that my blobs are so huge, each array byte length is more than 1 500 000, so conversion is failed and an image icon is displayed instead of the real image. If I can't convert huge data to base64 is there another way to get images and display them? helps are more than appreciated!

What I have tried:

You can check the link mentioned above

推荐答案

Dim rawData As Byte() = File.ReadAllBytes("D:\Test Data\BigImage.jpg")
Dim base64 As String = Convert.ToBase64String(rawData)
Console.WriteLine("{0}:{1}", rawData.Length, base64.Length)



给我:


Gives me:

3489676:4652904

哪个输入图像数据文件的大小是给您带来问题的两倍。好吧,我不是从Oracle读取我的数据 - 它来自一个文件所以我知道它是一个大图像 - 但是一旦它在一个数组中,就系统而言只是数据。

所以我首先要查看你的代码,然后确定你正在做什么,然后再决定是否导致你的问题转换为base64。





您可以尝试在img标签中实现转换后的图像吗?





对我来说工作正常!

Which is an input image data file twice the size of the ones giving you problems. OK, I'm not reading my data from Oracle - it's coming from a file so I know it's a "large image" - but once it's in an array it's just data as far as the system is concerned.
So I'd start by looking at your code and working out exactly what you are doing, before deciding it's the conversion to base64 that is causing your problem.


"can you try to implement your converted image in img tag ?"


Works fine for me!

byte[] rawData = File.ReadAllBytes(@"D:\Test Data\BigImage.jpg");
string base64 = Convert.ToBase64String(rawData);
Response.Write(string.Format("<img src=\"data:image/jpg;base64,{0}\">", base64));




Dim rawData As Byte() = File.ReadAllBytes("D:\Test Data\BigImage.jpg")
Dim base64 As String = Convert.ToBase64String(rawData)
Response.Write(String.Format("<img src=""data:image/jpg;base64,{0}"">", base64))



不可否认,我的浏览器看起来并不漂亮,有一个肮脏的3880x4997图片,但是......它可以工作。


Admittedly, my browser doesn't look pretty with a dirty great 3880x4997 image slapped into it, but...it works.


这篇关于如何在VB.NET中将大字节数组转换为base 64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多