|
531
|
Programación / .NET (C#, VB.NET, ASP) / Re: Reproducir Ñ con sapi.voice
|
en: 28 Abril 2019, 20:29 pm
|
gracias dog, voy a probar, pero creo que habia probado algo parecido sin resultado. te aviso.
más lento Dim message, sapi message = "el ninio no sabe lo que es un monio en la cabeza" sapi = CreateObject("sapi.spvoice") sapi.rate = -5 sapi.Speak(message)
|
|
|
533
|
Programación / .NET (C#, VB.NET, ASP) / Re: substraer color
|
en: 28 Abril 2019, 15:40 pm
|
Con vb6 para crear el OCX hice esto. Option Explicit Public Property Get Picture() As Picture Set Picture = UserControl.Picture End Property Public Property Set Picture(ByVal New_Picture As Picture) Set UserControl.Picture = New_Picture PropertyChanged "Picture" End Property 'Cargar valores de propiedad desde el almacén Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Set Picture = PropBag.ReadProperty("Picture", Nothing) End Sub 'Escribir valores de propiedad en el almacén Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Call PropBag.WriteProperty("Picture", Picture, Nothing) End Sub
Esto funciona si asigno la imagen desde la página de propiedades de pero cuando hago esto con códgo: Private Sub Command1_Click() UserControl_1.Picture = LoadPicture("") End Sub
Me dice eso de uso no válido de la propiedad
justo acabo de solucionar el problema viendo este foro que encontré en google http://www.vbforums.com/showthread.php?560245-RESOLVED-Problem-with-LoadPicture-in-an-ActiveX-ControlPara que funcionara tenía que añadir SET Private Sub Command1_Click() Set UserControl_1.Picture = LoadPicture("") End Sub
Para evitar usar el procedimiento set añadí esto al código del activex y ya funcionó bien Public Property Let Picture(ByVal New_Picture As Picture) Picture1.Picture = New_Picture PropertyChanged "Picture" End Property
ahora ya puedo seguir publicaré los resultados a ver si lo consigo. pero me gustaría no tener que usar un ocx y hacerlo todo desde net. Tengo alguna idea pero por ahora probaré esto. javascript:void(0);
he creado ya el ActiveX pero SetLayeredWindowAttributes no aplica cambios en el ActiveX, no elimina la parte coloreada. paso a la siguiente opción
|
|
|
534
|
Programación / .NET (C#, VB.NET, ASP) / Re: substraer color
|
en: 27 Abril 2019, 17:10 pm
|
perdona si no fui claro amigo
ahora he conseguido instalar vb6 para hacer un control ocx pero no consigo que funciona la propiedad picture, he seguido tutoriales pero cuando establezco el picture me dice uso de la propiedad no válida. aún estoy en elllo.
|
|
|
535
|
Programación / .NET (C#, VB.NET, ASP) / Re: substraer color
|
en: 23 Abril 2019, 01:50 am
|
NEBIRE muchas gracias antes de nada. Pero eso no es lo que intentaba. El objetivo es recortar, eliminar una porción de un control Picturebox dejándolo transparente de tal modo que se puedan ver otros controles que hubieran debajo del Picturebox, SetLayeredWindowAttributes solo funciona con ventanas no funciona por ejemplo usando Picturebox1.Handle. DrawImage solo afecta a imágenes aplicadas al Picturebox pero no al objeto en cuestión. No existe en NET ningún método para hacer eso que yo sepa, la única manera es recurrir a APIs de Windows. Conozco una forma de recortar partes de un control pero si quiero darle una forma concreta es complicado, de ahí que partiera usando un color. Quizás con éste método pudiera eliminar solo los píxeles que contengan un determinado color. Otra forma sería creando un objeto COM y a esperar que SetLayeredWindowAttributes solo afecte a este y no al formulario que lo contiene. También se me ocurre crear un formulario mediante código e incrustarlo en el formulario principal. A ver si esto funciona. Creo que otra forma sería usar GDI32 pero no se nada de eso parece complicado.
ya he probado la primera opción se podría decir que hace lo que quiero pero tiene una extraño comportamiento, además una vez elimino la zona verde se vuelve el picture se vuelve a dibujar, tiene autoredraw. También realiza el proceso muy lentamente ya que va eliminando pixel por pixel. Igualmente lo posteo por si alguien tiene curiosidad o lo puede arreglar. Imports System Imports System.Runtime.InteropServices Imports System.Text Imports System.Drawing.Color Public Class Form1 <DllImport("gdi32")> _ Private Shared Function CreateRectRgn(ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer) As Integer End Function <DllImport("gdi32.dll", CharSet:=CharSet.Auto)> _ Private Shared Function CreateEllipticRgn(ByVal X1 As Integer, _ ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer) As Integer End Function <DllImport("user32.dll", CharSet:=CharSet.Auto)> _ Private Shared Function SetWindowRgn(ByVal hwnd As IntPtr, ByVal hRgn As Integer, ByVal bRedraw As Boolean) As Integer End Function <DllImport("user32.dll", Entrypoint:="SendMessageA", CharSet:=CharSet.Auto)> Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As StringBuilder) As IntPtr End Function <DllImport("user32.dll", CharSet:=CharSet.Auto)> Private Shared Function ReleaseCapture() As Integer End Function <DllImport("gdi32.dll")> Private Shared Function CreatePolygonRgn(ByVal lppt As Point(), ByVal cPoints As Integer, ByVal fnPolyFillMode As Integer) As IntPtr End Function Const WM_NCLBUTTONDOWN = &HA1 Const HTCAPTION = 2 Public Const ALTERNATE = 1 Public Structure POINTAPI Dim x As Integer Dim y As Integer End Structure Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click '//Obtiene la localización X Y de los píxeles de color Verde RGB(0, 255, 0) Dim b As Bitmap = New Bitmap(PictureBox1.Image) Dim xPosPixel As Integer = Nothing Dim yPosPixel As Integer = Nothing Dim gp As New Bitmap(b.Width, b.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb) For Y As Integer = 0 To gp.Height - 1 For X = 0 To gp.Width - 1 Dim cw As New Color cw = Color.Lime 'Verde RGB(0, 255, 0) Dim curPixColor As Color = b.GetPixel(X, Y) If curPixColor.ToArgb() = cw.ToArgb() Then 'Elimina el píxel ClipPixel(X, Y) End If Next Next End Sub Public Sub ClipPixel(ByVal X As Integer, ByVal Y As Integer) Dim lpPts(12) As Point Dim hRustedRgn As Long ' Rusted region Dim WPicture As Integer Dim HPicture As Integer Dim X1, X2, Y1, Y2 As Integer WPicture = PictureBox1.Width HPicture = PictureBox1.Height X1 = X : X2 = Y : Y1 = Y : Y2 = Y + 1 ' Fill out the Rusted region points ' The starting point lpPts(0).X = 0 : lpPts(0).Y = 0 ' The width from the starting point lpPts(1).X = WPicture : lpPts(1).Y = 0 ' The height from the Width lpPts(2).X = WPicture : lpPts(2).Y = HPicture ' The Height from the starting point lpPts(3).X = 0 : lpPts(3).Y = HPicture ' Create half of the square as a Triangle lpPts(4).X = 0 : lpPts(4).Y = X1 lpPts(5).X = X1 : lpPts(5).Y = X1 lpPts(6).X = X1 : lpPts(6).Y = Y1 lpPts(7).X = X2 : lpPts(7).Y = Y1 lpPts(8).X = X2 : lpPts(8).Y = Y2 lpPts(9).X = X1 : lpPts(9).Y = Y2 lpPts(10).X = X1 : lpPts(10).Y = X1 lpPts(11).X = 0 : lpPts(11).Y = X1 hRustedRgn = CreatePolygonRgn(lpPts, lpPts.Length, ALTERNATE) Call SetWindowRgn(PictureBox1.Handle, hRustedRgn, True) End Sub End Class
Curiosamente este código en VB6 funciona mejor. En VB6 los objetos que hay debajo del Picture, como un botón se ven correctamente cuando eliminas la zona de color verde, además una vez eliminado el efecto se mantiene, pero en VB.NET justamente los objetos se vuelven de color verde y el picture se vuelve a redibujar. No funciona
|
|
|
537
|
Programación / .NET (C#, VB.NET, ASP) / Re: substraer color
|
en: 22 Abril 2019, 00:42 am
|
Qé tal si cambias tu código: ...por algo como lo siguiente: Private sub SubstractColor(ByVal HWND As IntPtr, Color As Integer, optional byval GradoTr as byte=128) SetWindowLong(HWND, GWL_EXSTYLE, GetWindowLong(HWND, GWL_EXSTYLE) Or WS_EX_LAYERED) SetLayeredWindowAttributes(HWND, Color, GradoTr , &H1) End Function
Esto es, le estás diciendo que el nivel de transparencia sea total (valor 0), de momento prueba a invocarlo a mitad de transparencia entre el contenido y lo que haya debajo, es decir cada uno pone el 50% de la fuerza de su color. Puedes variar el valor entre 0 (transparente) y 255 (opaco). Se agradece la respuesta pero esto que propones es incorrecto en todo caso. Te lo explico <DllImport("User32.dll", CharSet:=CharSet.Unicode), SuppressUnmanagedCodeSecurityAttribute> Private Shared Function SetLayeredWindowAttributes(ByVal HWND As IntPtr, ByVal crKey As Integer, ByVal bAlpha As Byte, ByVal dwFlags As Integer) As Integer End Function
El último valor que he marcado en rojo (dwFlags) de la función SetLayeredWindowAttributes, puede tener dos valores según el objetivo a aplicar. Que serían Const LWA_COLORKEY As Long = &H1 Const LWA_ALPHA As Long = &H2
Si uso &H1 el valor de bAlpha para la función sólo significa una asignación de color para sustraer Si aplico &H2 es decir LWA_COLORKEY, entonces bAlpha representaría un valor de nivel de transparencia que afectaría a TODO el formulario y no solo al color. Private Sub SubstractColor(ByVal HWND As IntPtr, Optional ByVal GradoTr As Byte = 128) SetWindowLong(HWND, GWL_EXSTYLE, GetWindowLong(HWND, GWL_EXSTYLE) Or WS_EX_LAYERED) SetLayeredWindowAttributes(HWND, IntPtr.Zero, GradoTr, LWA_ALPHA) End Sub
El código quedaría de la siguiente manera: Imports System Imports System.Runtime.InteropServices Imports System.Security Imports System.Drawing.Imaging Public Class Form1 <DllImport("User32.dll", CharSet:=CharSet.Unicode), SuppressUnmanagedCodeSecurityAttribute> Private Shared Function SetLayeredWindowAttributes(ByVal HWND As IntPtr, ByVal crKey As Integer, ByVal bAlpha As Byte, ByVal dwFlags As Integer) As Integer End Function <DllImport("User32.dll", EntryPoint:="GetWindowLongA", CharSet:=CharSet.Unicode), SuppressUnmanagedCodeSecurityAttribute> Private Shared Function GetWindowLong(ByVal HWND As IntPtr, ByVal nIndex As Integer) As Integer End Function <DllImport("User32.dll", EntryPoint:="SetWindowLongA", CharSet:=CharSet.Unicode), SuppressUnmanagedCodeSecurityAttribute> Private Shared Function SetWindowLong(ByVal HWND As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer End Function Const GWL_EXSTYLE = (-20) Const WS_EX_LAYERED = &H80000 Const GreenColor = &HFF00 Const LWA_COLORKEY As Long = &H1 Const LWA_ALPHA As Long = &H2 Private Sub SubstractColor(ByVal HWND As IntPtr, Optional ByVal GradoTr As Byte = 128) SetWindowLong(HWND, GWL_EXSTYLE, GetWindowLong(HWND, GWL_EXSTYLE) Or WS_EX_LAYERED) SetLayeredWindowAttributes(HWND, IntPtr.Zero, GradoTr, LWA_ALPHA) End Sub 'Private Function SubstractColor(ByVal HWND As IntPtr, Color As Integer) As Integer ' SetWindowLong(HWND, GWL_EXSTYLE, GetWindowLong(HWND, GWL_EXSTYLE) Or WS_EX_LAYERED) ' SetLayeredWindowAttributes(HWND, Color, 0, LWA_COLORKEY) ' Return Nothing 'End Function Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown SubstractColor(CType(Me.Handle, IntPtr), 210) End Sub End Class
Pero esto aplica el nivel de transparencia a todo el formulario. Por desgracia no se puede limitar a un determinado color.
y si hago lo siguiente hace las dos cosas, sustrae el color asignado al 100% dejándolo todo transparente, excepto el resto del formulario que queda semi-transparente Private Sub SubstractColor(ByVal HWND As IntPtr, Optional ByVal GradoTr As Byte = 128) SetWindowLong(HWND, GWL_EXSTYLE, GetWindowLong(HWND, GWL_EXSTYLE) Or WS_EX_LAYERED) SetLayeredWindowAttributes(HWND, GreenColor, GradoTr, LWA_ALPHA + LWA_COLORKEY) End Sub
mejor: Private Sub SubstractColor(ByVal HWND As IntPtr, ByVal Color As Integer, Optional ByVal GradoTr As Byte = 128) SetWindowLong(HWND, GWL_EXSTYLE, GetWindowLong(HWND, GWL_EXSTYLE) Or WS_EX_LAYERED) SetLayeredWindowAttributes(HWND, Color, GradoTr, LWA_ALPHA + LWA_COLORKEY) End Sub
Encontré una persona que quiso hacer lo mismo aquí http://forums.codeguru.com/showthread.php?477962-Tranparent-color
no se puede hacer, al menos de una forma sencilla, tengo alguna idea pero va para rato. Sería creando un objeto COM o una nueva ventana incrustada en la aplicación mediante código.
|
|
|
538
|
Programación / .NET (C#, VB.NET, ASP) / substraer color
|
en: 21 Abril 2019, 22:03 pm
|
estoy intentado substraer el color de una imagen. El objetivo es superponer un objeto PictureBox y hacer transparentar una parte de color verde de modo que se puedan ver objetos que hay debajo del PictureBox. He intentado esto, pero lo único que consigo es un agujero en el formulario, ya que al transparentar el color verde de la imagen que está en el picture, también transparenta el formulario y se ve el escritorio, o cualquier cosa que haya debajo del formulario de la aplicación. Imports System Imports System.Runtime.InteropServices Imports System.Security Imports System.Drawing.Imaging Public Class Form1 <DllImport("User32.dll", CharSet:=CharSet.Unicode), SuppressUnmanagedCodeSecurityAttribute> Private Shared Function SetLayeredWindowAttributes(ByVal HWND As IntPtr, ByVal crKey As Integer, ByVal bAlpha As Byte, ByVal dwFlags As Integer) As Integer End Function <DllImport("User32.dll", EntryPoint:="GetWindowLongA", CharSet:=CharSet.Unicode), SuppressUnmanagedCodeSecurityAttribute> Private Shared Function GetWindowLong(ByVal HWND As IntPtr, ByVal nIndex As Integer) As Integer End Function <DllImport("User32.dll", EntryPoint:="SetWindowLongA", CharSet:=CharSet.Unicode), SuppressUnmanagedCodeSecurityAttribute> Private Shared Function SetWindowLong(ByVal HWND As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer End Function Const GWL_EXSTYLE = (-20) Const WS_EX_LAYERED = &H80000 Const GreenColor = &HFF00 Private Function SubstractColor(ByVal HWND As IntPtr, Color As Integer) As Integer SetWindowLong(HWND, GWL_EXSTYLE, GetWindowLong(HWND, GWL_EXSTYLE) Or WS_EX_LAYERED) SetLayeredWindowAttributes(HWND, Color, 0, &H1) Return Nothing End Function Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load SubstractColor(Me.Handle, GreenColor) End Sub End Class
Mi Net no tiene la System.Windows.Media que creo serviría para esto. https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.color.subtract?view=netframework-4.8Tampoco me funciona lo de backcolor = color. transparent, ni aún colocando imágenes con transparencia. Recuerdo que el objetivo es recortar o substraer una parte del PictureBox en la sección marcada por un determinado color. Parece complicado
|
|
|
|
|
|
|