How to avoid a NSCachedImageRep - objective-c

I'm working with an NSImage which comes from a PDF. When I initially create the image, it has only one NSImageRep and that is NSPDFImageRep. This is good. I can work with it. I can find out how many pages it has, and go to a specified page, and draw it, etc.
The problem is that as soon as I turn my back, it gets turned into a NSCachedImageRep, which doesn't seem to have multiple pages. Now, if I keep the PDFImageRep in a separate variable, it is kept track of, but it isn't associated with the image anymore, so when I draw the image, it's still on the same page.
What am I missing?
thanks.

You need to call [image setDataRetained:YES] on the image, so that your original PDF data is kept around, otherwise it will be cached to a bitmap.
If you're still having problems you could turn off caching altogether by using [image setCacheMode:NSImageCacheNever].

Try it on 10.6. The problem has probably evaporated.
Please see the AppKit release notes for details of the NSImage changes.

Related

Wrong images loading using AFNetworking

I have tiny issue in my app. I load data from JSON and then take image links and load images on cells. Im not sure i really should paste all of my code, since it may not concern the issue. Just want to point i use
[imageView setImageWithURL:url];
and in myCell custom class i use:
- (void)prepareForReuse {
[self.myCellImageView cancelImageRequestOperation];
self.myCellImageView.image = nil;
}
Second code snipper fix the issue when u smoothly scroll table, tableView load correct images. But there is the trick - if u press on status bar on an iPhone (place where your clock, battery charge and carrier name appears) you may get from bottom of your table to top in fraction of second.
During that, application proceed to load wrong images (apparently, recently loaded in bottom cells), and after switching images it set correct one.
I want to admit, that problem almost didn't noticeable if u scrolling with low or medium speed, it only appears when you make enormous move from one side of tableView to another. But still, its nasty bug. How could i fix it?
Thanks!

SDL Window shows final frame from the last time the program was run in the background of a new window when I start up a new instance

I'm making a simple game and just messing around with SDL. I have two images currently, and I am practicing making them the background. I make one the background by calling RenderCopy, the DestroyTexture to clear it from memory, and then I present it. I changed the file path from one image to the other to change the background. I ran the program, and now the new image is layered on top of the other. I can fix this problem if I manually do a clean of my computer's memory, and it renders properly. For some reason, SDL is not clearing the image called previously. There is no mention of the old image anywhere else in the code, and all the Destroy functions are called. What is going on?
Edit: I did a little bit of snooping and its not that it even loads the old image; whatever the final render displayed on any program running SDL was before it was run, it will be the background. It is literally like a TV burning an image into the screen; its always there.
The problem was fixed by simply clearing the frame between frames. Didn't have any performance impact.

Keeping backing CAGradientLayer static when UITableView scrolls

I'm trying to use a CAGradientLayer as a background for a UITableView. Everything works well until the overlaying view is scrolled, at which point then the pre-rendered background scrolls up and out of the way along with the original screen of data.
This is code that is being migrated from an iOS 3.1.3 app using a UIImage as a background to something device/resolution independent-looks great, works well, but sniffing the device type and using an alternate png isn't the sort of code that I want to ship, much less maintain.
Any suggestions as to how to do this?
Found the solution to what I was trying to solve, courtesy of Matt Gallagher:
http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html
His blog post has quite a few nice touches, including shadowing relevant cells instead of the whole table (mentioned as a performance issue in Noah's response).
You may have to make the table view transparent, and add the gradient layer to the table's superview. Keep in mind that your scrolling performance is probably going to be hideous—Core Animation will have to composite every subview of the table for every frame it displays. You may be able to slightly mitigate this by setting the cells' layers to rasterize themselves, as described here, but expect things to be pretty choppy regardless.

UIImage change raw pixels from white to clear?

I've tried some code from each of these questions:
How to make one color transparent on a UIImage?
How to mask a UIImage so that white becomes transparent on iphone?
but have come up unsuccessful, unfortunately working with Core Graphics and images is not my strong suit.
How would I go about accessing a UIImage's raw data and changing the white pixels to clear?
How would I go about accessing a UIImage's raw data …?
Look at the documentation.
You'll find that there is no way to get the raw data behind a UIImage. The closest you can get is a CGImage. That will let you get its data provider, which you can ask for a copy of the raw data.
The problem with that solution is that you need to handle every possible configuration (RGBA, ARGB, RGB_, _RGB, RGB, 8-bpc, 16-bpc, etc.) that CGImage supports. That's a lot of work. If you don't do it, then someday, you'll get surprised by an image that somehow doesn't work with your code, or by an OS upgrade changing how the CGImage gets created.
The CGImageCreateWithMaskingColors function, suggested on one of the other questions you linked to, is the correct solution.
One thing that's tripping you up is that the values shown in the accepted answer on that question are generally bogus: They're out of range. The Quartz 2D Programming Guide has more details in at least two.places.
I also argue against including that answer's createMask: method, since it doesn't do what it says it does and is barely useful at all (it's only worth having if the source image may be CMYK, but how likely is that on an iPhone app?). Skip it and create the mask image from the UIImage's CGImage directly.
That answer will probably work just fine once you fix those two problems.

Removing the image from an IKImageView

I have an IKImageView that is coming up effectively un-initialized. This is happening effectively in an error-state (The user is unregistered) so I haven't had a chance to put an image in it yet.
In 10.6, this comes up fine, with a black rectangle. In 10.5, however, it comes up with garbage. some rectangles of noise, some rectangles of copies of the desktop, etc. I've tried setting the ZoomFactor to 0.0, I've tried setting the image to nil, but it appears that the problem is beyond that.
any ideas? (My next kludge is going to be to ship tiny blank image with the app, and try to get it to load that... but that's kind of silly)
Designing your product such that this view is not displayed when it has no content to display would be the most obvious course of action.