Load Image from Flutter IOS plugin assets folder - flutter

I try to write a plugin for my Flutter project, I want to load an image from plugin Assets folder, do anyone know how can I load this frame.png from objective c native code?
I tried use: [[NSBundle mainBundle] pathForResource:#"frame" ofType:#"png"];
but it getting null. Anyone here know how to load this image?
Thanks

If you are developing a flutter plugin and need to have native assets these are the following things you have to do,
Add your files in Assets folder or any other folder inside ios folder
Add the following line in podspec file
s.resources = 'Assets/*.png'
Access the file using Bundle
let bundle = Bundle(for: YourPlugin.self)
let url = bundle.url(forResource: "frame", withExtension: "png")!

Related

Swift how to reference an image file that is not in *.xcassets folder in storyboard

I was trying to update the icon of my app in LaunchScreen, turned out that the UIImage doesn't update for the situation that a user update from old version to new version, and I searched on web for some solutions, there is one suggesting that I should load image files that are out of the *.xcassets folder, I know how to put the image files to my project root directory, but I don't know how to load it in storyboard, as LaunchScreen.storyboard can't have a view controller class
So my question is: How to reference image files in storyboard
This is the source link: http://arsenkin.com/launch_screen_image_cache.html
You can't use any custom behavior in LaunchScreen.storyboard. And loading images from anywhere except *.xcassets is a custom behavior.
Generally you'd use something like
let path = Bundle.main.path(forResource: "image", ofType: "imageType")
let image = UIImage(contentsOfFile: path!)
to load such an image, but as I've already mentioned, this approach doesn't work for launch screens

Swift : WKWebView not showing image on device

I am loading a html file to WKWebview from local everything is working fine but it is not showing image on iPhone.
This is the code i am using to load a html file
do{
let fileName = try String(contentsOf: destinationURLForFile)
print("fileName is equal to\(fileName)")
webView.loadHTMLString(fileName, baseURL: destinationURLForFile)
}catch{
}
Trying to fix since hours. Any suggestions would be helpful!
I had a very similar issue yesterday, you need to tell the build to copy this file to the device as part of the bundle.
Make sure sure you have the HTML file in the Copy Bundle Resources part of the build settings. Just go to the project settings > build phases > copy bundle resources and if your HTML file is not listed there, click the + button and add it.
This should solve your issue, if not could you please provide more information, are you getting any errors, does the file actually exist?

Where should I add my own Markdown file in Vapor project?

I want to add my own Markdown file, a file named profile.md. However, I don't know where I should add the file in my Vapor project, which is developed in Xcode.
I tried adding it to Sources/ or just the root directory, but it cannot be searched by Bundle.main.url(forResource:) function, like:
guard let url = Bundle.main.url(forResource: "profile", withExtension: ".md") else { ... }
Also, I found that I already added it under Copy Bundle Resources tab.
In the normal app (for iOS and macOS), the function above works properly.
How can I add my own file to be used in Vapor project developed in Xcode?
This is a very basic example of loading the contents of a file from a custom location using Foundation rather than Vapor's template view loading mechanism, and returning it as a text response.
drop.get { req in
let templateString = try String(contentsOfFile: drop.workDir + "Resources/profile.md")
return templateString
}
I'm not sure exactly what you mean by "parse, and embed it into another template file" but you'd put that bit in between the lines above.

Import Image into Eclipse Plugin

I have developed an eclipse Plugin using Java SWT. My plugin has few Wizard Pages.
Now, I need to add an image/logo on the header part of the Wizard Pages.
Can anyone give suggestions on how to do the same using SWT please.
Images in a plugin are usually placed in an images or icons folder - don't forget to add this folder to the build.properties so that it will be included in the built plugin.
You load images from the folder using:
final URL fullPathString = FileLocator.find(bundle, new Path(path), null);
ImageDescriptor imageDesc = ImageDescriptor.createFromURL(fullPathString);
Image image = imageDesc.createImage();
bundle is your plugin Bundle, you can get this from your Activator (if you have one) or using:
Bundle bundle = Platform.getBundle("plugin id");
or
Bundle bundle = FrameworkUtil.getBundle(getClass());
path is the image path relative to the plugin - so something like images/xxx.gif
If you create an Image you must dispose of it when done (ImageDescriptor does not need to be disposed).
You can use org.eclipse.jface.resource.ImageRegistry to manage the images and image descriptors.
Update:
Once you have an ImageDescriptor you set it as the title image on a wizard page by calling WizardPage.setImageDescriptor(descriptor).

NSBundle -- finding resources within a bundle?

I created a directory MyDirectory inside a bundle myBundle. I then put an image myImage.png inside MyDirectory. But a call to
[myBundle pathForResource: #"myImage" ofType: #"png"]
does not find the image. What am I missing?
EDIT: To clarify, if the image is in the top level of the bundle, it finds it just fine.
First you must have added the image to the bundle. If you've did it, I guess you would have added folder references while you added the image to the project. If so, you should specify the folder hierarchy with the image name.
[myBundle pathForResource:#"MyDirectory/myImage" ofType:#"png"];
Edit: As Deepak commented below, there is even a better method pathForResource:ofType:inDirectory:
[myBundle pathForResource:#"myImage" ofType:#"png" inDirectory:#"MyDirectory"];
Did you add the image to your Xcode project (project.pbxproj)?