mysql保存rtf文件_在RTF格式中提取图片并保存成文件 | 学步园

这段代码展示了如何从RTF格式的文本中提取图片,并将它们保存为.jpg文件。同时,它还演示了如何将处理后的RTF内容保存到MySQL数据库中。
摘要由CSDN通过智能技术生成

Friend Sub getpic(ByVal RT As String, ByVal remid As String)

'Dim RTlenth As Int64 = RT.Rtf.Length

'Dim Sindex As Int64

'Dim Eindex As Int64

'Dim rtfPIC As String

'Sindex = RT.Rtf.ToString.IndexOf("{/pict/")

'rtfPIC = RT.Rtf.Substring(Sindex, RTlenth - Sindex)

'Eindex = rtfPIC.IndexOf("}")

'rtfPIC = Left(rtfPIC, Eindex + 1)

'MsgBox(rtfPIC)

'Dim windex As Int16 = rtfPIC.IndexOf("/picw")

'Dim hindex As Int16 = rtfPIC.IndexOf("/pich")

'Dim heindex As Int16 = rtfPIC.IndexOf("/picwgoa")

'Dim Pwith As Int16 = rtfPIC.Substring(windex + 5, hindex - (windex + 5))

'Dim pheight As Int16 = rtfPIC.Substring(hindex + 5, heindex - (hindex + 5))

'MsgBox(Pwith & "——" & pheight)

'Dim imgdata As String

'imgdata = rtfPIC.Substring(rtfPIC.IndexOf(" ") + 2, rtfPIC.Length - rtfPIC.IndexOf(" ") - 4)

Dim _RtfText As String = RT

Dim savertf As String = RT

Dim _ImageList As IList(Of String) = New List(Of String)()

Dim repaceinglist As IList(Of String) = New List(Of String)()

While True

Dim _Index As Integer = _RtfText.IndexOf("pichgoal")

If _Index = -1 Then

Exit While

End If

_RtfText = _RtfText.Remove(0, _Index + 8)

'_Index = _RtfText.IndexOf(vbCr & vbLf)

'Dim _Temp As Integer = Convert.ToInt32(_RtfText.Substring(0, _Index))

'_RtfText = _RtfText.Remove(0, _Index)

Dim index As Int64 = _RtfText.IndexOf(vbLf) + 1

_RtfText = _RtfText.Remove(0, index)

Dim instr As String

Dim inte As Int64 = _RtfText.IndexOf("}")

instr = _RtfText.Substring(0, inte)

'

repaceinglist.Add(instr)

instr = instr.Replace(vbCr & vbLf, "")

' _RtfText = _RtfText.Replace(vbCr & vbLf, "")

_Index = _RtfText.IndexOf("}")

If instr = _RtfText.Substring(0, _Index) Then

MsgBox("一样")

End If

_ImageList.Add(instr)

_RtfText = _RtfText.Remove(0, _Index)

End While

Dim i As Integer = 0

While i <> _ImageList.Count

Dim chatadr As String = adrmyPersonal & Uinflist(0).uID & "/" & remid & "/pic/"

If My.Computer.FileSystem.DirectoryExists(chatadr) = False Then

My.Computer.FileSystem.CreateDirectory(chatadr)

End If

Dim chatfileadr As String = chatadr & Now.Date & "_" & Now.Hour & "-" & Now.Minute & "-" & Now.Second & ".jpg"

Dim _File As System.IO.FileStream = New FileStream(chatfileadr, System.IO.FileMode.Create)

Dim _Count As Integer = _ImageList(i).Length / 2

Dim z As Integer = 0

While z <> _Count

Dim _TempText As String = _ImageList(i)(z * 2).ToString() + _ImageList(i)((z * 2) + 1).ToString()

_File.WriteByte(Convert.ToByte(_TempText, 16))

z += 1

End While

_File.Close()

savertf = savertf.Replace(repaceinglist(i), "")

i += 1

End While

Dim insqlstr As String = jiami(savertf, "11111111")

Dim mysql As New ClassSQL

If mysql.SETconn(Uinflist(0).uID, remid) = True Then

Dim sqlinsert As String = "insert into chatlog(cbody,ctime) values ('" & insqlstr & "','" & Now.ToString & "')"

If mysql.insert(sqlinsert) Then

MsgBox("数据插入成功")

End If

End If

End Sub

Friend Function setnewRTF() As RichTextBox

Dim rtb As New RichTextBox

Dim str As String = "{/rtf1/ansi/ansicpg936/deff0/deflang1033/deflangfe2052{/fonttbl{/f0/fnil/fcharset134 " & _

"/'cb/'ce/'cc/'e5;}}" & _

"/viewkind4/uc1/pard/lang2052/f0/fs18/par"

rtb.Rtf = str

Return rtb

End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值