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

 

 


Tema destacado:


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Como escalar una imagen dentro de un PictureBox en Visual Studio 2010
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Como escalar una imagen dentro de un PictureBox en Visual Studio 2010  (Leído 5,022 veces)
juanma2468

Desconectado Desconectado

Mensajes: 3


Ver Perfil
Como escalar una imagen dentro de un PictureBox en Visual Studio 2010
« en: 22 Junio 2013, 18:47 pm »

Hola a todo, he estado tratando de escalar una imagen que se encuentra dentro de un picturebox y el resultado de dicha imagen resulta en ser muy difusa. Para poder escalar la imagen lo que utilice fue una de las propiedades del PictureBox, la propiedad Sizemode puesta en Zoom. Pasa que la imagen que quiero representar es chica en cuanto a pixeles, es de 30X30 pixeles, pero necesito agrandarla bastante aunque se vea muy pixelada, pero necesito que los pixeles se distingan bien un de otro, lo cual no he podido lograr hasta ahora. Quisiera saber si alguien sabe de alguna otra forma en la que puedo agrandar la imagen, conservando la nitides de los pixeles. Para darles mas información, lo que hago es recoger un vector de 900 datos por el puerto COM, provenientes de un dispositivo electronico, y los represento de la siguiente manera:
Dim Imagen = New Bitmap(30, 30)
Dim Salto As Integer = 30
Dim Datos_Int(899) As Integer

For i = 0 To 29
For j = 0 To 29
Imagen.SetPixel(j, i, Color.FromArgb(Datos_Int(j + i * Salto), Datos_Int(j + i * Salto), Datos_Int(j + i * Salto)))
Next
Next
ImagenGris.Image = Imagen

El objeto Imagen luego de asignarle cada valor de los pixeles, se la paso al PictureBox con el nombre de ImagenGris, la imagen que estoy representando es en escala de grises.
Adjunto una imagen de la interfase que desarrolle para que vean como se ve la imagen con el zoom.
Desde ya muchas gracias al que me pueda dar una mano con este tema, saludos.

LINK IMAGEN: http://img59.imageshack.us/img59/7273/891c.jpg


En línea

XresH


Desconectado Desconectado

Mensajes: 384



Ver Perfil WWW
Re: Como escalar una imagen dentro de un PictureBox en Visual Studio 2010
« Respuesta #1 en: 22 Junio 2013, 21:20 pm »

Mira yo utilizo apis cuando quiero mantener la nitidez de una imágen, el tema es que no he probado con tan chicas, aunque son solo 1 poco mas grandes en el proyecto que tengo aplicado esto.

A ver si te sirve:

Declara estas dos funciones


Código:
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal hStretchMode As Long) As Long


Luego esto en form load o donde quieras:

Código:
Call SetStretchBltMode(picNuevo.hdc, STRETCHMODE)
Call StretchBlt(picNuevo.hdc, 0, 0, 355, 312, picOriginal.hdc, 0, 0, 55, 52, vbSrcCopy)
picNuevo.Refresh

En este caso la imagen original no es 30 x 30, sino 52 x 55 y a un "agrandamiento" de 312 x 355 no presenta distorsión.

Entiende que picNuevo es el Picturebox de destino de la nueva imágen, y el otro tiene la imágen original que deseas agrandar.

Espero sirva, saludos.

Esta en Vb6 pero supongo se podra adaptar.




« Última modificación: 22 Junio 2013, 21:37 pm por XresH » En línea

[ - Si eres programador y quieres que tus proyectos esten en mi blog(con o sin source), consúltame! - ]
Entra A Mi Blog De Programación | | Dudas en este post :| | >>Clic para ir al Post<<
juanma2468

Desconectado Desconectado

Mensajes: 3


Ver Perfil
Re: Como escalar una imagen dentro de un PictureBox en Visual Studio 2010
« Respuesta #2 en: 27 Junio 2013, 04:05 am »

