【问题标题】:Visual Basic Reading Saving Images Into AccessVisual Basic 阅读将图像保存到访问中
【发布时间】:2016-01-05 05:29:13
【问题描述】:

有人可以给我解释一下这段代码吗,为了你的信息,我正在尝试保存显示在图片框中的图片并将其保存到 Microsoft access 数据库中,我不明白什么意思,尤其是 0。

 If Not PictureBox1.Image Is Nothing Then

            Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
            Dim breader As New BinaryReader(fsreader)
            Dim imgbuffer(fsreader.Length) As Byte
            breader.Read(imgbuffer, 0, fsreader.Length)
            fsreader.Close()

【问题讨论】:

  • 你的代码是 VB.NET,不是 VBA
  • 如果您想知道方法的参数是什么意思,那么显而易见的事情就是阅读该方法的 MSDN 文档。 VS 中有一个帮助菜单是有原因的。
  • sn-p 与 MS-Access 有什么关系?

标签: vb.net


【解决方案1】:

您的 sn-p 代码是将图片的二进制文件保存到 VB.Net 中的 imgbuffer 变量的代码。这个 sn-p 代码没有将此图像保存到 Ms Access 中。但是……

我会试着解释一下,这段代码是如何工作的:

If Not PictureBox1.Image Is Nothing Then 'This code for checking if there's any images in the picture box, if it's so run next code.
    Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)  'This variable declared for getting file name, access file and the read mode. And open it using `Filestream` variable, so after it's opened, the length of images will be saved into `fsreader` variable
    Dim breader As New BinaryReader(fsreader) 'This code for reading the binary of images from `fsreader` variable and put the image buffer from range of byte to a variable
    Dim imgbuffer(fsreader.Length) As Byte  'This variable is use to collect image buffer with specified length of binary images from `fsreader` variable.
    breader.Read(imgbuffer, 0, fsreader.Length) 'This code is use for reading binary of images with specified length of byte and put the image buffer into a imgbuffer variable. The number `0` in the brackets means the binary images will be put fully in imgbuffer. Why `0` ? can I use larger than `0` ? yes you can but the image will be corrupt or differ from the original, so you must read the binary images from 0 to the image file size.
    fsreader.Close() 'This is for closing `fsreader` from accessing images file.

那么,接下来是什么?

从该 sn-p 代码中,您可以使用VB.Net 中提供的一些库集合(如OleDB 或其他任何内容)继续处理imgbuffer 变量以将其保存到Ms-Access。最后,我更喜欢使用MemoryStream 来放置图像缓冲区并将其保存到Bitmap 变量中。

希望这能解释你的 sn-p 代码。

【讨论】:

  • 嘿eko junaidi!谢谢你我明白了,我可以请你的工作电子邮件或其他东西,这样你就可以解释完整的代码,我真的很感谢你的帮助!我不知道如何在这里发布整个代码对不起
猜你喜欢
  • 2018-03-13
  • 1970-01-01
  • 2019-06-17
  • 1970-01-01
  • 2018-09-12
  • 2012-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多