Hola como estan.
Tengo una pregunta como hago transparente un picturebox, tengo dos picturebox uno encima del otro las dos son imagenes png sin fondo, pero una quiero superponerla sobre la otra pero no logro quitar el fondo de la de encima.
he probado pero el picture box dos me sique mostrando el contorno
PictureBox1.Controls.Add(PictureBox2)
PictureBox2.BackColor = Color.Transparent
Aca dejo unas imagenes de ejemplo de como seria lo que quiero hacer
(http://i.stack.imgur.com/JafAa.jpg)
(http://i.stack.imgur.com/NuEM6.png)
Muchas gracias saludos.
lo hacía así:
Imports System.Drawing
Imports System.Drawing.Graphics
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox3.Image = Overlay(PictureBox1.Image, PictureBox2.Image, Color.Magenta)
End Sub
Public Function Overlay(ByVal SourceImage As Bitmap, ByVal OverlayImage As Bitmap) As Bitmap
'Llama a la version con Color
Return Overlay(SourceImage, OverlayImage, Color.Black)
End Function
Public Function Overlay(ByVal SourceImage As Bitmap, ByVal OverlayImage As Bitmap, ByVal ColorTransparent As Color) As Bitmap
Dim g As Graphics
'Obtengo Graphic de la imagen de fondo para poder dibujar sobe ella
g = Drawing.Graphics.FromImage(SourceImage)
'Hago trasparente la imagen que vamos a superponer
OverlayImage.MakeTransparent(ColorTransparent)
'Dibujo la imagen sobre el fondo
g.DrawImage(OverlayImage, 0, 0)
'Elimino manejador grafico
g.Dispose()
'Devuelve la imagen mezclada
Return SourceImage
End Function
End Class
en donde la segunda imagen (a superponer) tiene que ser el color de fondo en este caso Magenta, claro está que puede ser cualquier otro, pero preferentemente uno que no este en uso.
Hola.
Muchas gracias por responder pero en la funcion Overlay recive 3 parametros el color es decir ColorTransparent As Color pero si es transparente por que se le asigna un color.
Este es mi problema basicamente.
(http://2.bp.blogspot.com/-jrIOqbiGfLM/VbHOB0EIwAI/AAAAAAAAA-w/gHapArIAeNs/s1600/Carro.png)
Quiero que el fondo del picturebox de carro sea transparente y se vea el carro superpuesto a la carretera.
Muchas gracias por responder tincopasan
Saludos.
No te lo recomiendo, este tipo de hacks en WindowsForms solo consiguen disminuir el rendimiento general de la aplicación, pero ya te entiendo, es algo que necesitas hacer (pero podrías usar WPF y no tendrías este tipo de problemas).
Aquí tienes por donde empezar, con un control sub-classeado:
(http://i.imgur.com/F8VNt87.png)
' ***********************************************************************
' Author : Elektro
' Modified : 24-July-2015
' ***********************************************************************
' <copyright file="TransparentControl.vb" company="Elektro Studios">
' Copyright (c) Elektro Studios. All rights reserved.
' </copyright>
' ***********************************************************************
#Region " Option Statements "
Option Explicit On
Option Strict On
Option Infer Off
#End Region
#Region " Imports "
Imports System
Imports System.Drawing
Imports System.Windows.Forms
#End Region
#Region " TransparentControl "
''' <summary>
''' A transparent <see cref="Control"/>.
''' </summary>
Public NotInheritable Class TransparentControl : Inherits Control
#Region " Properties "
''' <summary>
''' Gets or sets the background image displayed in the control.
''' </summary>
''' <value>The background image.</value>
Public Overloads Property BackgroundImage As Image
Get
Return Me.backgroundImageB
End Get
Set(ByVal value As Image)
Me.backgroundImageB = value
MyBase.RecreateHandle()
End Set
End Property
''' <summary>
''' ( Backing Field )
''' The background image displayed in the control.
''' </summary>
Private backgroundImageB As Image
''' <summary>
''' Gets or sets the image displayed in the control.
''' </summary>
''' <value>The image.</value>
Public Overloads Property Image As Image
Get
Return Me.imageB
End Get
Set(ByVal value As Image)
Me.imageB = value
MyBase.RecreateHandle()
End Set
End Property
''' <summary>
''' ( Backing Field )
''' The background image displayed in the control.
''' </summary>
Private imageB As Image
''' <summary>
''' Gets the background color for the control.
''' </summary>
''' <value>The background color.</value>
<EditorBrowsable(EditorBrowsableState.Never)>
Public Shadows ReadOnly Property BackColor() As Color
Get
Return Color.Transparent
End Get
End Property
''' <summary>
''' Gets the required creation parameters when the control's handle is created.
''' </summary>
''' <value>The creation parameters.</value>
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = (cp.ExStyle Or 32)
Return cp
End Get
End Property
#End Region
#Region " Constructors "
''' <summary>
''' Initializes a new instance of the <see cref="TransparentControl"/> class.
''' </summary>
Public Sub New()
End Sub
#End Region
#Region " Event-Handlers "
''' <summary>
''' Handles the <see cref="E:Control.Paint"/> event.
''' </summary>
''' <param name="e">A <see cref="T:Forms.PaintEventArgs"/> that contains the event data.</param>
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If Me.backgroundImageB IsNot Nothing Then ' Draw background image (filled).
e.Graphics.DrawImage(Me.backgroundImageB, Me.ClientRectangle)
End If
If Me.imageB IsNot Nothing Then ' Draw image (centered).
e.Graphics.DrawImage(Me.imageB,
((Me.ClientRectangle.Width \ 2) - (Me.imageB.Width \ 2)),
CSng((Me.ClientRectangle.Height / 2) - (Me.imageB.Height / 2)))
End If
End Sub
''' <summary>
''' Handles the <see cref="E:PaintBackground" /> event.
''' </summary>
''' <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
' Ignore painting (don't raise PaintBackground event).
End Sub
#End Region
End Class
#End Region
Saludos
Hola sos grande ;-) ;-) ;-)
Logre hacerlo con un label y un picturebox pero el problema que el label no tiene ciertas propiedades del pic.
Ya logre avanzar y hacerlo como queria muchas gracias Eleкtro
asi quedo:
(http://2.bp.blogspot.com/-ckjQZljlgE8/VbInFvE83FI/AAAAAAAAA_A/tvCMTfhaa8U/s1600/carr0.png)
Muchas gracias te agradezco el tiempo que te tomaste para hacer 143 lineas de codigo.
Claro tambien sin menos preciar la ayuda del compa~nero tincopasan
Saludos y muchas gracias y se que es poco.