RECORTAR IMAGEM
Pessoal, preciso cortar uma imagem de um PictureBox1 antes de salvá-la no disco.
Salvar a imagem é mole, eu preciso que fique como a imagem em anexo:
Alguém sabe como?
Salvar a imagem é mole, eu preciso que fique como a imagem em anexo:
Alguém sabe como?
Pessoal, navegando pela internet consegui resolver meu problema usando esta função aqui:
[txt-color=#0000f0]Private Sub[/txt-color] Button11_Click([txt-color=#0000f0]ByVal[/txt-color] sender [txt-color=#0000f0]As[/txt-color] System.Object, [txt-color=#0000f0]ByVal[/txt-color] e [txt-color=#0000f0]As[/txt-color] System.EventArgs) [txt-color=#0000f0]Handles[/txt-color] Button11.Click
[txt-color=#0000f0]Dim[/txt-color] Bitmap1 [txt-color=#0000f0]As Bitmap[/txt-color] = PictureBox1.Image
[txt-color=#0000f0]Dim[/txt-color] Secao [txt-color=#0000f0]As New Rectangle[/txt-color]([txt-color=#0000f0]New[/txt-color] Point(350, 70), [txt-color=#0000f0]New[/txt-color] Size(150, 150))
[txt-color=#0000f0]Dim[/txt-color] FiguraCortada [txt-color=#0000f0]As Bitmap[/txt-color] = CortarFigura(Bitmap1, Secao)
PictureBox1.Image = FiguraCortada
[txt-color=#0000f0]If My[/txt-color].Computer.FileSystem.FileExists(Application.StartupPath & [txt-color=#e80000][Ô]\imagens\imagem.jpg[Ô][/txt-color]) [txt-color=#0000f0]Then[/txt-color]
File.Delete(Application.StartupPath & [txt-color=#e80000][Ô]\imagens\imagem.jpg[Ô][/txt-color])
[txt-color=#0000f0]End If[/txt-color]
FiguraCortada.Save(Application.StartupPath & [txt-color=#e80000][Ô]\imagens\imagem.jpg[Ô][/txt-color], System.Drawing.Imaging.ImageFormat.Jpeg)
Clipboard.Clear()
[txt-color=#0000f0]End Sub[/txt-color]
______________________________________________________________________________________________________________________
[txt-color=#0000f0]Private Function[/txt-color] CortarFigura([txt-color=#0000f0]ByRef[/txt-color] QualFigura [txt-color=#0000f0]As Bitmap[/txt-color], [txt-color=#0000f0]ByVal[/txt-color] QualSecao [txt-color=#0000f0]As Rectangle[/txt-color]) [txt-color=#0000f0]As Bitmap[/txt-color]
[txt-color=#0000f0]Dim[/txt-color] BMP [txt-color=#0000f0]As New Bitmap[/txt-color](QualSecao.Width, QualSecao.Height)
[txt-color=#0000f0]Dim[/txt-color] G [txt-color=#0000f0]As Graphics[/txt-color] = Graphics.FromImage(BMP)
G.DrawImage(QualFigura, 0, 0, QualSecao, GraphicsUnit.Pixel)
[txt-color=#0000f0]Return[/txt-color] BMP
[txt-color=#0000f0]End Function[/txt-color]
[txt-color=#0000f0]Private Sub[/txt-color] Button11_Click([txt-color=#0000f0]ByVal[/txt-color] sender [txt-color=#0000f0]As[/txt-color] System.Object, [txt-color=#0000f0]ByVal[/txt-color] e [txt-color=#0000f0]As[/txt-color] System.EventArgs) [txt-color=#0000f0]Handles[/txt-color] Button11.Click
[txt-color=#0000f0]Dim[/txt-color] Bitmap1 [txt-color=#0000f0]As Bitmap[/txt-color] = PictureBox1.Image
[txt-color=#0000f0]Dim[/txt-color] Secao [txt-color=#0000f0]As New Rectangle[/txt-color]([txt-color=#0000f0]New[/txt-color] Point(350, 70), [txt-color=#0000f0]New[/txt-color] Size(150, 150))
[txt-color=#0000f0]Dim[/txt-color] FiguraCortada [txt-color=#0000f0]As Bitmap[/txt-color] = CortarFigura(Bitmap1, Secao)
PictureBox1.Image = FiguraCortada
[txt-color=#0000f0]If My[/txt-color].Computer.FileSystem.FileExists(Application.StartupPath & [txt-color=#e80000][Ô]\imagens\imagem.jpg[Ô][/txt-color]) [txt-color=#0000f0]Then[/txt-color]
File.Delete(Application.StartupPath & [txt-color=#e80000][Ô]\imagens\imagem.jpg[Ô][/txt-color])
[txt-color=#0000f0]End If[/txt-color]
FiguraCortada.Save(Application.StartupPath & [txt-color=#e80000][Ô]\imagens\imagem.jpg[Ô][/txt-color], System.Drawing.Imaging.ImageFormat.Jpeg)
Clipboard.Clear()
[txt-color=#0000f0]End Sub[/txt-color]
______________________________________________________________________________________________________________________
[txt-color=#0000f0]Private Function[/txt-color] CortarFigura([txt-color=#0000f0]ByRef[/txt-color] QualFigura [txt-color=#0000f0]As Bitmap[/txt-color], [txt-color=#0000f0]ByVal[/txt-color] QualSecao [txt-color=#0000f0]As Rectangle[/txt-color]) [txt-color=#0000f0]As Bitmap[/txt-color]
[txt-color=#0000f0]Dim[/txt-color] BMP [txt-color=#0000f0]As New Bitmap[/txt-color](QualSecao.Width, QualSecao.Height)
[txt-color=#0000f0]Dim[/txt-color] G [txt-color=#0000f0]As Graphics[/txt-color] = Graphics.FromImage(BMP)
G.DrawImage(QualFigura, 0, 0, QualSecao, GraphicsUnit.Pixel)
[txt-color=#0000f0]Return[/txt-color] BMP
[txt-color=#0000f0]End Function[/txt-color]
Tópico encerrado , respostas não são mais permitidas