Error Image Loading as stream

Put your problem here if it does not fit any of the other categories.

Error Image Loading as stream

Postby Rizwan » Sun Dec 16, 2007 6:39 pm

Hi!
I have tried lots of method of loading image file as stream but nothing
works for me like
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. String path = "src/com/kudcs/MyImage/myimage.jpg" ;
  3.  
  4. InputStream is = this.getClass().getResourceAsStream(path) ;
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


also try context.getResource().getraw Method ;
nothing works for me . all return null .

what 's the problem ? any method of reading image files as stream in
Android. Looking forward for your replies . I m trying to load Images from hard drive or from inside resource folder of Android application directory . looking forward for your replies

Regards
Rizwan
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Top

Postby plusminus » Sun Dec 16, 2007 7:18 pm

Hello Rizwan,

have you tried the following :?:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. FileInputStream android.app.ApplicationContext.openFileInput(String name) throws FileNotFoundException
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Where exactly is the file located you are trying to load :?:
  1. Desktop-PC-HDD
  2. Within the Android-Project
  3. On the Emulator-HDD

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Rizwan » Sun Dec 16, 2007 7:55 pm

I m trying to load image file from Android 's project . what will be the path string ?
say if a file is located in res folder of the project .

Thanks .
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Postby plusminus » Sun Dec 16, 2007 8:11 pm

Hello Rizwan,

Is it this, what you need :?:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.getResources().openRawResource(int id);
  2.  
  3. // Uses like:
  4.  
  5. this.getResources().openRawResource(R.drawable.myImage);
Parsed in 0.052 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Rizwan » Sun Dec 16, 2007 8:48 pm

I have use this method
this.getResources().openRawResource(R.drawable.myImage);

I got the exception Resource not found but I did place the Image file in drawable file and eclipse recognize it . it does not red highlight it . but still not working please help me . I have my hours in this issue , this is really simple in J2me why it's not working in Android . Looking forward for your reply.

Thanks ,
Rizwan
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Postby Rizwan » Sun Dec 16, 2007 8:51 pm

I have read about raw folder in
http://code.google.com/android/devel/re ... rcesInCode

about the raw folder but eclipse is not recoginizing

R.raw.ID

what 's missing ?
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Top

Postby plusminus » Sun Dec 16, 2007 9:25 pm

Hello Rizwan,

put the image you want to load to the following folder:
"/res/raw/myImage.png"

Then access it with the following code (I'm doing this to a mp3-File):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. InputStream in = this.getResources().openRawResource(R.raw.everlast);
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


With me in is not null, it is:
Code: Select all
in:   AssetManager$AssetInputStream  (id=830003249256)


This works ;) :!:

Regards
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Rizwan » Mon Dec 17, 2007 3:38 pm

Thanks ! it works . great Indeed No 1 site for Android developer . :)

Thank you very much .
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Image bytes into Inputstream

Postby zeeshan » Mon Mar 17, 2008 9:26 am

I want to show image on my listview i have image bytes .how can i get input stream from bytes???
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Re: Error Image Loading as stream

Postby laksmi07 » Thu Dec 17, 2009 7:36 am

Rizwan wrote:Hi!
I have tried lots of method of loading image file as stream but nothing
works for me like
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String path = "src/com/kudcs/MyImage/myimage.jpg" ;
  2. InputStream is = this.getClass().getResourceAsStream(path) ;
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


also try context.getResource().getraw Method ;
nothing works for me . all return null .

what 's the problem ? any method of reading image files as stream in
Android. Looking forward for your replies . I m trying to load Images from hard drive or from inside resource folder of Android application directory . looking forward for your replies

Regards
Rizwan


how should i give the path if the image is in drawable folder of the project. And i dont want to initialize it through R.id.image? I get is as null if i try using the above code
laksmi07
Freshman
Freshman
 
Posts: 2
Joined: Thu Nov 26, 2009 10:04 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 23 guests