Reputation: 1535
Is it possible to load an image asset from CoreGraphics using MonoTouch?
If so, how?
I can't find anything in the MonoTouch framework that will let me do this.
FYI, I am looking to do this with CoreGraphics, not with CoreImage. I want my app to be compatible with iOS4+, so any way to do it with this in mind is acceptable.
FYI, I already have the asset object I need. I just need to turn this into something the user can see on the screen.
Upvotes: 1
Views: 347
Reputation: 43553
Here's how to load a .PNG into a CGImage
using a CGDataProvider
and then initialize an UIImage
from it (similar to your previous questions about CoreImage).
string file = Path.Combine (NSBundle.MainBundle.ResourcePath, "image.png");
using (var dp = new CGDataProvider (file))
using (var img = CGImage.FromPNG (dp, null, false, CGColorRenderingIntent.Default))
using (var ui = new UIImage (img, 1.0f, UIImageOrientation.Up)) {
Assert.IsNotNull (ui.CGImage, "CGImage");
}
You can use the FromJPEG
method if you have JPEG images (or adjust automatically based on your URL file extension).
Upvotes: 1