ahco Posted February 3, 2017 at 12:03 PM Report Share #602311 Posted February 3, 2017 at 12:03 PM Bom dia, Alguem me consegue informar de uma maneira rapida e leve de inserir imagens na listview ?? eu tenho uma mas estou a começar a ter problemas de desempenho. na db tenho no nome da foto e depois vai buscar a foto á pasta. Dim imgs As ImageList = New ImageList() imgs.ImageSize = New Size(90, 90) 'our files img Dim files As String() = New String() {} files = Directory.GetFiles(Application.StartupPath & "\imgimoveis\") Array.Reverse(files) 'files.OrderBy() For Each row As DataRow In sqlDatafile.Rows Dim id As String = row("IDimoveisVendidos").ToString Dim compara As String = Application.StartupPath & "\imgimoveis\" + row("IMG").ToString Dim Naoexisteimg As String = Nothing If row("IMG").ToString = Nothing Then imgs.Images.Add(Image.FromFile(Application.StartupPath & "\SYSTEM\nopic.jpg")) Else For Each f In files If f = compara Then If File.Exists(compara) Then imgs.Images.Add(Image.FromFile(f)) Naoexisteimg = compara Else imgs.Images.Add(Image.FromFile(Application.StartupPath & "\SYSTEM\nopic.jpg")) End If Else If File.Exists(f) = False Then 'imgs.Images.Add(Image.FromFile(f)) imgs.Images.Add(Image.FromFile(Application.StartupPath & "\SYSTEM\nopic.jpg")) Else End If End If Next If Naoexisteimg = Nothing Then imgs.Images.Add(Image.FromFile(Application.StartupPath & "\SYSTEM\nopic.jpg")) End If End If Next ListView1.SmallImageList = imgs Link to comment Share on other sites More sharing options...
ahco Posted February 10, 2017 at 03:04 PM Author Report Share #602437 Posted February 10, 2017 at 03:04 PM Boa tarde, Arranjei uma maneira melhor para por imagens na listview Partilho com vocês. Dim imgs As ImageList = New ImageList() imgs.ColorDepth = ColorDepth.Depth24Bit imgs.ImageSize = New Size(90, 80) Dim files As String() = New String() {} files = Directory.GetFiles(Application.StartupPath & "\imgimoveis\") Array.Reverse(files) For Each row As DataRow In sqlDatafile.Rows Dim id As String = row("IDimoveisVendidos").ToString Dim compara As String = Application.StartupPath & "\imgimoveis\" + row("IMG").ToString Dim Naoexisteimg As String = Nothing If row("IMG").ToString = Nothing Then imgs.Images.Add(Image.FromFile(Application.StartupPath & "\SYSTEM\nopic.jpg")) Else Dim ficheirocerto As String = Array.IndexOf(files, compara) If ficheirocerto <> Nothing Then If File.Exists(compara) Then imgs.Images.Add(Image.FromFile(files(ficheirocerto))) Else imgs.Images.Add(Image.FromFile(Application.StartupPath & "\SYSTEM\nopic.jpg")) End If End If End If Next 1 Report Link to comment Share on other sites More sharing options...
ahco Posted February 16, 2017 at 05:46 PM Author Report Share #602561 Posted February 16, 2017 at 05:46 PM Boas, tou a ver que ninguém tem problemas com a listview so eu. Relativamente ao código acima, ele é mais rápido, mas quando falamos que mais de 100 imagens sem resize, a imagelist rebenta () System out of memory. visto que ela põe tudo em memoria. Tive a testar e de facto essa situação acontecia, por isso tive a mexer novamente, não é tão rápido e simples mas não estoira. Dim imgs As ImageList = New ImageList() imgs.ColorDepth = ColorDepth.Depth24Bit imgs.ImageSize = New Size(90, 80) Dim files As String() = New String() {} files = Directory.GetFiles(Application.StartupPath & "\img\") Array.Reverse(files) Dim Table1 As New DataTable Table1.Columns.Add("ficheiro") For Each f In files Table1.Rows.Add(f) Next Dim callback As System.Drawing.Image.GetThumbnailImageAbort For Each row As DataRow In sqlDatafile.Rows Dim id As String = row("ID").ToString Dim compara As String = Application.StartupPath & "\img\" + row("IMG").ToString Dim Naoexisteimg As String = Nothing If row("IMG").ToString = Nothing Then imgs.Images.Add(Image.FromFile(Application.StartupPath & "\SYSTEM\nopic.jpg")) Else Dim ficheirocerto As String = Array.IndexOf(files, compara) If ficheirocerto <> Nothing Then If File.Exists(compara) Then For Each linha As DataRow In Table1.Rows Dim valordt As String = linha("ficheiro").ToString() If valordt = compara Then Dim pic As Image pic = Image.FromFile(compara) imgs.Images.Add(pic.GetThumbnailImage(90, 80, callback, System.IntPtr.Zero)) pic.Dispose() End If Next Else imgs.Images.Add(Image.FromFile(Application.StartupPath & "\SYSTEM\nopic.jpg")) End If End If End If Next Espero que possa ajudar alguém. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now