# .NET and More > Silverlight >  load images

## pikosan

Hi everyone, 
i got application which allows users to choose images from their own locations in computer and application has button add. when they click it the picture is displayed and starts to rotate as in carousel. i would like to add some images that would be preloaded. would it be possible to use this application for that?d (VB.Net was used to build initial application). Thank you.

----------


## pikosan

forgot to mention. Silverlight 4 was used for building application.

----------


## Lightning

If you have the source it's no problem

----------


## pikosan

Here is the code I was using



```
Partial Public Class Carousel
    Inherits UserControl
    Private Rotation As New Storyboard
    Private Images As New List(Of ImageSource)
    Private Items As New List(Of CarouselItem)
    Private Position As Point
    Private Radius As Point = New Point With {.X = 150, .Y = -40}
    Private Speed As Double = 0.0125
    Private Perspective As Double = 200
    Private Distance As Double




    Private Sub Populate(ByRef Canvas As Canvas)
        Canvas.Children.Clear()
        For Each image In Images
            Dim index As Integer
            Dim item As New CarouselItem
            item.Image.Source = image
            item.Angle = index * ((Math.PI * 2) / Images.Count)
            Position.X = Math.Cos(item.Angle) * Radius.X
            Position.Y = Math.Sin(item.Angle) * Radius.Y
            Canvas.SetLeft(item, Position.X)
            Canvas.SetTop(item, Position.Y)
            Distance = 1 / (1 - (Position.Y / Perspective))
            item.ItemScale.ScaleY = Distance
            item.ItemScale.ScaleX = item.ItemScale.ScaleY
            item.Opacity = item.ItemScale.ScaleX
            Items.Add(item)
            Canvas.Children.Add(item)
            index += 1
        Next
    End Sub





    Private Sub Rotate()
        For Each item As CarouselItem In Items
            item.Angle -= Speed
            Position.X = Math.Cos(item.Angle) * Radius.X
            Position.Y = Math.Sin(item.Angle) * Radius.Y
            Canvas.SetLeft(item, Position.X)
            Canvas.SetTop(item, Position.Y)
            If Radius.Y >= 0 Then
                Distance = 1 * (1 - (Position.Y / Perspective))
                Canvas.SetZIndex(item, CInt(Position.Y))
            Else
                Distance = 1 / (1 - (Position.Y / Perspective))
                Canvas.SetZIndex(item, CInt(Position.Y))
            End If
            item.ItemScale.ScaleY = Distance
            item.ItemScale.ScaleX = item.ItemScale.ScaleY
            item.Opacity = item.ItemScale.ScaleX
        Next
        Rotation.Begin()

    End Sub

    Public Sub Add(ByVal Source As ImageSource)
        Images.Add(Source)

        Populate(Display)
    End Sub

    Public Sub RemoveLast()
        If Images.Count > 0 Then
            Images.RemoveAt(Images.Count - 1)
            Populate(Display)
        End If
    End Sub

    Public Sub Clear()
        Images.Clear()
        Populate(Display)
    End Sub


    Public Sub New()
        InitializeComponent()
        Canvas.SetLeft(Display, Container.Width / 2 - Display.Width / 2)
        Canvas.SetTop(Display, Container.Height / 2 - Display.Height / 2)
        AddHandler Rotation.Completed, AddressOf Rotate
        Rotation.Begin()
    End Sub

    

    Private Function ImageMedium() As Object
        ImageMedium.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/images/image1.png", UriKind.Absolute))
    End Function


End Class
```

If somebody could help me with it I would be very appreciated. I need my images to be loaded from the images folder. Thank you

----------


## MattP

Initialize your Images List with the images you want to start with and call Populate in the constructor.

----------


## gep13

pikosan,

When you are posting code into the forum, can you please remember to surround it in [code][/code] or [HIGHLIGHT=vb][/highlight] tags?  It makes it a lot easier to read.

I have edited your posted to do this.

Thanks

Gary

----------