Gracias por responder, tengo una inquietud, donde coloco las dos funciones?,o sea en que parte del codigo, te adjunto todo el codigo que tengo hecho.
Por otro lado cuando llamo las funciones, las tengo que llamar antes o despues de obtener la imagen??.
Código:
Public Class Form1
    Dim Imagen = New Bitmap(30, 30)
    Dim Datos As String
    Dim Salto As Integer = 30
    Dim fps As Integer = 0
    Dim Datos_Int(899) As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PuertosCOM.Items.Clear()
        For Each PuertoDisponible As String In My.Computer.Ports.SerialPortNames
            PuertosCOM.Items.Add(PuertoDisponible)
        Next
        If PuertosCOM.Items.Count > 0 Then
            PuertosCOM.Text = PuertosCOM.Items(0)
        Else
            MessageBox.Show("NO SE ENCONTRARON PUERTOS COM DISPONIBLES")
            PuertosCOM.Items.Clear()
            PuertosCOM.Text = ("                   ")
            BotonCONECTAR.Enabled = False
        End If
    End Sub
    Private Sub BotonCONECTAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BotonCONECTAR.Click
        If BotonCONECTAR.Text = "CONECTAR" Then
            PuertoSerie.PortName = PuertosCOM.Text
            BotonCONECTAR.Text = "DESCONECTAR"
            IndicadorDeEstado.BackColor = Color.Green
            Estado.Text = "Conectado"
            PuertoSerie.Open()
            PuertoSerie.RtsEnable = True
            PuertoSerie.DiscardInBuffer()
            Timer1.Enabled = True
        ElseIf BotonCONECTAR.Text = "DESCONECTAR" Then
            BotonCONECTAR.Text = "CONECTAR"
            IndicadorDeEstado.BackColor = Color.Red
            Estado.Text = "Desconectado"
            Timer1.Enabled = False
            PuertoSerie.RtsEnable = False
            PuertoSerie.Close()
        End If
    End Sub
    Private Sub BuscarPuertos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BuscarPuertos.Click
        PuertosCOM.Items.Clear()
        For Each PuertoDisponible As String In My.Computer.Ports.SerialPortNames
            PuertosCOM.Items.Add(PuertoDisponible)
        Next
        If PuertosCOM.Items.Count > 0 Then
            PuertosCOM.Text = PuertosCOM.Items(0)
        Else
            MessageBox.Show("NO SE ENCONTRARON PUERTOS COM DISPONIBLES")
            PuertosCOM.Items.Clear()
            PuertosCOM.Text = ("                   ")
            BotonCONECTAR.Enabled = False
        End If
    End Sub
    Private Sub PuertoSerie_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles PuertoSerie.DataReceived
        Datos = PuertoSerie.ReadExisting()
        PuertoSerie.DiscardInBuffer()
        If Len(Datos) <> 0 Then
            For k = 0 To 899
                Select Case Datos(k)
                    Case CChar(ChrW(0))
                        Datos_Int(k) = 0
                    Case CChar(ChrW(1))
                        Datos_Int(k) = 1
                    Case CChar(ChrW(2))
                        Datos_Int(k) = 2
                    Case CChar(ChrW(3))
                        Datos_Int(k) = 3
                    Case CChar(ChrW(4))
                        Datos_Int(k) = 4
                    Case CChar(ChrW(5))
                        Datos_Int(k) = 5
                    Case CChar(ChrW(6))
                        Datos_Int(k) = 6
                    Case CChar(ChrW(7))
                        Datos_Int(k) = 7
                    Case CChar(ChrW(8))
                        Datos_Int(k) = 8
                    Case CChar(ChrW(9))
                        Datos_Int(k) = 9
                    Case CChar(ChrW(10))
                        Datos_Int(k) = 10
                    Case CChar(ChrW(11))
                        Datos_Int(k) = 11
                    Case CChar(ChrW(12))
                        Datos_Int(k) = 12
                    Case CChar(ChrW(13))
                        Datos_Int(k) = 13
                    Case CChar(ChrW(14))
                        Datos_Int(k) = 14
                    Case CChar(ChrW(15))
                        Datos_Int(k) = 15
                    Case CChar(ChrW(16))
                        Datos_Int(k) = 16
                    Case CChar(ChrW(17))
                        Datos_Int(k) = 17
                    Case CChar(ChrW(18))
                        Datos_Int(k) = 18
                    Case CChar(ChrW(19))
                        Datos_Int(k) = 19
                    Case CChar(ChrW(20))
                        Datos_Int(k) = 20
                    Case CChar(ChrW(21))
                        Datos_Int(k) = 21
                    Case CChar(ChrW(22))
                        Datos_Int(k) = 22
                    Case CChar(ChrW(23))
                        Datos_Int(k) = 23
                    Case CChar(ChrW(24))
                        Datos_Int(k) = 24
                    Case CChar(ChrW(25))
                        Datos_Int(k) = 25
                    Case CChar(ChrW(26))
                        Datos_Int(k) = 26
                    Case CChar(ChrW(27))
                        Datos_Int(k) = 27
                    Case CChar(ChrW(28))
                        Datos_Int(k) = 28
                    Case CChar(ChrW(29))
                        Datos_Int(k) = 29
                    Case CChar(ChrW(30))
                        Datos_Int(k) = 30
                    Case CChar(ChrW(31))
                        Datos_Int(k) = 31
                    Case CChar(ChrW(32))
                        Datos_Int(k) = 32
                    Case CChar(ChrW(33))
                        Datos_Int(k) = 33
                    Case CChar(ChrW(34))
                        Datos_Int(k) = 34
                    Case CChar(ChrW(35))
                        Datos_Int(k) = 35
                    Case CChar(ChrW(36))
                        Datos_Int(k) = 36
                    Case CChar(ChrW(37))
                        Datos_Int(k) = 37
                    Case CChar(ChrW(38))
                        Datos_Int(k) = 38
                    Case CChar(ChrW(39))
                        Datos_Int(k) = 39
                    Case CChar(ChrW(40))
                        Datos_Int(k) = 40
                    Case CChar(ChrW(41))
                        Datos_Int(k) = 41
                    Case CChar(ChrW(42))
                        Datos_Int(k) = 42
                    Case CChar(ChrW(43))
                        Datos_Int(k) = 43
                    Case CChar(ChrW(44))
                        Datos_Int(k) = 44
                    Case CChar(ChrW(45))
                        Datos_Int(k) = 45
                    Case CChar(ChrW(46))
                        Datos_Int(k) = 46
                    Case CChar(ChrW(47))
                        Datos_Int(k) = 47
                    Case CChar(ChrW(48))
                        Datos_Int(k) = 48
                    Case CChar(ChrW(49))
                        Datos_Int(k) = 49
                    Case CChar(ChrW(50))
                        Datos_Int(k) = 50
                    Case CChar(ChrW(51))
                        Datos_Int(k) = 51
                    Case CChar(ChrW(52))
                        Datos_Int(k) = 52
                    Case CChar(ChrW(53))
                        Datos_Int(k) = 53
                    Case CChar(ChrW(54))
                        Datos_Int(k) = 54
                    Case CChar(ChrW(55))
                        Datos_Int(k) = 55
                    Case CChar(ChrW(56))
                        Datos_Int(k) = 56
                    Case CChar(ChrW(57))
                        Datos_Int(k) = 57
                    Case CChar(ChrW(58))
                        Datos_Int(k) = 58
                    Case CChar(ChrW(59))
                        Datos_Int(k) = 59
                    Case CChar(ChrW(60))
                        Datos_Int(k) = 60
                    Case CChar(ChrW(61))
                        Datos_Int(k) = 61
                    Case CChar(ChrW(62))
                        Datos_Int(k) = 62
                    Case CChar(ChrW(63))
                        Datos_Int(k) = 63
                    Case CChar(ChrW(64))
                        Datos_Int(k) = 64
                    Case CChar(ChrW(65))
                        Datos_Int(k) = 65
                    Case CChar(ChrW(66))
                        Datos_Int(k) = 66
                    Case CChar(ChrW(67))
                        Datos_Int(k) = 67
                    Case CChar(ChrW(68))
                        Datos_Int(k) = 68
                    Case CChar(ChrW(69))
                        Datos_Int(k) = 69
                    Case CChar(ChrW(70))
                        Datos_Int(k) = 70
                    Case CChar(ChrW(71))
                        Datos_Int(k) = 71
                    Case CChar(ChrW(72))
                        Datos_Int(k) = 72
                    Case CChar(ChrW(73))
                        Datos_Int(k) = 73
                    Case CChar(ChrW(74))
                        Datos_Int(k) = 74
                    Case CChar(ChrW(75))
                        Datos_Int(k) = 75
                    Case CChar(ChrW(76))
                        Datos_Int(k) = 76
                    Case CChar(ChrW(77))
                        Datos_Int(k) = 77
                    Case CChar(ChrW(78))
                        Datos_Int(k) = 78
                    Case CChar(ChrW(79))
                        Datos_Int(k) = 79
                    Case CChar(ChrW(80))
                        Datos_Int(k) = 80
                    Case CChar(ChrW(81))
                        Datos_Int(k) = 81
                    Case CChar(ChrW(82))
                        Datos_Int(k) = 82
                    Case CChar(ChrW(83))
                        Datos_Int(k) = 83
                    Case CChar(ChrW(84))
                        Datos_Int(k) = 84
                    Case CChar(ChrW(85))
                        Datos_Int(k) = 85
                    Case CChar(ChrW(86))
                        Datos_Int(k) = 86
                    Case CChar(ChrW(87))
                        Datos_Int(k) = 87
                    Case CChar(ChrW(88))
                        Datos_Int(k) = 88
                    Case CChar(ChrW(89))
                        Datos_Int(k) = 89
                    Case CChar(ChrW(90))
                        Datos_Int(k) = 90
                    Case CChar(ChrW(91))
                        Datos_Int(k) = 91
                    Case CChar(ChrW(92))
                        Datos_Int(k) = 92
                    Case CChar(ChrW(93))
                        Datos_Int(k) = 93
                    Case CChar(ChrW(94))
                        Datos_Int(k) = 94
                    Case CChar(ChrW(95))
                        Datos_Int(k) = 95
                    Case CChar(ChrW(96))
                        Datos_Int(k) = 96
                    Case CChar(ChrW(97))
                        Datos_Int(k) = 97
                    Case CChar(ChrW(98))
                        Datos_Int(k) = 98
                    Case CChar(ChrW(99))
                        Datos_Int(k) = 99
                    Case CChar(ChrW(100))
                        Datos_Int(k) = 100
                    Case CChar(ChrW(101))
                        Datos_Int(k) = 101
                    Case CChar(ChrW(102))
                        Datos_Int(k) = 102
                    Case CChar(ChrW(103))
                        Datos_Int(k) = 103
                    Case CChar(ChrW(104))
                        Datos_Int(k) = 104
                    Case CChar(ChrW(105))
                        Datos_Int(k) = 105
                    Case CChar(ChrW(106))
                        Datos_Int(k) = 106
                    Case CChar(ChrW(107))
                        Datos_Int(k) = 107
                    Case CChar(ChrW(108))
                        Datos_Int(k) = 108
                    Case CChar(ChrW(109))
                        Datos_Int(k) = 109
                    Case CChar(ChrW(110))
                        Datos_Int(k) = 110
                    Case CChar(ChrW(111))
                        Datos_Int(k) = 111
                    Case CChar(ChrW(112))
                        Datos_Int(k) = 112
                    Case CChar(ChrW(113))
                        Datos_Int(k) = 113
                    Case CChar(ChrW(114))
                        Datos_Int(k) = 114
                    Case CChar(ChrW(115))
                        Datos_Int(k) = 115
                    Case CChar(ChrW(116))
                        Datos_Int(k) = 116
                    Case CChar(ChrW(117))
                        Datos_Int(k) = 117
                    Case CChar(ChrW(118))
                        Datos_Int(k) = 118
                    Case CChar(ChrW(119))
                        Datos_Int(k) = 119
                    Case CChar(ChrW(120))
                        Datos_Int(k) = 120
                    Case CChar(ChrW(121))
                        Datos_Int(k) = 121
                    Case CChar(ChrW(122))
                        Datos_Int(k) = 122
                    Case CChar(ChrW(123))
                        Datos_Int(k) = 123
                    Case CChar(ChrW(124))
                        Datos_Int(k) = 124
                    Case CChar(ChrW(125))
                        Datos_Int(k) = 125
                    Case CChar(ChrW(126))
                        Datos_Int(k) = 126
                    Case CChar(ChrW(127))
                        Datos_Int(k) = 127
                    Case Else
                        Datos_Int(k) = 127
                End Select
            Next
            For i = 0 To 29
                For j = 0 To 29
                    Imagen.SetPixel(j, i, Color.FromArgb(Datos_Int(j + i * Salto), Datos_Int(j + i * Salto), Datos_Int(j + i * Salto)))
                Next
            Next
            ImagenGris.Image = Imagen
            fps = fps + 1
        End If
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Cantfps.Text = fps
        fps = 0
    End Sub
End Class

Desde ya muchas gracias
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Introducing .NET 4.0 With Visual Studio 2010
.NET (C#, VB.NET, ASP)
Shell Root 3 5,859 Último mensaje 11 Febrero 2010, 19:39 pm
por Jubjub
Visual Studio 2010
.NET (C#, VB.NET, ASP)
Sarachan 1 3,002 Último mensaje 4 Diciembre 2011, 19:20 pm
por DoNPiNPoN
como Manejar visual studio 2010
.NET (C#, VB.NET, ASP)
LUCKEM 2 3,109 Último mensaje 21 Marzo 2012, 00:55 am
por ABDERRAMAH
programacion en visual studio 2010
.NET (C#, VB.NET, ASP)
leidy martinez 0 2,900 Último mensaje 27 Abril 2012, 02:19 am
por leidy martinez
como poder hacer un istalador de una aplicacion creada en visual studio 2010
.NET (C#, VB.NET, ASP)
yovs 4 3,337 Último mensaje 22 Febrero 2013, 21:05 pm
por ABDERRAMAH
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines