Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共10 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:请教,如何字符串转换成字节?

1楼
baoxyang 发表于:2011/5/30 16:45:00

SQL图片列是image类型,存放照片二进制内容“0xFFD8FFE000104A46494600010100000100010000FFDB0043000302020302020303030304030304050805050404050A070706080C0A0C0C0B0A0B0B0D0E12100D0E110E0B0B1016101113141515150C0F171816141812141514FFDB00430103040405040509050509140D0B0D14141414141414141414141414141414141414”
发现这个查询是很慢的。我把照片存放二进制为text类型时,查询是很快的。但是如何把text转换成byte类型的。

 

          Dim imageByte() As Byte = Tables("卸船货损管理_Table1").Current("照片")   ‘原来照片列是image类型的,现改成了text类型了

          Dim ms As New IO.MemoryStream(imageByte)       '将字节数组转换为二进制流
          Dim image As Image = Image.FromStream(ms)      '将二进制流转换为图片
          e.Form.Controls("Picturebox1").Image = image 

 

请问以上代码应如何实现呢?谢谢指教。



 

2楼
狐狸爸爸 发表于:2011/5/30 17:03:00
Dim bt1 As Byte() =  {&H0, &H12, &H34, &H56, &HAA, &H55, &HFF}
Dim s As String = Convert.ToBase64String (bt1)
Dim bt2 As Byte() = Convert.FromBase64String(s)
For i As Integer = 0 To bt1.length -1
    If bt1(i) <> bt2(i) Then
        Return "false"
    End If
Next
Return "true"
3楼
baoxyang 发表于:2011/5/30 17:04:00

请教下,是否把图片以二进制存储在表中image类型列中,在查询此表数据时反映是否很慢?

4楼
狐狸爸爸 发表于:2011/5/30 17:04:00

看2楼。

5楼
hhbb 发表于:2011/5/30 17:16:00
晕,神马啊?
6楼
baoxyang 发表于:2011/5/30 17:22:00
以下是引用狐狸爸爸在2011-5-30 17:03:00的发言:
Dim bt1 As Byte() =  {&H0, &H12, &H34, &H56, &HAA, &H55, &HFF}
Dim s As String = Convert.ToBase64String (bt1)
Dim bt2 As Byte() = Convert.FromBase64String(s)
For i As Integer = 0 To bt1.length -1
    If bt1(i) <> bt2(i) Then
        Return "false"
    End If
Next
Return "true"

 不太明白。

 但这样不行。

         dim s as stirng = Tables("卸船货损管理_Table1").Current("照片")    '是text类型的二进制。

          Dim imageByte() As Byte = Convert.FromBase64String(s)

          Dim ms As New IO.MemoryStream(imageByte)       '将字节数组转换为二进制流
          Dim image As Image = Image.FromStream(ms)      '将二进制流转换为图片
          e.Form.Controls("Picturebox1").Image = image 

提示字符组无效长度。

7楼
狐狸爸爸 发表于:2011/5/30 17:29:00
图片太大,字符数组太长?
8楼
狐狸爸爸 发表于:2011/5/30 17:50:00

我这个通过测试的:

 

Dim fs As New IO.FileStream("c:\001.gif" , IO.FileMode.Open , IO.FileAccess.Read)   '用文件流打开图片
Dim br As New IO.BinaryReader(fs) 
Dim bt1 As Byte() =  br.ReadBytes(fs.Length)
Dim s As String = Convert.ToBase64String (bt1)
Dim bt2 As Byte() = Convert.FromBase64String(s)
Dim ms As New IO.MemoryStream(bt2)       '将字节数组转换为二进制流
Dim image As Image = Image.FromStream(ms)      '将二进制流转换为图片
e.Form.Controls("PictureBox1").Image = image      '显示图片

9楼
baoxyang 发表于:2011/5/31 11:18:00

老大,没有明白我的意思。

 Dim imageByte() As Byte = Tables("卸船货损管理_Table1").Current('照片') 

’这个列是image类型,已存放的是二进制方式。我把这个二进制的内容保存到一个*。txt文件中。

如何实现等效的代码?谢谢!!

 

 

10楼
狐狸爸爸 发表于:2011/5/31 11:40:00

Dim bt1() as Byte= Tables("卸船货损管理_Table1").Current('照片')

Filesys.WriteAlltext(文件名,Convert.ToBase64String (bt1))

Dim bt2 As Byte() = Convert.FromBase64String(Filesys.ReadAllText(文件名))


 

共10 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03125 s, 2 queries.