相关疑难解决方法(0)

加载图像时内存不足异常

我使用以下代码将图像作为缩略图加载到FlowLayoutPanel控件.不幸的是我得到了OutOfMemory异常.

正如您已经猜到的那样,内存泄漏是在线上找到的

 Pedit.Image = System.Drawing.Image.FromStream(fs)
Run Code Online (Sandbox Code Playgroud)

那我怎么能优化下面的代码呢?

 Private Sub LoadImagesCommon(ByVal FlowPanel As FlowLayoutPanel, ByVal fi As FileInfo)
        Pedit = New DevExpress.XtraEditors.PictureEdit
        Pedit.Width = txtIconsWidth.EditValue
        Pedit.Height = Pedit.Width / (4 / 3)
        Dim fs As System.IO.FileStream
        fs = New System.IO.FileStream(fi.FullName, IO.FileMode.Open, IO.FileAccess.Read)
        Pedit.Image = System.Drawing.Image.FromStream(fs)
        fs.Close()
        fs.Dispose()
        Pedit.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom

        If FlowPanel Is flowR Then
            AddHandler Pedit.MouseClick, AddressOf Pedit_MouseClick
            AddHandler Pedit.MouseEnter, AddressOf Pedit_MouseEnter
            AddHandler Pedit.MouseLeave, AddressOf Pedit_MouseLeave
        End If

        FlowPanel.Controls.Add(Pedit)
    End Sub
Run Code Online (Sandbox Code Playgroud)

更新:加载大量图像时出现问题(3264x2448px为300dpi - 每个图像大约为3Mb)

vb.net memory-leaks memory-management image image-processing

3
推荐指数
1
解决办法
1万
查看次数

如何使用图像索引将图像添加到imageList

我是c#的初学者.这是一个小问题.我想用图像索引将图像添加到图像列表.

  ilsLargeFlags  --> ImageList
  strFlagPath --> full file path
  strPetPath  --> only file name (gif image)
Run Code Online (Sandbox Code Playgroud)

我尝试了下面的代码:( 不工作)

 ilsLargeFlags.Images.Add(Image.FromFile(strFlagPath));
 ilsLargeFlags.Images.SetKeyName(8, strPetPath);
Run Code Online (Sandbox Code Playgroud)

我在上面的代码中做错了什么?

imageList中已有8个图像.通过简单的用户界面添加(我不知道它是什么)

.net c# imagelist

0
推荐指数
1
解决办法
8443
查看次数