Solved>bitmap image from file

Software: Away3D 4.x

charlito, Jr. Member
Posted: 25 April 2012 02:10 AM   Total Posts: 36

Hi everyone.

im still learning about this framework,  and while i was doing some test, i got into a problem

i have an xml file, wich i load into my aplication, then i get an array,  with the address of some images. (img/file1.jpg,img/file2.jpg.. etc)

once the images are loaded (with event.complete listener), i wanna create a plane and add this image to this plane.. but nothing i do seams to work out.

my code is:

var my_loader:Loader = new Loader();
my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,createPlane)
var 
fileRequest:URLRequest = new URLRequest(aDirArchivo[n]);//addres of imagen
my_loader.load(fileRequest);
}

//then in  createplane function

public function createPlane(e:Event):void
{
var oPlane:PlaneGeometry = new PlaneGeometry(256,256,1,1,false);
var 
omPlane:BitmapTexture;
var 
tPlane:TextureMaterial;

// i cant have the clasicc
//omPlane = new BitmapTexture(new class().bitmapData);
//so this line, i dont know how it so create this objec material..

omPlane = new BitmapTexture( ???.bitmapData);

//:( 

any ideas??

thx a lot

   

Waffles, Newbie
Posted: 25 April 2012 09:27 PM   Total Posts: 3   [ # 1 ]

Here’s one way to handle it.

var nMaterial:TextureMaterial = new TextureMaterial( new BitmapTextureBitmapmy_loader.content ).bitmapData ) );

var 
oPlane:PlaneGeometry = new PlaneGeometry25625611false );
var 
oPlaneMesh:Mesh = new MeshoPlanenMaterial ); 

You can also do this to get the BitmapData, which is good if you need to resize or modify the incoming image.

var nBMP_D:BitmapData = new BitmapData256256false0x00000000 );

var 
nSprt:Sprite = new Sprite();
nSprt.addChildmy_loader );
// resize, enhance, whatever +++
nBMP_D.drawnSprt );

var 
nMaterial:TextureMaterial = new TextureMaterial( new BitmapTexturenBMP_D ) ); 

Anyways, hopefully that helps and hopefully I didn’t just have a brain-fart and put up gibberish, because I forgot something…

   

charlito, Jr. Member
Posted: 26 April 2012 02:33 AM   Total Posts: 36   [ # 2 ]

hi.

dude.. thx a lot.. u solve me my problem and also help me to understan a few more things..

i couldnt make ur firs solution to work.. i think it was me who didnt know how to apply correctly..

but ur second solution, solve my problem and it helped me to understand a few things..

thx a lot.

smile

   

Karim Beyrouti, Administrator
Posted: 26 April 2012 11:19 AM   Total Posts: 30   [ # 3 ]

You can also use the inbuilt AssetLibrary to load your textures,
which is probably good practise. Here is an example:

private var textureURL String 'texture.png';
private var 
textureMat TextureMaterial = new TextureMaterial();

public function 
loadMaps() : void {

 
var loadToken AssetLoaderToken AssetLibrary.load( new URLRequesttextureURL ) );
 
loadToken.addEventListener(AssetEvent.ASSET_COMPLETEonAssetLoadComplete );

}

private function onAssetLoadComplete(event AssetEvent) : void {

 
var bmd BitmapTexture

 
switch ( event.asset.name {
       
  
case textureURL:
    
   
bmd AssetLibrary.getAssetevent.asset.name ) as BitmapTexture;
   
textureMat.texture bmd;
       
   break;

 
}

   

fcimage, Newbie
Posted: 17 June 2013 09:40 AM   Total Posts: 2   [ # 4 ]

after loading bitmap image vb, you can get the bitmapdata, and then you can process images:reszie scale and crop by using the codes above.

   

hjimage, Newbie
Posted: 22 April 2014 07:38 AM   Total Posts: 4   [ # 5 ]
fcimage - 17 June 2013 09:40 AM

after loading bitmap image vb, you can get the bitmapdata, and then you can process images:reszie scale and crop by using the codes above.

as i can see, this is vb.net method to load image from file, i am a C# expert, so can you provide some c# sample codes for loading image from file.
thanks.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X