xamarin.forms set backgroundimage for page from file in android - xamarin.forms

I have an Image file that i create during runtime.
I want to set it as backgroundImage of a ContentPage (in android project)
I tried to set the path of the file to the BackgroundImage property but it doesn't work.
Is there a way to do it ?
I can't put it as resource since I create it at runtime

Put your page into Grid which first element is an Image, then set that image Source to your stream like:
Image bgImage = new Image
{
Source = ImageSource.FromStream(() => { return new MemoryStream(buffer); });
}
Grid mainGrid = new Grid
{
Children = {bgImage,yourContent}
};
yourPage.Content= mainGrid;

I think that documentation is out of date. Becuase target Android has more than one resources.
as
/drawable-hdpi
/drawable-xhdpi
etc.
So you should add your images for all folders because it will work device. It Works.
*but I think that main issue on Xamarin.Forms
Becase drawable folder have to default images source when system couldn't find special resolution must select from default folder... *

Related

How to dynamically render images in react native from file paths

I am having trouble loading images dynamically in React Native in which the file path is stored in an sqlite database.
Consider 3 buttons: "Show image1", "Show image2", "Show image3"
I could simply use
source={require("./assets/image1.png")}
to load image 1. I could use a require switch statement on all three images to return the require I need depending on the button pressed.
However, I do not know the paths before the application is loaded. I need to retrieve them from the database and cannot do:
var image = imagePathFromDB;
require(image)
The offline database pulls user specified images from an online database from which there can be a very large variation of images so specifying all possible paths ahead of time is not possible.
The application is being developed to work for both Android and iOS.
2 Questions:
Where is an appropriate place to store the image files
..and more importantly
How do I retrieve and render them dynamically?
in React native ,all your images sources needs to be loaded before compiling your bundle.
you can use dynamic images by using switch case
Like
class App extends Component {
state = { avatar: "" }
get avatarImage() {
switch (this.state.avatar) {
case "car":
return require('./car.png');
case "bike":
return require('./bike.png');
case "bus":
return require('./bus.png');
default:
return require('./defualt.png');
}
}
render() {
return <Image source={this.avatarImage} />
}
}
place your images in case and then store only case value for specific output

Uploading and image dynamically at runtime in Flex 4.5

I am building a form builder in Flex 4.5. For that I need help regarding uploading image at runtime such that any user can just simply place cursor on particular location on image and is able to upload any image from the local file system.
Maybe try using native extension or native process. But this is only possible with AIR.
Here is a simple example:
http://thanksmister.com/2011/03/16/upload-s3-curl-air-nativeprocess/
I hope this helps :)
Could you describe more what you are trying to do?
It's fairly simple
private function browseForFile():void
{
fr = new FileReference();
fr.addEventListener(Event.SELECT,handleBrowseForFileSelected);
fr.browse([]);
}
protected function handleBrowseForFileSelected(event:Event):void
{
fr.removeEventListener(Event.SELECT,handleBrowseForFileSelected);
fr.upload( ...)
}
in fr.upload fill the parameters as you need, basically a URLRequest to which you will upload the file to.

ActionScript 3 - a loader that supports many apps?

I have created a simple SWF-loader in ActionScript 3.0. It loads an SWF from a server and then plays it. While downloading, it displays the "loading" screen.
Its main defect is that it can load only one Flash application - the one which it is compiled for. Let's say it's named test1.swf.
Is there any way to make the loader support more than one Flash app (for example test2.swf and test3.swf)? I mean by passing external parameters to it and not by creating another loader. Is using Javascript the only way to do it? I don't want my loader to require the Javascript support.
And I really don't want to create separate loaders for all of my apps...
Thanks in advance.
In order to load an external SWF your loader only need the url of the swf to be loaded, this url doesn't have to be hardcoded. There are many ways to pass parameters to a SWF file and they don't necessarily require Javascript.
You could load a XML file for instance, a simple text file would work too , you could also use a PHP script. Using flahsvars would require Javascript, although only to set your application in your HTML page.
With the following example , your app doesn't need to recompile , you simply change the url in the text file.
Example with a text file containing a url, something like this:
http://yourwebsite.com/test1.swf
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE , completeHandler );
urlLoader.load( new URLRequest('swfURL.txt') );
function completeHandler(event:Event):void
{
loadExternalSWF(event.target.data );
event.target.removeEventListener(Event.COMPLETE , completeHandler );
}
function loadExternalSWF(url:String ):void
{
//your code here , using the url value
trace(url );//should return your text file content
}

tree view properties in web application

i open a web application in visual studio 2008...
it contain the tree view properties as,
TreeNodeType type;
type = new TreeNodeType();
type.Type = "folder";
type.ImageUrl = "Images/" + "folder.gif";
type.ExpandedImageUrl = "Images/" + "folderopen.gif";
i dont know how this image tag comes.. and how to chage that...
If your image directory is in the root of the application you should use the tilde character '~' at the start:
type.ImageUrl = "~/Images/" + "folder.gif";
you should include the full path to the image from the root, so if the image is in Content/Images:
type.ImageUrl = "~/Content/Images/" + "folder.gif";
At runtime, the '~/' is translated to the correct path to the image and rendered to the page.
If this is not working, you need to post the relevant markup of the page and the codebehind. Alos, it would help if you rightclick the image in IE and slect properties. You can see the expected path there. Or open the page in Firefox, with the Firebug Addon installed, right click the image and select Inspect Element. This will show you the path that was rendered and you can compare this to where the image actually is in your project.

Programmatically load images in Flex

I need to load several images as Bitmap or BitmapData objects. The images are hosted outside the Flex project, and they're referenced by an external configuration file, so I can't embed them. Because the images won't be displayed directly to the user (they're being added to a PDF that is generated for download), creating a grouping of Image objects, attaching them to the application, and waiting for their LoadComplete handler to fire seems inefficient.
What is the best way to load these images into an application?
Have you considered using Loader class?
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
ldr.load(new URLRequest("image.png"));
function onLoad(e:Event):void
{
var image:Bitmap = Bitmap(LoaderInfo(e.target).content);
var bmpData:BitmapData = image.bitmapData;
//use bmpdata the way you want
trace(bmpdata.width);
trace(bmpdata.height);
}

Resources