Adding image in java code in code name - codenameone

I am new in code name one. I have to add image in a container(flow layout) with specific width and height.
1: codenameone's guide says that we have to add image in resource folder. Where is that resource folder?
2: To create image i am using createImage(path) of image class. if we put image file in resource folder then what is path of that image.
3: Is here any type restriction of image file in it.
Please help.

When you put the image you would like to add in your src folder the code should look as followed:
Label i = new Label();
Image img = Image.createImage("/imageToAdd.png");
i.setIcon(img);
You can change the label to whatever object you would like to use to display your image.

Resource file not folder, the ".res" file in the root of the SRC directory contains your theme as well as additional images you might need. The value here is that you can add multi-images (see tutorial) as well as write very portable code.
You can access the resource file in a GUI builder via fetchResourceFile() or in a non-GUI builder app using Resources.open (as is demonstrated in the init method).
You can also place arbitrary JPG/PNG files in the src root next to the res file. While there is no restriction from Codename One, devices tend to support PNG/JPG well and might fail with other formats.

Related

WPF cannot set Build Action for added file [duplicate]

I would like to assign a BitmapImage from my Resources.resx to an Image.
Beforehand I saved a .png image to Resources.resx. This image is now located in "/Resources/logo.png".
After reading several SO posts and other articles I have this now:
logoImage.Source = new BitmapImage(new Uri(#"pack://application:,,,/Resources/logo.png"));
Unfortunately it doesn't work.
I don't know how to solve this.
I tried to replace the Pack-URI with the fullpath and it worked but I would like to use relative paths in order to use the same source on different machines on which the absolute path would be incorrect.
Can anyone help me out with this?
In order to make that Uri work, the file logo.png must be contained in a folder named "Resources" in your VS project (see first image), and its Build Action must be set to Resource (see second image).
This Resources folder is completely unrelated to Resources.resx. You may rename it to whatever you like.

Custom theme in ExtJS pointing to wrong image folders

I've create a custom theme using Sencha ExtJS and the compass compile and sencha splice commands.
I have a folder structure as follows:
/ext-4.1.0 -- This is where the stock SDK resides
/resources -- copied from the SDK template, as per the instructions
/resources/sass -- This is where my SASS and confif.rb file reside
/resources/css -- This is where compass compiles my my-ext-theme.css
/resources/images/foo/bar.gif -- This is where sencha splice creates my GIFs.
The problem is, the newly-compiled /resources/css/my-ext-theme.css is referring to all images with the relative paths like ../../ext-4.1.0/resources/themes/images/default/foo/bar.gif.
Why is my custom theme compiling to refer to the stock image folder rather than my custom images?
Here are the key parameters in my config.rb file:
$ext_path = "../../ext-4.1.0"
sass_path = File.dirname(__FILE__)
css_path = File.join(sass_path, "..", "css")
load File.join(File.dirname(__FILE__), $ext_path, 'resources', 'themes')
I don't want to pollute my ext-4.1.0 folder with custom theme files if possible.
Apparently the "bug" referred to in the documentation here applies to version 4.1.0, not just to 4.0.7. Changing the utils.rb file as described fixed the relative path problem:
http://www.sencha.com/learn/theming/

ReportViewer WPF - Set Images Dynamically

I'd like to load image(s) at runtime (dynamically) into my report (inside the header).
I've already create the following parameter:
Name: Path
Datatype: String (should be the path to the image)
Allow Blank = True
Then I've draged and droped an image control to my report.
Set the name to: Image2
Imagesource: External
Use the following image: [#Path]
Now (back in my MainWindow) I've added the following code:
viewerInstance.LocalReport.EnableExternalImages = true;
List<ReportParameter> param1 = new List<ReportParameter>();
//header_2.png exists (for test purposes) in the root folder
param1.Add(new ReportParameter("Path", #"/header_2.png"));
viewerInstance.LocalReport.SetParameters(param1);
It doesn't work.
I'll get this error message:
The invocation of the constructor on type 'ReportViewer.MainWindow' that matches the specified binding constraints threw an exception.
{"The source of the report definition has not been specified"}
Any ideas?
I am not very sure about how to do it with External Images using the absolute path in SSRS 2008. But I guess I can provide with a workaround but this would work only in case you have all the images that you would be using in reports available to you beforehand.
You can add an Image control to the report. In the Image Control property, provide name, select the image source as Embedded, and click on Import, and select the image. Click Import. The image is imported. Now you can import all images like this. Once done, go to Image control property again and set the Use this Image as "[#Path]". Now you do not need to pass the absolute path but only the image name amongst the imported images which you can see under images in Report Data.
Also, if you want to use External Images, as per this msdn article you need to provide the Url for the image and not the absolute path. In this case you can hoist your image on a server and pass the path in the Path parameter. Select the image source as External. I have tested this and it works.
Edit: You can also upload the images to the ReportServer through the Report Manager and provide the path to that image as the relative path in the RDL after you specify the Image Source as external. e.g. /Report/Logo.png. You can also upload multiple images and use them by providing the path as parameter to the report.

Drupal Attachments (FileField) file path

What function in Drupal gets file attachment path?
Edit: the attachments provided by Upload module in system section. But since you mentioned there may be another way around it. Maybe I could achieve may goals using FileField module so if you could tell me how to get a direct link of a file uploaded by FileField module that may also be very helpful.
Edit 2:
Ok I will start from my main and final objective:
It is to get an image linking to a file which visibility I could be managed using CCK module.
I am doing this step by step. So now I have written a code which generates the needed image and I have added that image to one of content types teaser. I found a way to warp my image in a tag and I had dug up simple attachments url. So my next step is to advance from simple upload attachment to the one added by FileFields and from odd looking HTML pace in all PHP document into beautifully managed CCK field.
How to fetch file path of a file uploaded FileFields?
Some plain and at the same time rich tutorials for making custom fields for CCK module.
Assuming you know how to get the $node object for a node containing a file attachment, this is super easy:
Upload (core)
$file = upload_load($node);
echo $file[1]->filepath;
Where 1 is the index of the file. Upload can let you upload more than one file, so file 2 would have an index of 2 and so on. If there's only one file, it'll always be 1.
More info: upload_load() API reference.
FileField
echo $node->field_fieldname[0]['filepath'];
Where field_filename is the short name you've used for the field, and 0 is the index of the field. CCK fields let you have multiple values in one field, so 0 would be the first, 1 would be the second, etc. If you only have one value, it'll always be 0.
Note: if you want to get the rendered output of the FileField using its formatters, you can just use $field_fieldname in your node template, or if you want to store the rendered output, you can use:
echo content_format('field_fieldname', $node->field_fieldname[0]);
More info: content_format() API reference.
Upload is a sad little module, and has been completely replaced with a core implementation of FileField in Drupal 7. If you have the option to use FileField, you should.
Don't direct links of file attachments appear below the uploaded file for the core Upload module?
Since you are trying to use images, you should use http://drupal.org/project/imagefield CCK module in order to add images to specified content type. After that using the Display fields tab in Content type configuration you can specify how image would be presented (as a link, image, image with link to node...) both in teaser and body view.

looping through an image folder in a wpf application

I currently am loading all images in a folder in my "MyPictures" folder on my machine which works fine...
foreach (string filename in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)))
What I really want to be able to do, though, is load all the images in my Images folder within my solution project. Can someone please tell me the correct syntax to do this?
[Nothing in your question (as it is currently stated) is really directly related to WPF as opposed to C# (and Windows development) in general, as far as I can tell. You might get a better reply if the question was tagged to C# as opposed to just WPF.]
I don't think there is a way to reference your solution's folder as such (nor does it really make much sense, as the users of your application won't in general have the solution, only the distributables).
If you need the directory to be within your solution folder somehow, maybe you should refer to the directory your executable resides in (...\SolutionDir\bin\Debug), which you can get using
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly()
.GetModules()[0].FullyQualifiedName);
(Of course, you could tack \..\.. to that to refer to the SolutionDir instead, but that'd be a bit ugly.)
Depending on the usage of the images, though, it'd probably be better to put them under one of the defined special directories -- Environment.SpecialFolder.CommonApplicationData sounds like the best candidate, if the images are to be shared by all users.
One way to access images stored in a folder inside the WPF project is to do the following:
If you have already added the images inside an Images folder, Add the images file names in the Resources.resx file under Properties. You can access the images in the code by the following
string imageFilename = "pack://application:,,,/APP.UI;component/Images/" + Properties.Resources.imagefilename;
var src = new BitmapImage();
src.UriSource = new Uri(imageFilename , UriKind.Absolute);

Resources