I am new to IOS development and trying to load image from url using Kingfisher library. I am using Kingfisher 2.6 with Xcode 7 and swift 2.3.
For that i have created a collection view cell with images. All works fine at first run. Images are shown but as i scroll down my collection view all images are gone. No new images are loaded and i also can't see my previous images.
This is my code
url = myUrl
url += product.image!
productImage.kf_setImageWithURL(NSURL(string: url),placeholderImage: UIImage(named: "placeholder.png"),optionsInfo: [KingfisherOptionsInfoItem.CacheMemoryOnly],progressBlock: nil,completionHandler: nil)
Please help me to cache and show image.
Related
I have an app that presents a bunch of thumbnail images and they are automatically cached using:
WebImage(url: URL(string: currentWallpaper.thumbnailURL), options: SDWebImageOptions.retryFailed)
This works great. When a user selects a thumbnail I present a full screen version:
WebImage(url: URL(string: currentWallpaper.hiresUrl), options: SDWebImageOptions.retryFailed)
When a user displays an image full res I have the ability to swipe to present the next or previous hires image without going back to my thumbnail catalog.. so I prefetch both the previous and next image so it feels immediate when they swipe.
After a while loading images gets sluggish. I'm thinking I'd like to setup a separate cache for the hires images so when the user goes back to the thumbnail view I can clear it but still keep the thumbs in cache. Or just limit the number of images in that cache, something like.
I'm just not finding any examples of how to point WebImage to a custom cache. I see how to create one:
let hiresCache = SDImageCache(namespace: "hiresCache")
SDImageCachesManager.shared.addCache(hiresCache)
Just not exactly how to use it. Ideally WebImage just allows you to pass a cache to it, but I'm not seeing that as an option. Or maybe someone has a better solution
As soon as I updated my iPhone XS Max to 13.2.2 & macOS Catalina to 10.15.1 I returned working on my project & ran it onto my device. Immediately I noticed every UIImageView that was displaying a UIImage created from an SKTexture.cgImage() was rendering something that literally looked like the missingno from Pokemon Red.
Those same atlas textures render fine inside SKSpriteNode's.
Log debugging returns the UIImage memory as uiimage anonymous
The horizontal white & blue lines is a single background image that has nothing to do with anything. There's a second, smaller image view on top & it's the one rendering the missingno/corrupt image with the texture cgImage() call.
My code is by the book standard for this:
let image = UIImage(cgImage: SKTextureAtlas(named: char.atlasName).textureNamed(char.imageNames.first!).cgImage()
self.imageView.image = image
self.imageView.layer.magnificationFilter = .nearest
My only guess is the latest update did this. I literally did nothing else after updating my system. Just opened the project & ran it. Any ideas if this can be fixed?
Yes, the standard derived data deletion has been tried.
Xcode -> Product -> Clean Build Folder as well
Mac & iPhone have been restarted
I don't know what else I can do but pray
Which is the most preferred method for an in-app web browser? My app has the need to have a toolbar at the bottom, and I need to be able to take screenshots of visited web pages by hitting a button on the toolbar.
Here is what I'm running into. I want to be able to click a link in my app, open an in-app browser, take a screenshot, and save to core data along with other information about the site.
I'm able to save a screenshot to the camera roll with .takesnapshot() method for Webkit. I've been unable to save it to core data. As of last night, I've found a few functions on SO that show how to take a screenshot of the UIView and return a UIImage, but I've been unable to cast this back to Data since this is what Core Data expects for binary data. Does anyone have a good resource to save Webkit snapshots to Core Data?
In one of the functions I attempted last night, I was able to return the UIImage object, but I was unable to convert it back to Data. I can save all other data about the site to Core Data, but I'm unable to save the image - in fact, when I attempted to save the data directly with Webkit's .takesnapshot() method, the result was nil.
I'm going to answer your question in two parts.
WebKit vs SFSafariViewController
If you want to have a custom toolbar with a button for taking screenshots, I would use a UIViewController with a custom tab bar where you can add whatever buttons you want, then I would also embed a WebKit view in the view controller too. That should be pretty straightforward.
Saving screenshot to Core Data
By the sounds of it, you may be getting a screenshot the wrong way, you want to do so with graphics begin and end image context as follows:
let layer = UIApplication.shared.keyWindow!.layer
let scale = UIScreen.main.scale
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale)
layer.render(in: UIGraphicsGetCurrentContext()!)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
Now you have a screenshot saved as a UIImage? in your screenshot variable. Next up you should convert this to data with:
let data = UIImagePNGRepresentation(screenshot!)
Which should give you a data representation of your image that you can then save to Core Data.
I am following this guide for displaying images in wicket How to load external Images
I see one problem and dont know how to solve it. Consider this piece of code
StaticImage img=new StaticImage( "icon", new Model(loadingGIFURL));
//get real image url
img.setDefaultModel(new Model(realURL))
It doesnt show the loading gif, because I override the DefaultModel. So how can I still show my loading gif but "preload" the real image and when the real image is downloaded then replace the loading gif with my image.
Note that I dont have a image source like base64, I only have the image url
I am grabbing my image from a webservice and pasting it into my app. The webservice saves the image as img.jpg. I wanted to change the picture to a different one so I got another one and saved the picture in the same spot to img.jpg. It overwrote the file
When I look in my webservice the picture is the new one. I retrieve the image with AsyncImageView like so:
[AsyncImageLoader sharedLoader] cancelLoadingURL:logoView.imageURL];
logoView.imageURL=[NSURL URLWithString:logourl];
The logourl is filled with the proper url but it isn't grabbing the new image. It is keeping the old image there.
How can I clear that old image and use the new one?
You have to remove the old image from the cache, because the URL is the same for both images the ImageLoader thinks they are the same.
[[AsyncImageCache sharedCache] removeImageForURL:logoView.imageURL];
EDIT:
Seems like my code was from an older version of AsyncImageLoader
Try this:
[[AsyncImageLoader defaultCache] removeObjectForKey:logoView.imageURL];
//Make sure logoView.imageURL is a NSURL