Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: Juancho25 en 26 Abril 2013, 05:19 am



Título: ¿Cómo crear un visualizador de imágenes con botones de siguiente y anterior?
Publicado por: Juancho25 en 26 Abril 2013, 05:19 am
Lo que necesito hacer es crear un picturebox en el cual debo cargar varias imágenes y con botones de "Anterior" y "Siguiente" avanzar o retroceder en las imágenes, según sea el caso. Espero me puedan ayudar con eso.


Título: Re: ¿Cómo crear un visualizador de imágenes con botones de siguiente y anterior?
Publicado por: Eleкtro en 30 Abril 2013, 12:11 pm
Es muy sencillo, indexa las imágenes por ejemplo en un diccionario, y las cargas.

PJMIri5WSi4

Source:
Código
  1. Public Class Form1
  2.  
  3.    Dim ImageList As New Dictionary(Of Int32, String)
  4.    Dim ImageIndex As Int32 = 0
  5.    Dim TotalImages As Int32 = 0
  6.  
  7.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  8.        Load_ImageList()
  9.    End Sub
  10.  
  11.    ' Botón "Anterior"
  12.    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  13.        If Not ImageIndex = 1 Then
  14.            ImageIndex -= 1
  15.            PictureBox1.BackgroundImage = Image.FromFile(ImageList.Item(ImageIndex))
  16.        End If
  17.    End Sub
  18.  
  19.    ' Botón "Siguiente"
  20.    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  21.        If Not ImageIndex = TotalImages Then
  22.            ImageIndex += 1
  23.            PictureBox1.BackgroundImage = Image.FromFile(ImageList.Item(ImageIndex))
  24.        End If
  25.    End Sub
  26.  
  27.    Private Sub Load_ImageList()
  28.        ImageList.Add(1, "F:\Customización\Wallpapers\Animated\[AnimePaper]wallpapers_Bleach_Cilou(1.33)_1280x960_64991.jpg")
  29.        ImageList.Add(2, "F:\Customización\Wallpapers\Animated\0f61391cfd811f6cf57cf74b9fb00211.jpg")
  30.        ImageList.Add(3, "F:\Customización\Wallpapers\Animated\dragon_ball_z_broly_1771x1154_wallpaper_Wallpaper_1920x1440_www.wall321.com.jpg")
  31.        ImageList.Add(4, "F:\Customización\Wallpapers\Girls (Fantasy)\2.jpg")
  32.        ImageList.Add(5, "F:\Customización\Wallpapers\Girls (Fantasy)\7k982aivf38npdom4ol22653m15074a52c3a33c.jpg")
  33.        TotalImages = ImageList.Count
  34.    End Sub
  35.  
  36. End Class


Título: Re: ¿Cómo crear un visualizador de imágenes con botones de siguiente y anterior?
Publicado por: ABDERRAMAH en 30 Abril 2013, 12:24 pm
bueno, eso es, aunque te has vuelto algo loco por el imagelist, realmente me parece mas sencillo con list of bitmap y bitmap.fromfile().


Título: Re: ¿Cómo crear un visualizador de imágenes con botones de siguiente y anterior?
Publicado por: Eleкtro en 30 Abril 2013, 13:08 pm
realmente me parece mas sencillo con list of bitmap y bitmap.fromfile().

Tu eres el que está acostumbrado a trabajar con imágenes :P

Saludos!


Título: Re: ¿Cómo crear un visualizador de imágenes con botones de siguiente y anterior?
Publicado por: ABDERRAMAH en 1 Mayo 2013, 12:31 pm
yo lo haría así

Código:
    Public imagestr As String() = {"imgs/img01.jpg", "imgs/img02.png", "imgs/img03.jpg", "c:/undir/imgs/img04.png"}
    Private imgs As New List(Of Bitmap)
    Private priv_index As Integer = 0

'utilizo una propiedad, de esta manera cuando cambie "index" la imágen
'se sitúa automáticamente en el picturebox

    Public Property index As Integer
        Get
            Return Me.priv_index
        End Get
        Set(value As Integer)
            If value < 0 Then
                If imgs.Count > 0 Then
                    value = imgs.Count - 1
                End If
            ElseIf value >= imgs.Count Then
                value = 0
            End If
            Me.priv_index = value

            try
              Me.picturebox1.image = imgs(Me.priv_index)
            catch ex as exception
              ' no hay imágen !
            end
        End Set
    End Property

' load imagelist lee un bitmap por cada texto en imagestr
' y lo memoriza en imgs

    Public Sub load_imagelist()
        imgs.Clear()
        Dim tmp As Bitmap
        For Each s As String In Me.imagestr
            Try
                tmp = Bitmap.FromFile(s)
                Me.imgs.Add(tmp)
            Catch ex As Exception
                ' no se encuentra el archivo
                ' ¿notificar al usuario?
            End Try
        Next
        Me.index = 0
    End Sub