how to record the result of an image and a label in a single file?

0

I'm making a small pogram to make memorials in photos is a label and a picturebox how can I record the label along with the image box image for a single image? This is my code.

Imports System.Diagnostics
Imports System.Drawing

Public Class Form1

Dim PPoint As Point
Dim image As Image
Dim graphics As Graphics
Dim fontx As Font
Dim point As PointF
Dim color
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    txtValueX.Text = e.x.tostring
    txtValueY.Text = e.Y.ToString
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim OpenFileDialog1 As New OpenFileDialog
    OpenFileDialog1.InitialDirectory = "C:\"
    OpenFileDialog1.FileName = "Open A File..."
    OpenFileDialog1.Multiselect = False
    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
        Dim sName As String = OpenFileDialog1.SafeFileName
        Dim img As String = OpenFileDialog1.FileName
        PictureBox1.Image = System.Drawing.Bitmap.FromFile(img)
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End If
    ' Load image
    image = Drawing.Image.FromFile(OpenFileDialog1.FileName)
    graphics = Drawing.Graphics.FromImage(image)
    ' Create font
    fontx = New Font("Times New Roman", 42.0F)
    ' Create text position
    point = New PointF(txtValueX.Text, txtValueY.Text)
    ' Draw text
    graphics.DrawString(TextBox2.Text, fontx, Brushes.Red, point)



End Sub
Private Sub mouseMove_Capture(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseMove
    Dim mousePos As Point = Control.MousePosition
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim OpenFileDialog1 As New OpenFileDialog
    OpenFileDialog1.InitialDirectory = "C:\"
    OpenFileDialog1.FileName = "Open A File..."
    OpenFileDialog1.Multiselect = False
    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
        Dim sName As String = OpenFileDialog1.SafeFileName
        Dim img As String = OpenFileDialog1.FileName
        PictureBox1.Image = System.Drawing.Bitmap.FromFile(img)
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End If


End Sub


Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Label5.Parent = PictureBox1

End Sub


Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    '// Save The image in PictureBox in its Original size.
    If Me.PictureBox1.Image IsNot Nothing Then
        Me.PictureBox1.Image.Save(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyPictures, "TestFile.jpg"))
    End If

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Process.Start("1.jpg")
End Sub


Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick





End Sub




Private Sub PictureBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
    PPoint = New Point(e.X, e.Y)
    Label5.Location = New Point(e.X, e.Y)



End Sub

Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
    Label5.Text = TextBox2.Text
    Label5.TextAlign = ContentAlignment.MiddleLeft

    Label5.Font = New Font("Comic Sans MS", 12, _
                FontStyle.Bold Or FontStyle.Underline)
End Sub

Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
    Label5.Font = New Font("Comic Sans MS", TrackBar1.Value, _
                FontStyle.Bold Or FontStyle.Underline)
End Sub

Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    FontDialog1.ShowDialog()
    Label5.Font = FontDialog1.Font
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    ColorDialog1.ShowDialog()
    Label5.ForeColor = ColorDialog1.Color

End Sub
End Class
    
asked by anonymous 27.07.2017 / 01:13

1 answer

0

You can implement a Panel , and save the contents of it:

Imports System.Drawing
...
Public Function CriarMemoria(ByVal foto As Image, texto As String, alinharNoCentro as Boolean) As Bitmap
    ' Cria um painel que será nossa imagem
    Dim moldura As New Panel With {
        .Size = foto.Size,
        .Location = New Point(0, 0)
    }
    ' Coloca o fundo no painel
    moldura.BackgroundImage = foto
    ' Ajusta o layout para preencher tudo
    moldura.BackgroundImageLayout = ImageLayout.Stretch
    ' Cria o tal label com a moldura
    Dim lab As New Label With {
        .Text = texto,
        .Font = New Font("Segoe UI", 14) ' você escolhe sua fonte aqui
    }
    ' Adiciona o label para a moldura
    moldura.Controls.Add(label)
    ' Ajusta a posição do label
    If(alinharNoCentro) Then
         lab.AutoSize = False
         lab.Dock = DockStyle.Top
         label.TextAlign = ContentAlignment.TopCenter
         label.Height = 32 ' ajusta a altura do label de acordo com a fonte
    Else
         lab.AutoSize = True
         lab.Dock = DockStyle.Top
    End If
    ' Cria uma imagem à partir desse painel criado
    Dim output As New Bitmap(moldura.Width, moldura.Height)
    Dim rect As New Rectangle(new Point(0, 0), moldura.Size)
    ' Escreve no bitmap a imagem
    moldura.DrawToBitmap(output, rect)
    ' Retorna o criado
    Return output
End Function

So, you can call the method to create the Bitmap CriarMemoria(Image, String) memory write to file, since the image will already be ready.

    
28.07.2017 / 05:52