elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


  Mostrar Mensajes
Páginas: 1 ... 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 [565] 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 ... 1254
5641  Programación / .NET (C#, VB.NET, ASP) / Re: diseño de interfaz en: 16 Abril 2015, 09:37 am
Interfáz ...de?.

...aplicación de escritorio?, aplicación web?, un juego?, un sistema operativo?.

¿Qué lenguaje, tecnología, y framework?.

¿La aplicación debe tener alguna funcionalidad en concreto?, es decir, ¿para que debe servir esa aplicación?.

No somos magos, especifica los detalles necesarios al formular una pregunta de programación!.



De todas formas por tus posts, intuyo que te refieres a una aplicación de escritorio en C# bajo tecnología WindowsForms y los controles de Microsoft .Net Framework, aunque sigo desconociendo la funcionalidad de dicha app.

Trata de diseñar una interfáz amigable, sencilla de entender, en ingles (¡NO EN ESPAÑOL!) o multi-idioma,
ponte en la piel del end-user, utiliza mensajes de ayuda (tooltips) para facilitarle el manejo por tu aplicación, si tienes textboxes u otros controles de edición entonces no te olvides de añadir text-hints (tips de ayuda que aparecen en controles vacíos para indicar de que manera se debe rellenar el texto),
y a menos que sea un programa muy simple con "un botón" entonces nunca metas toda la lógica del programa en un solo form, divide el programa en "secciones", el form principal con la funcionalidad principal, el form de opciones con la configuración del programa, etc...

Puedes utilizar pestañas (tabs) verticales o laterales, o un menú, entre otras técnicas.

También podrías implementar un menú Ribbon
Easily Add a Ribbon into a WinForms Application (C#)

Si te está permitido usar cualquier cosa para el diseño de la interfáz, entonces indiscutiblemente debes utilizar un set de controles de terceros (o también podrías personalizar por ti mismo los controles de Microsoft), sin duda alguna yo te recomiendo los controles de Telerik para permitirte desarrollar una aplicación con una interfáz única y espléndida:
Telerik for WinForms

Otros controles muy buenos son:
Krypton
DotNetBar

Si prefieres algún recurso gratuito (no te lo recmiendo) siempre hay muchos controles gratuitos en la página CodeProject, además de tutoriales, etc...

Cómo este, lo saqué de dicha página (para que te hagas una idea):
[APORTE] Amazing ProgressBar

El compañero @Doddy compartió unos themes bastante interesantes:
[Tutorial] Skins para C#

Yo compartí el source de algunos user-control que desarrollé cómo este:
[SOURCE] ElektroListBox v2.1

Por último, si quieres intentar impresionar a tu profesor/a para ganar "puntos" entonces esta vez intenta trabajar de una manera profesional, trata de diseñar un mockup (una especie de Sketch de aplicaciones) y enséñale eso antes de implementar el diseño en la aplicación.

Yo te recomiendo esta aplicación:
Balsamiq Mockups

Pero también podrías usar:
PowerMockup
WireframeSketcher Studio

Saludos!
5642  Informática / Software / Re: kgb archiver en: 15 Abril 2015, 16:35 pm
Pense que desarrollaban su propio algoritmo je

no, pero para que todo quede dicho, supuestamente mejoraban algún aspecto del algoritmo original (no se que aspectos, ni tampoco lo que considerarán "mejora").

saludos
5643  Programación / Scripting / Re: FOR que ejcute script en subdirectorios en: 14 Abril 2015, 21:54 pm
Añádele el parámetro /R al FOR para habilitar la recursividad de archivos.

Código:
For /R %%# In () DO ()

Es algo muy básico, trata de buscar antes de preguntar:
For - Looping commands | Windows CMD | SS64.com
(ni siquiera debes buscar, tienes la documentación del FOR en la ayuda del comando, en consola: FOR /?)

Saludos
5644  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 14 Abril 2015, 13:09 pm
Una helper class para manejar los servicios de Windows.

Por el momento puede listar, iniciar, detener, y determinar el estado o el modo de inicio de un servicio.
(no lo he testeado mucho en profundidad)

Ejemplos de uso:
Código
  1.        Dim svcName As String = "themes"
  2.        Dim svcDisplayName As String = ServiceUtils.GetDisplayName(svcName)
  3.        Dim svcStatus As ServiceControllerStatus = ServiceUtils.GetStatus(svcName)
  4.        Dim svcStartMode As ServiceUtils.SvcStartMode = ServiceUtils.GetStartMode(svcName)
  5.  
  6.        ServiceUtils.SetStartMode(svcName, ServiceUtils.SvcStartMode.Automatic)
  7.        ServiceUtils.SetStatus(svcName, ServiceUtils.SvcStatus.Stop, wait:=True, throwOnStatusMissmatch:=True)

Source code:
Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 14-April-2015
  4. ' ***********************************************************************
  5. ' <copyright file="ServiceUtils.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Usage Examples "
  11.  
  12. 'Dim svcName As String = "themes"
  13. 'Dim svcDisplayName As String = ServiceUtils.GetDisplayName(svcName)
  14. 'Dim svcStatus As ServiceControllerStatus = ServiceUtils.GetStatus(svcName)
  15. 'Dim svcStartMode As ServiceUtils.SvcStartMode = ServiceUtils.GetStartMode(svcName)
  16.  
  17. 'ServiceUtils.SetStartMode(svcName, ServiceUtils.SvcStartMode.Automatic)
  18. 'ServiceUtils.SetStatus(svcName, ServiceUtils.SvcStatus.Stop, wait:=True, throwOnStatusMissmatch:=True)
  19.  
  20. #End Region
  21.  
  22. #Region " Option Statements "
  23.  
  24. Option Strict On
  25. Option Explicit On
  26. Option Infer Off
  27.  
  28. #End Region
  29.  
  30. #Region " Imports "
  31.  
  32. Imports Microsoft.Win32
  33. Imports System.ServiceProcess
  34.  
  35. #End Region
  36.  
  37. ''' <summary>
  38. ''' Contains related Windows service tools.
  39. ''' </summary>
  40. Public NotInheritable Class ServiceUtils
  41.  
  42. #Region " Enumerations "
  43.  
  44.    ''' <summary>
  45.    ''' Indicates the status of a service.
  46.    ''' </summary>
  47.    Public Enum SvcStatus
  48.  
  49.        ''' <summary>
  50.        ''' The service is running.
  51.        ''' </summary>
  52.        Start
  53.  
  54.        ''' <summary>
  55.        ''' The service is stopped.
  56.        ''' </summary>
  57.        [Stop]
  58.  
  59.    End Enum
  60.  
  61.    ''' <summary>
  62.    ''' Indicates the start mode of a service.
  63.    ''' </summary>
  64.    Public Enum SvcStartMode As Integer
  65.  
  66.        ''' <summary>
  67.        ''' Indicates that the service has not a start mode defined.
  68.        ''' Since a service should have a start mode defined, this means an error occured retrieving the start mode.
  69.        ''' </summary>
  70.        Undefinied = 0
  71.  
  72.        ''' <summary>
  73.        ''' Indicates that the service is to be started (or was started) by the operating system, at system start-up.
  74.        ''' The service is started after other auto-start services are started plus a short delay.
  75.        ''' </summary>
  76.        AutomaticDelayed = 1
  77.  
  78.        ''' <summary>
  79.        ''' Indicates that the service is to be started (or was started) by the operating system, at system start-up.
  80.        ''' If an automatically started service depends on a manually started service,
  81.        ''' the manually started service is also started automatically at system startup.
  82.        ''' </summary>
  83.        Automatic = 2 'ServiceStartMode.Automatic
  84.  
  85.        ''' <summary>
  86.        ''' Indicates that the service is started only manually,
  87.        ''' by a user (using the Service Control Manager) or by an application.
  88.        ''' </summary>
  89.        Manual = 3 'ServiceStartMode.Manual
  90.  
  91.        ''' <summary>
  92.        ''' Indicates that the service is disabled, so that it cannot be started by a user or application.
  93.        ''' </summary>
  94.        Disabled = 4 ' ServiceStartMode.Disabled
  95.  
  96.    End Enum
  97.  
  98. #End Region
  99.  
  100. #Region " Public Methods "
  101.  
  102.    ''' <summary>
  103.    ''' Retrieves all the services on the local computer, except for the device driver services.
  104.    ''' </summary>
  105.    ''' <returns>IEnumerable(Of ServiceController).</returns>
  106.    Public Shared Function GetServices() As IEnumerable(Of ServiceController)
  107.  
  108.        Return ServiceController.GetServices.AsEnumerable
  109.  
  110.    End Function
  111.  
  112.    ''' <summary>
  113.    ''' Gets the name of a service.
  114.    ''' </summary>
  115.    ''' <param name="svcDisplayName">The service's display name.</param>
  116.    ''' <returns>The service name.</returns>
  117.    ''' <exception cref="ArgumentException">Any service found with the specified display name.;svcDisplayName</exception>
  118.    Public Shared Function GetName(ByVal svcDisplayName As String) As String
  119.  
  120.        Dim svc As ServiceController = (From service As ServiceController In ServiceController.GetServices()
  121.                                        Where service.DisplayName.Equals(svcDisplayName, StringComparison.OrdinalIgnoreCase)
  122.                                        ).FirstOrDefault
  123.  
  124.        If svc Is Nothing Then
  125.            Throw New ArgumentException("Any service found with the specified display name.", "svcDisplayName")
  126.  
  127.        Else
  128.            Using svc
  129.                Return svc.ServiceName
  130.            End Using
  131.  
  132.        End If
  133.  
  134.    End Function
  135.  
  136.    ''' <summary>
  137.    ''' Gets the display name of a service.
  138.    ''' </summary>
  139.    ''' <param name="svcName">The service name.</param>
  140.    ''' <returns>The service's display name.</returns>
  141.    ''' <exception cref="ArgumentException">Any service found with the specified name.;svcName</exception>
  142.    Public Shared Function GetDisplayName(ByVal svcName As String) As String
  143.  
  144.        Dim svc As ServiceController = (From service As ServiceController In ServiceController.GetServices()
  145.                                        Where service.ServiceName.Equals(svcName, StringComparison.OrdinalIgnoreCase)
  146.                                        ).FirstOrDefault
  147.  
  148.        If svc Is Nothing Then
  149.            Throw New ArgumentException("Any service found with the specified name.", "svcName")
  150.  
  151.        Else
  152.            Using svc
  153.                Return svc.DisplayName
  154.            End Using
  155.  
  156.        End If
  157.  
  158.    End Function
  159.  
  160.    ''' <summary>
  161.    ''' Gets the status of a service.
  162.    ''' </summary>
  163.    ''' <param name="svcName">The service name.</param>
  164.    ''' <returns>The service status.</returns>
  165.    ''' <exception cref="ArgumentException">Any service found with the specified name.;svcName</exception>
  166.    Public Shared Function GetStatus(ByVal svcName As String) As ServiceControllerStatus
  167.  
  168.        Dim svc As ServiceController =
  169.            (From service As ServiceController In ServiceController.GetServices()
  170.             Where service.ServiceName.Equals(svcName, StringComparison.OrdinalIgnoreCase)
  171.            ).FirstOrDefault
  172.  
  173.        If svc Is Nothing Then
  174.            Throw New ArgumentException("Any service found with the specified name.", "svcName")
  175.  
  176.        Else
  177.            Using svc
  178.                Return svc.Status
  179.            End Using
  180.  
  181.        End If
  182.  
  183.    End Function
  184.  
  185.    ''' <summary>
  186.    ''' Gets the start mode of a service.
  187.    ''' </summary>
  188.    ''' <param name="svcName">The service name.</param>
  189.    ''' <returns>The service's start mode.</returns>
  190.    ''' <exception cref="ArgumentException">Any service found with the specified name.</exception>
  191.    ''' <exception cref="Exception">Registry value "Start" not found for service.</exception>
  192.    ''' <exception cref="Exception">Registry value "DelayedAutoStart" not found for service.</exception>
  193.    Public Shared Function GetStartMode(ByVal svcName As String) As SvcStartMode
  194.  
  195.        Dim reg As RegistryKey = Nothing
  196.        Dim startModeValue As Integer = 0
  197.        Dim delayedAutoStartValue As Integer = 0
  198.  
  199.        Try
  200.            reg = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\" & svcName, writable:=False)
  201.  
  202.            If reg Is Nothing Then
  203.                Throw New ArgumentException("Any service found with the specified name.", paramName:="svcName")
  204.  
  205.            Else
  206.                startModeValue = Convert.ToInt32(reg.GetValue("Start", defaultValue:=-1))
  207.                delayedAutoStartValue = Convert.ToInt32(reg.GetValue("DelayedAutoStart", defaultValue:=0))
  208.  
  209.                If startModeValue = -1 Then
  210.                    Throw New Exception(String.Format("Registry value ""Start"" not found for service '{0}'.", svcName))
  211.                    Return SvcStartMode.Undefinied
  212.  
  213.                Else
  214.                    Return DirectCast([Enum].Parse(GetType(SvcStartMode),
  215.                                                   (startModeValue - delayedAutoStartValue).ToString), SvcStartMode)
  216.  
  217.                End If
  218.  
  219.            End If
  220.  
  221.        Catch ex As Exception
  222.            Throw
  223.  
  224.        Finally
  225.            If reg IsNot Nothing Then
  226.                reg.Dispose()
  227.            End If
  228.  
  229.        End Try
  230.  
  231.    End Function
  232.  
  233.    ''' <summary>
  234.    ''' Gets the start mode of a service.
  235.    ''' </summary>
  236.    ''' <param name="svc">The service.</param>
  237.    ''' <returns>The service's start mode.</returns>
  238.    Public Shared Function GetStartMode(ByVal svc As ServiceController) As SvcStartMode
  239.  
  240.        Return GetStartMode(svc.ServiceName)
  241.  
  242.    End Function
  243.  
  244.    ''' <summary>
  245.    ''' Sets the start mode of a service.
  246.    ''' </summary>
  247.    ''' <param name="svcName">The service name.</param>
  248.    ''' <param name="startMode">The start mode.</param>
  249.    ''' <exception cref="ArgumentException">Any service found with the specified name.</exception>
  250.    ''' <exception cref="ArgumentException">Unexpected value.</exception>
  251.    Public Shared Sub SetStartMode(ByVal svcName As String,
  252.                                   ByVal startMode As SvcStartMode)
  253.  
  254.        Dim reg As RegistryKey = Nothing
  255.  
  256.        Try
  257.            reg = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\" & svcName, writable:=True)
  258.  
  259.            If reg Is Nothing Then
  260.                Throw New ArgumentException("Any service found with the specified name.", paramName:="svcName")
  261.  
  262.            Else
  263.  
  264.                Select Case startMode
  265.  
  266.                    Case SvcStartMode.AutomaticDelayed
  267.                        reg.SetValue("DelayedAutoStart", 1, RegistryValueKind.DWord)
  268.                        reg.SetValue("Start", SvcStartMode.Automatic, RegistryValueKind.DWord)
  269.  
  270.                    Case SvcStartMode.Automatic, SvcStartMode.Manual, SvcStartMode.Disabled
  271.                        reg.SetValue("DelayedAutoStart", 0, RegistryValueKind.DWord)
  272.                        reg.SetValue("Start", startMode, RegistryValueKind.DWord)
  273.  
  274.                    Case Else
  275.                        Throw New ArgumentException("Unexpected value.", paramName:="startMode")
  276.  
  277.                End Select
  278.  
  279.            End If
  280.  
  281.        Catch ex As Exception
  282.            Throw
  283.  
  284.        Finally
  285.            If reg IsNot Nothing Then
  286.                reg.Dispose()
  287.            End If
  288.  
  289.        End Try
  290.  
  291.    End Sub
  292.  
  293.    ''' <summary>
  294.    ''' Sets the start mode of a service.
  295.    ''' </summary>
  296.    ''' <param name="svc">The service.</param>
  297.    ''' <param name="startMode">The start mode.</param>
  298.    Public Shared Sub SetStartMode(ByVal svc As ServiceController,
  299.                                   ByVal startMode As SvcStartMode)
  300.  
  301.        SetStartMode(svc.ServiceName, startMode)
  302.  
  303.    End Sub
  304.  
  305.    ''' <summary>
  306.    ''' Sets the status of a service.
  307.    ''' </summary>
  308.    ''' <param name="svcName">The service name.</param>
  309.    ''' <param name="status">The desired service status.</param>
  310.    ''' <param name="wait">if set to <c>true</c> waits for the status change completition.</param>
  311.    ''' <param name="throwOnStatusMissmatch">
  312.    ''' If set to <c>true</c> throws an error when attempting to start a service that is started,
  313.    ''' or attempting to stop a service that is stopped.
  314.    ''' </param>
  315.    ''' <exception cref="ArgumentException">Any service found with the specified name.;svcName</exception>
  316.    ''' <exception cref="ArgumentException">Cannot start service because it is disabled.</exception>
  317.    ''' <exception cref="ArgumentException">Cannot start service because a dependant service is disabled.</exception>
  318.    ''' <exception cref="ArgumentException">The service is already running or pendng to run it.</exception>
  319.    ''' <exception cref="ArgumentException">The service is already stopped or pendng to stop it.</exception>
  320.    ''' <exception cref="ArgumentException">Unexpected enumeration value.</exception>
  321.    ''' <exception cref="Exception"></exception>
  322.    Public Shared Sub SetStatus(ByVal svcName As String,
  323.                                ByVal status As SvcStatus,
  324.                                Optional wait As Boolean = False,
  325.                                Optional ByVal throwOnStatusMissmatch As Boolean = False)
  326.  
  327.        Dim svc As ServiceController = Nothing
  328.  
  329.        Try
  330.            svc = (From service As ServiceController In ServiceController.GetServices()
  331.                   Where service.ServiceName.Equals(svcName, StringComparison.OrdinalIgnoreCase)
  332.                  ).FirstOrDefault
  333.  
  334.            If svc Is Nothing Then
  335.                Throw New ArgumentException("Any service found with the specified name.", "svcName")
  336.  
  337.            ElseIf GetStartMode(svc) = SvcStartMode.Disabled Then
  338.                Throw New Exception(String.Format("Cannot start or stop service '{0}' because it is disabled.", svcName))
  339.  
  340.            Else
  341.  
  342.                Select Case status
  343.  
  344.                    Case SvcStatus.Start
  345.  
  346.                        Select Case svc.Status
  347.  
  348.                            Case ServiceControllerStatus.Stopped,
  349.                                 ServiceControllerStatus.StopPending,
  350.                                 ServiceControllerStatus.Paused,
  351.                                 ServiceControllerStatus.PausePending
  352.  
  353.                                For Each dependantSvc As ServiceController In svc.ServicesDependedOn
  354.  
  355.                                    If GetStartMode(dependantSvc) = SvcStartMode.Disabled Then
  356.                                        Throw New Exception(String.Format("Cannot start service '{0}' because a dependant service '{1}' is disabled.",
  357.                                                                          svcName, dependantSvc.ServiceName))
  358.                                        Exit Select
  359.                                    End If
  360.  
  361.                                Next dependantSvc
  362.  
  363.                                svc.Start()
  364.                                If wait Then
  365.                                    svc.WaitForStatus(ServiceControllerStatus.Running)
  366.                                End If
  367.  
  368.                            Case ServiceControllerStatus.Running,
  369.                                 ServiceControllerStatus.StartPending,
  370.                                 ServiceControllerStatus.ContinuePending
  371.  
  372.                                If throwOnStatusMissmatch Then
  373.                                    Throw New Exception(String.Format("The service '{0}' is already running or pendng to run it.", svcName))
  374.                                End If
  375.  
  376.                        End Select
  377.  
  378.                    Case SvcStatus.Stop
  379.  
  380.                        Select Case svc.Status
  381.  
  382.                            Case ServiceControllerStatus.Running,
  383.                                 ServiceControllerStatus.StartPending,
  384.                                 ServiceControllerStatus.ContinuePending
  385.  
  386.                                svc.Stop()
  387.                                If wait Then
  388.                                    svc.WaitForStatus(ServiceControllerStatus.Stopped)
  389.                                End If
  390.  
  391.                            Case ServiceControllerStatus.Stopped,
  392.                                 ServiceControllerStatus.StopPending,
  393.                                 ServiceControllerStatus.Paused,
  394.                                 ServiceControllerStatus.PausePending
  395.  
  396.                                If throwOnStatusMissmatch Then
  397.                                    Throw New Exception(String.Format("The service '{0}' is already stopped or pendng to stop it.", svcName))
  398.                                End If
  399.  
  400.                        End Select
  401.  
  402.                    Case Else
  403.                        Throw New ArgumentException("Unexpected enumeration value.", paramName:="status")
  404.  
  405.                End Select
  406.  
  407.            End If
  408.  
  409.        Catch ex As Exception
  410.            Throw
  411.  
  412.        Finally
  413.            If svc IsNot Nothing Then
  414.                svc.Close()
  415.            End If
  416.  
  417.        End Try
  418.  
  419.    End Sub
  420.  
  421. #End Region
  422.  
  423. End Class
5645  Foros Generales / Foro Libre / Re: El español hablado en Andalucía en: 14 Abril 2015, 09:39 am
¿Soy el único que piensa que esto no tiene ningún sentido y estais llevando ya el tema hacia límites extremos?.

No se, pero por hacer una simple comparación, nunca he visto a alguien que por llamarle subnormal vaya y publique un post sobre el coeficiente intelectual de su ciudad o sobre psicología para intentar demostrar algo... xD. ¿se entiende, no?.

Saludos!
5646  Foros Generales / Foro Libre / Re: He olvidado una cuenta de correo en: 13 Abril 2015, 13:09 pm
Microsoft tiene un foro de soporte dedicado para problemas con Hotmail (outlook.com), el cual por cierto a mi me ayudó en varias ocasiones para recuperar cuentas, cualquier moderador de allí te podrá intentar solucionar el conflicto con tu cuenta de correo siempre que te puedas identificar cómo el propietario de tal.

Soporte:
http://windows.microsoft.com/es-419/windows/contact-support

Soporte Outlook
http://answers.microsoft.com/es-es/outlook_com

Preguntar en el foro de Outlook:
http://answers.microsoft.com/es-es/newthread?forum=outlook_com&threadtype=Questions&cancelurl=%2Fes-es%2Foutlook_com

PD: La idea es que hagas una cuenta temporal con la que puedas publicar en el foro para exponer el problema que tienes con la cuenta que no recuerdas.

Saludos.
5647  Foros Generales / Foro Libre / Re: He olvidado una cuenta de correo en: 13 Abril 2015, 12:29 pm
Muy poca información das.

Acude a la asistencia online del servicio de mail que tengas.

Para Gmail: https://support.google.com/dartsignin/answer/114766?hl=en



De todas formas, si has iniciado sesión a dicho servicio desde tu navegador y no has eliminado los rastros entonces revisa las cookies de esa página web de mail para intentar hallar el nombre de usuario
https://addons.mozilla.org/en-us/firefox/addon/cookies-manager-plus/

o, en caso de que también hayas guardado la contraseña al iniciar sesión entonces prueba a utilizar aplicaciones cómo Browser Password Decryptor para que te sea más sencillo de localizar:
http://securityxploded.com/browser-password-decryptor.php

Slaudos
5648  Foros Generales / Foro Libre / Re: ayuda para independizarme en: 13 Abril 2015, 09:05 am
hola mi nombre es Enrique y vivo con mi madre tengo 30 años de eda
bueno yo quiero independisame, estoy buscando prestamista por internet
y todo son legares bueno pues entoce e desidido pedirle un credito a la mafia
estoy pensando en ir a clubs de alterne a intenta da con la mafia pero no me atrevo balla que sea una mafia solo especialisada en mujeres y se cabreen
aver si arguien de foro me puede aurienta
, saludos.

.
..
...

5649  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 11 Abril 2015, 15:05 pm
Transformar una imagen a blanco y negro:

Código
  1.    ''' <summary>
  2.    ''' Transforms an image to black and white.
  3.    ''' </summary>
  4.    ''' <param name="img">The image.</param>
  5.    ''' <returns>The black and white image.</returns>
  6.    Public Shared Function GetBlackAndWhiteImage(ByVal img As Image) As Image
  7.  
  8.        Dim bmp As Bitmap = New Bitmap(img.Width, img.Height)
  9.  
  10.        Dim grayMatrix As New System.Drawing.Imaging.ColorMatrix(
  11.            {
  12.                New Single() {0.299F, 0.299F, 0.299F, 0, 0},
  13.                New Single() {0.587F, 0.587F, 0.587F, 0, 0},
  14.                New Single() {0.114F, 0.114F, 0.114F, 0, 0},
  15.                New Single() {0, 0, 0, 1, 0},
  16.                New Single() {0, 0, 0, 0, 1}
  17.            })
  18.  
  19.        Using g As Graphics = Graphics.FromImage(bmp)
  20.  
  21.            Using ia As System.Drawing.Imaging.ImageAttributes = New System.Drawing.Imaging.ImageAttributes()
  22.  
  23.                ia.SetColorMatrix(grayMatrix)
  24.                ia.SetThreshold(0.5)
  25.  
  26.                g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height,
  27.                                                 GraphicsUnit.Pixel, ia)
  28.  
  29.            End Using
  30.  
  31.        End Using
  32.  
  33.        Return bmp
  34.  
  35.    End Function
5650  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 11 Abril 2015, 13:38 pm
Una simple función que publiqué en S.O para cifrar/descifrar un String mediante la técnica de Caesar.

Ejemplo de uso:
Código
  1.        Dim value As String = "Hello World!"
  2.  
  3.        Dim encrypted As String = CaesarEncrypt(value, shift:=15)
  4.        Dim decrypted As String = CaesarDecrypt(encrypted, shift:=15)
  5.  
  6.        Debug.WriteLine(String.Format("Unmodified string: {0}", value))
  7.        Debug.WriteLine(String.Format("Encrypted  string: {0}", encrypted))
  8.        Debug.WriteLine(String.Format("Decrypted  string: {0}", decrypted))

Source:
Código
  1.    ''' <summary>
  2.    ''' Encrypts a string using Caesar's substitution technique.
  3.    ''' </summary>
  4.    ''' <remarks> http://en.wikipedia.org/wiki/Caesar_cipher </remarks>
  5.    ''' <param name="text">The text to encrypt.</param>
  6.    ''' <param name="shift">The character shifting.</param>
  7.    ''' <param name="charSet">A set of character to use in encoding.</param>
  8.    ''' <returns>The encrypted string.</returns>
  9.    Public Shared Function CaesarEncrypt(ByVal text As String,
  10.                                         ByVal shift As Integer,
  11.                                         Optional ByVal charSet As String =
  12.                                                        "abcdefghijklmnopqrstuvwxyz" &
  13.                                                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" &
  14.                                                        "0123456789" &
  15.                                                        "çñáéíóúàèìòùäëïöü" &
  16.                                                        "ÇÑÁÉÍÓÚÀÈÌÒÙÄËÏÖÜ" &
  17.                                                        " ,;.:-_´¨{`^[+*]ºª\!|""#$~%€&¬/()=?¿'¡}*") As String
  18.  
  19.        Dim sb As New System.Text.StringBuilder With {.Capacity = text.Length}
  20.  
  21.        For Each c As Char In text
  22.  
  23.            Dim charIndex As Integer = charSet.IndexOf(c)
  24.  
  25.            If charIndex = -1 Then
  26.                Throw New ArgumentException(String.Format("Character '{0}' not found in character set '{1}'.", c, charSet), "charSet")
  27.  
  28.            Else
  29.                Do Until (charIndex + shift) < (charSet.Length)
  30.                    charIndex -= charSet.Length
  31.                Loop
  32.  
  33.                sb.Append(charSet(charIndex + shift))
  34.  
  35.            End If
  36.  
  37.        Next c
  38.  
  39.        Return sb.ToString
  40.  
  41.    End Function
  42.  
  43.    ''' <summary>
  44.    ''' Decrypts a string using Caesar's substitution technique.
  45.    ''' </summary>
  46.    ''' <remarks> http://en.wikipedia.org/wiki/Caesar_cipher </remarks>
  47.    ''' <param name="text">The encrypted text to decrypt.</param>
  48.    ''' <param name="shift">The character shifting to reverse the encryption.</param>
  49.    ''' <param name="charSet">A set of character to use in decoding.</param>
  50.    ''' <returns>The decrypted string.</returns>
  51.    Public Shared Function CaesarDecrypt(ByVal text As String,
  52.                                         ByVal shift As Integer,
  53.                                         Optional ByVal charSet As String =
  54.                                                        "abcdefghijklmnopqrstuvwxyz" &
  55.                                                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" &
  56.                                                        "0123456789" &
  57.                                                        "çñáéíóúàèìòùäëïöü" &
  58.                                                        "ÇÑÁÉÍÓÚÀÈÌÒÙÄËÏÖÜ" &
  59.                                                        " ,;.:-_´¨{`^[+*]ºª\!|""#$~%€&¬/()=?¿'¡}*") As String
  60.  
  61.        Return CaesarEncrypt(text, shift, String.Join("", charSet.Reverse))
  62.  
  63.    End Function
Páginas: 1 ... 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 [565] 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 ... 1254
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines