在VB.Net上的数据库中保存inkPicture

时间:2018-05-21 16:40:09

标签: database vb.net

我需要很多帮助。 我想将图像中的墨迹图像记录到访问数据库中。  不幸的是,我已经尝试了几种方法  我无法帮助某人,因为  我一直在尝试,总是错误或二进制长。 请帮我! 我喜欢完成我的工作,但没有关闭procject无法记录数据库中的inkpicture。 抱歉,我的英文不好

Dim tempPath As String = Path.GetTempPath
    Dim tempFile As String = (tempPath + serie_doc.Text + n_doc.Text & ".gif")
    Dim inkBox As Rectangle = InkPicture1.Ink.GetBoundingBox
    Dim point As Point = New Point(inkBox.Left, inkBox.Top)
    MessageBox.Show((point.X.ToString + (", " + point.Y.ToString)))
    Dim tempGraphics As Graphics = CreateGraphics()
    Dim inkRenderer As Microsoft.Ink.Renderer = New Renderer
    inkRenderer.InkSpaceToPixel(tempGraphics, point)
    MessageBox.Show((point.X.ToString + (", " + point.Y.ToString)))
    ' Clean up
    tempGraphics.Dispose()
    ' save the ink and background image to a temp file
    If (InkPicture1.Ink.Strokes.Count > 0) Then
        Dim bytes() As Byte = InkPicture1.Ink.Save(PersistenceFormat.Gif, CompressionMode.NoCompression)
        Dim ms As MemoryStream = New MemoryStream(bytes)
        Dim gif As Bitmap = New Bitmap(ms)
        Dim bmp = New Bitmap(InkPicture1.BackgroundImage)
        Dim g = Graphics.FromImage(bmp)
        g.DrawImage(gif, New Rectangle(point.X, point.Y, gif.Width, gif.Height))
        bmp.Save(tempFile, System.Drawing.Imaging.ImageFormat.Gif)
        Canhotos_AkfixTableAdapter.Gravar_mastik_canhoto(doc, serie_doc.Text, n_doc.Text, data.Text, n_cliente.Text, nome_cliente.Text, bmp, p_nome.Text, u_nome.Text, modo_pagamento, dias.Text, total.Text)
    End If

Best Reagrds

1 个答案:

答案 0 :(得分:0)

我有一个允许用户上传照片的过程,然后我将其缩放并保存在数据库中,我从不将图像保存到磁盘上,而是在计算机的内存中进行处理。它与您的行为并不完全相同,但它应该可以帮助您入门:

' Get the posted image file
Dim TheStream As Stream = file1.PostedFile.InputStream
Dim origimage As System.Drawing.Image
' get the image from the posted file stream
origimage = System.Drawing.Image.FromStream(TheStream)

Dim ms2 As New System.IO.MemoryStream
origimage = ScaleImage(origimage, 320, 200) 
origimage.Save(ms2, Imaging.ImageFormat.Jpeg)
' convert to byte array
Dim MyPhoto() As Byte = ms2.GetBuffer ' The scaled image is now stored in memory
Session("ThePhoto") = MyPhoto ' put it into the session to retrieve later
ms2.Dispose()

此时我将图像转换为字节数组,我将其保存到会话对象,因为此时用户尚未保存数据。在另一个页面上,我检索图像并将其与数据库中的blog列相同。