Jump to content

Recommended Posts

Posted

Tenho o seguinte código para pegar uma imagem e carrega-la num picturebox e por cima dela escrever, mas não consigo gravar com o texto, já pesquisei no link http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx , mas não estou conseguindo lá chegar

    Private Sub But_LerImage_Click(sender As System.Object, e As System.EventArgs) Handles But_LerImage.Click
        Dim G As Graphics = PictureBox1.CreateGraphics
        ' G.Clear(Color.White)
        Dim Fonte As New Font("Arial", 18, FontStyle.Bold + FontStyle.Italic, GraphicsUnit.Pixel)
        Dim Texto As String = "Expo 014"
        Dim MedidasTexto As SizeF = G.MeasureString(Texto, Fonte)
        Dim PosicaoX As Integer = (PictureBox1.Width - MedidasTexto.Width - 10)
        Dim PosicaoY As Integer = (MedidasTexto.Height - 10)
        G.DrawString(Texto, Fonte, Brushes.Blue, PosicaoX, PosicaoY)

    End Sub

    Private Sub But_Escreve_Click(sender As System.Object, e As System.EventArgs) Handles But_Escreve.Click
        PictureBox1.Image = Image.FromFile("D:\Fotos portas\Site\EXP014.jpg")
    End Sub

Obrigado

Posted

Ao fazeres no fim

PictureBox1.Image = Image.FromFile("D:\Fotos portas\Site\EXP014.jpg")

Destrois o trabalho já efectuado na superfície.

Se fizeres isso primeiro e depois a escrita, já "funciona"

Das três uma:

- Ou desenhas APÓS definires a imagem da superfície (não é uma composição)

- Ou desenhas tudo num Bitmap novo (ideal)

- Ou desenhas tudo directamente na superficie (meh)

As letras da primeira, bem como a imagem e letras da última, "desaparecem" sempre que algo força o controlo a redesenhar-se, por exemplo, levar a janela para além dos limites do ecrã.

Já na ideal, está tudo "cozinhado" na imagem. Podes inclusivamente gravar para ficheiro se te apetecer.

	Private Sub FazerTudo()
	Dim B As New Bitmap("D:\Fotos portas\Site\EXP014.jpg")
	Dim G As Graphics = Graphics.FromImage(B)
	Dim Fonte As New Font("Arial", 18, FontStyle.Bold + FontStyle.Italic, GraphicsUnit.Pixel)
	Dim Texto As String = "Expo 014"
	Dim MedidasTexto As SizeF = G.MeasureString(Texto, Fonte)
	Dim PosicaoX As Integer = (PictureBox1.Width - MedidasTexto.Width - 10)
	Dim PosicaoY As Integer = (MedidasTexto.Height - 10)
	G.DrawString(Texto, Fonte, Brushes.Blue, PosicaoX, PosicaoY)
	PictureBox1.Image = B
End Sub

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Posted

humm ? é isso...obrigado

Eu executava primeiro  But_Escreve e depois But_LerImage (que por acaso os nomes estão trocados)

Mas como dizes está a funcionar (e já consigo guardar a imagem).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.