How do I load dynamic image assets into adobe air - apache-flex

The app I'm working on displays four random images at one point. These four images come from a set of fifty images. If this was a standard Flex project I would just set the img.source property:
this.img1.source ="../assets/img/"+randomname+".png";`
This isn't working though, I'm getting a broken image. One other way to go about it is to load the image with a urlLoader, which is also not loading the image (unsurprisingly, given that it's a local asset)
loader = new Loader();
var urlReq:URLRequest = new URLRequest("../assets/img/"+randomname+".png");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loader.load(urlReq)
So this isn't working either, I'm thinking of loading all of the images into a swc and then linking the swc to the project. This is obviously not great because then all the assets are loaded into memory at runtime. Is there another way of doing this?
I'm hoping that I'm missing something really simple.
If the .swc solution is the best one, can someone point me in the right direction? I forget how that whole business works, as it's been a couple of years since I've worked with Flex/Flash.
Thanks in advance

You should add your asset directories as "source" directories.
Then you should be aware of the fact that the contents of the asset directories will be copied to the root of your application. So when you have the image "assets/interface/bg.png" you should load it using new URLRequest("interface/bg.png").

You may try:
var urlReq:URLRequest = new URLRequest("assets/img/"+randomname+".png");

Related

JAVA FX ImageView only loads certain images when launched

I'm currently working on a poker application for fun and I've encountered another issue when trying to work with imageviews.
Right now my structure for my images is the following:
JavaFXApplication1\src\images
that "images" folder contains two more folders, one being "cards" and the other "playerImages".
Here is a screenshot of it also:project structure
Currently I am using a document relative path within scene builder to initially load the images for each of the cards and players. for each of the cards, the imagepath initially is "#..\images\cards\back.png" which is set in scenebuilder. this method works perfectly fine when launching the application. however, for the player images next to the cards, i have "#..\images\playerImages\player1.png" for example and this doesnt work for some reason.
In scenebuilder the "player1.png" image shows up where it should, but disappears when i launch everything.
I read through Images not showing on launch by the main, but showed on Scene builder but Im not not sure the solution for that is the same for me, as my images are in my source folder.
I tried using the fx:id and setting the image manually in my controller class, but was receiving an error stating that my input stream was null.
I also tried just adding "player1.png" to my root images folder and using that path, and that still didnt work. yet, when I change the player1 image path to anything in the cards folder it works. I dont understand why it works for the images in the cards folder but not in the playerImages folder. Both of those folders are in the same location.
I apologize if this was already answered somewhere else and i am too oblivious to see it, but any insight into this seemingly simple problem would be greatly appreciated.
if you have a similar project structure:
--main
--java
--src
--resources
--images
--cards
back.png
--players
player1.png
you can set images from resources in your java-code. But you need to use getResources()
For example:
#FXML
private ImageView imageView;
Image image = new Image(getClass().getResourceAsStream("/images/players/player1.png"));
imageView = new ImageView(image);
Of course directory "resources: shuild be marked as resources root

Unable to load an image in sub folder present in the working directory- Google maps marker icon

A simple issue but unable to find a solution.
I have some image files that I placed in a subfolder called icons in my working directory in my ASP.NET website. I want to set an image during initialization to the markers on my Google map. But this isn't working. I have tried-
var marker= new google.maps.Marker({icon:'E:\cdeez\Sites\googletest 5\icons\busballon.png', position:pos,map:map});
It gives an error:
Not allowed to load local resource: file:///E:/cdeezSitesgoogletest%205icons%08usballon.png
However there is no problem if I place the image in the working directory. I guess giving the absolute path is not the right way too. So what is the right way in the above case.(Just a reminder- the above code will be in the aspx file).
According to the MarkerOptions docs, the icon should be a URL. However local files (embedded with file:///) tend to be ignored by browsers if the website is served over http - and I think that is what is happening in your case.
I would suggest to try out the following steps:
try using a relative path, e.g icon: "/icons/busballon.png"
try using a http path to your file, e.g. icon: "http://yoursite.com/icons/busballon.png"

After exporting a flex project, the images are broken

After completing building a flex project in Flash Builder 4.5, the project was exported using the
File -> Export Flash Builder Project.
After which some of the images stopped working (get the broken image icon). This has left me clueless and even search on the internet did not give me good answers...
I get the same problem time to time. Probably compiler / Flash Builder bug. But to be sure, you might want to check some basic things. First off: check that you have correct image urls. Secondly, ensure you are not using absolute source paths (e.g. C:\workspace\project\src\assets\images\image.png). Instead use relative path (i.e. assets\images\image.png).
If these are correct, check your build directory (default build directory for release builds in FB is bin-release) and see if the images are compiled there correctly. As I said, for some reason my FB does not always compile all the assets correctly, so sometimes I have to move them in manually. That is, you can simply drag and drop them from the source directory to the bin-release directory (although if you are using svn, you should be careful with this as it might copy also the svn metadata).
Other solutions you might want to try:
restart eclipse / FB (maybe it's simply out of memory)
delete the project from your workspace and import it again with no project information
change workspace and import the project there
I finally found the answer... made all the images bindable and just used the class to tag the images.
for example... instead of
if (draggedImage.id == "Chris" )
{
newImage.source = "assets/Chris.png";
}
changed it to
if (draggedImage.id == "Chris" )
{
newImage.source = pic3_icon;
}

How do I rotate an Image in .NET?

I have an asp.net 2010 project. I write a jpg to the filesystem. Then I display it in an Image control. Then I use this code on button click to allow the user to rotate it 90 degrees.
string path = Server.MapPath(Image1.ImageUrl) ;
// creating image from the image url
System.Drawing.Image i = System.Drawing.Image.FromFile(path);
// rotate Image 90' Degree
i.RotateFlip(RotateFlipType.Rotate90FlipXY);
// save it to its actual path
i.Save(path);
// release Image File
i.Dispose();
It does rotate (I can actually watch that happen in Windows Explorer). But when I run the app again and it grabs the file from its path, it still displays it in its original form.
Try adding a dummy querystring to the end of the image like "image1.jpv?v=1". This works to prevent caching for things like Javascript files and it may do the same for you.
This is the classic issue with browser-cached resource files. Alison's answer is one option. Another option is to change the name of the physical file. If you "version" the files, then after each change, the file name will be different. This does mean that you'll have to dynamically reference the image path so that you display the correct version, and you'll need some way to determine the file name for the current version. It does prevent the browser from displaying the previously cached file immediately after a change, though, because it's technically a new file to the browser at that point.
If you are using some sort of data source (XML files or database) to store metadata for the images, then you can add a "Version" column and store a simple integer. With each change, increment the integer value and use the new value in the file name. You can even extend this by saving the previous versions and allowing your users to "undo" actions by copying an older version of the file into a new version. This might require a more robust metadata storage implementation, though.

Flex ItemRenderer Images not appearing at runtime

in datagrid I have an ItemRenderer (which extends UIComponent) which loads images based on a data value, eg:
_img.source = "assets/images/flags/" + value[dglistData.dataField] + ".gif";
When I run my application the images (flags) are appearing in the ItemRenderer. When I build and deploy the application into BlazeDS as an SWF file - the images do not appear. Instead there is the standard "missing icon" link that appears in Internet explorer.
As far as I can tell, my ANT build script includes the above directory "assets/images/flags/" and all the images into the SWF file.
Is this a relative path issue? Not sure, any help would be appreaciated.
Thanks
Mike
When you are assigning a path as source Flash Player is trying to load the images via HTTP requests. Therefore, embedding your images in the SWF has no effect.
There are two possible solutions. Either deploy the folder containing your images to the server and use the corresponding path as your source or embed all your images into the SWF.
A simple example for the second solution. The code assumes that value[dglistData.dataField] corresponds to one of the variables with the [Embed] metadata.
[Embed(source='assets/images/flags/Image1.png')]
private var image1:Class;
[Embed(source='assets/images/flags/Image2.png')]
private var image2:Class;
[Embed(source='assets/images/flags/Image3.png')]
private var image3:Class;
// access the image like this...
_img.source = this[value[dglistData.dataField]];

Resources