我从网上抓取了很多图片,它们都是各种尺寸 - 它们可以是大的,小的等等。
所以当我在单元格中显示它们时我可以调整它们的大小,但这样效率很低。在SDWebImage下载它们并缓存它们的大小后,更好地调整它们的大小,而不是将大图像存储在磁盘上并为每个单元调整大小。
那么我怎么能用SDWebImage做到这一点,或者我不得不在课堂上进行一些修改?
答案 0 :(得分:24)
SDWebImage开发人员Olivier Poitrey为我回答了这个问题here。
您必须实现SDWebImageManagerDelegate协议,然后将其设置为共享管理器的委托,如下所示:
SDWebImageManager.sharedManager.delegate = self;
using the imageManager:transformDownloadedImage:withURL: instance method.
完美地为我工作。
答案 1 :(得分:4)
我遇到了和你一样的问题,并尝试首先调整SDWebImage,但最终构建了我自己的组件来解决问题。您可以在此处查看:https://github.com/adig/RemoteImageView
答案 2 :(得分:0)
SDWebImage 3.8.2
如果使用UIImageView类别<Guid("$guid1$")> _
<ComVisible(True)> _
<SwAddin( _
Description:="$safeprojectname$ description", _
Title:="$safeprojectname$", _
LoadAtStartup:=True _
)> _
Public Class SwAddin
Implements SolidWorks.Interop.swpublished.SwAddin
#Region "SolidWorks Registration"
<ComRegisterFunction()> Public Shared Sub RegisterFunction(ByVal t As Type)
' Get Custom Attribute: SwAddinAttribute
Dim attributes() As Object
Dim SWattr As SwAddinAttribute = Nothing
attributes = System.Attribute.GetCustomAttributes(GetType(SwAddin), GetType(SwAddinAttribute))
If attributes.Length > 0 Then
SWattr = DirectCast(attributes(0), SwAddinAttribute)
End If
Try
Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
Dim keyname As String = "SOFTWARE\SolidWorks\Addins\{" + t.GUID.ToString() + "}"
Dim addinkey As Microsoft.Win32.RegistryKey = hklm.CreateSubKey(keyname)
addinkey.SetValue(Nothing, 0)
addinkey.SetValue("Description", SWattr.Description)
addinkey.SetValue("Title", SWattr.Title)
keyname = "Software\SolidWorks\AddInsStartup\{" + t.GUID.ToString() + "}"
addinkey = hkcu.CreateSubKey(keyname)
addinkey.SetValue(Nothing, SWattr.LoadAtStartup, Microsoft.Win32.RegistryValueKind.DWord)
Catch nl As System.NullReferenceException
Console.WriteLine("There was a problem registering this dll: SWattr is null.\n " & nl.Message)
System.Windows.Forms.MessageBox.Show("There was a problem registering this dll: SWattr is null.\n" & nl.Message)
Catch e As System.Exception
Console.WriteLine("There was a problem registering this dll: " & e.Message)
System.Windows.Forms.MessageBox.Show("There was a problem registering this dll: " & e.Message)
End Try
End Sub
<ComUnregisterFunction()> Public Shared Sub UnregisterFunction(ByVal t As Type)
Try
Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
Dim keyname As String = "SOFTWARE\SolidWorks\Addins\{" + t.GUID.ToString() + "}"
hklm.DeleteSubKey(keyname)
keyname = "Software\SolidWorks\AddInsStartup\{" + t.GUID.ToString() + "}"
hkcu.DeleteSubKey(keyname)
Catch nl As System.NullReferenceException
Console.WriteLine("There was a problem unregistering this dll: SWattr is null.\n " & nl.Message)
System.Windows.Forms.MessageBox.Show("There was a problem unregistering this dll: SWattr is null.\n" & nl.Message)
Catch e As System.Exception
Console.WriteLine("There was a problem unregistering this dll: " & e.Message)
System.Windows.Forms.MessageBox.Show("There was a problem unregistering this dll: " & e.Message)
End Try
End Sub
。我创建了另一个UIImageView类别(扩展名)
sd_setImageWithURL
答案 3 :(得分:0)
扩展MaeSTRo在 Swift 3 中的回答:
myImageView.sd_setImage(with: imageUrl){ (image, error, cacheType, url) in
guard let image = image, cacheType == .none else { return }
DispatchQueue.global(qos: .userInitiated).async {
let modifiedImage = myImageProcessor(image)
SDWebImageManager.shared().saveImage(toCache: modifiedImage, for: imageUrl)
DispatchQueue.main.async {
myImageView.image = modifiedImage
myImageView.setNeedsDisplay()
}
}
}