Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old October 12th, 2011, 09:01 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2011
Posts: 6
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Question 2d image app

Hi everibody! I have to create an app that draws a map reading data from a text file : for example the text file can be like

. index x y orientation
vertex 1 0 0 0
vertex 2 5 0 0.5
vertex 3 10 2 0.3

so i need to do in java something like fscanf does in c (fscanf scans the text file for known formatted data... example, in the file i written i know each line has a string float float float and i need to put them into a specific data structure that can be a list of elements "vertex"

next, when i have all the data, draw a simple image rappresenting the data..

my questions are...
there is a function like fscanf?

and then.. what's better for drawing the 2d map? i have tu use Opengl? At the end i have to draw the image pixel by pixel.. i hope there is something easier then openGL

alexenduro is offline  
Reply With Quote
sponsored links
Old October 12th, 2011, 10:31 AM   #2 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

You need to use an input stream. There are various options here, but the one I would use is a DataInputStream.
jonbonazza is offline  
Reply With Quote
Old October 12th, 2011, 10:49 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2011
Posts: 6
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot Jonbonazza! It seems perfect ! And about the drawing, ideas?
alexenduro is offline  
Reply With Quote
Old October 13th, 2011, 05:32 AM   #4 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2011
Posts: 6
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default strings

Quote:
Originally Posted by jonbonazza View Post
You need to use an input stream. There are various options here, but the one I would use is a DataInputStream.
today i was trying to use that but i have got some problems to read string with datainputsream.. how can i do if the file its like

newyork 1 2
rome 5 7

so I know each line begins with a string but i dont know how long it is and i need to put the names in a String value?In c its easy, i simply put something like fscanf(file,"%s %d %d\n",name,x,y); and %s gets the string, no matter how long it is..

Thanks for help!
alexenduro is offline  
Reply With Quote
Old October 13th, 2011, 10:46 AM   #5 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

It doesn't matter how long it is. to read the first line of the above text, you would do this:
Code:
DataInputStream dis = new DataInputStream(new FileInputStream(new File(filename)));
String city = dis.readUTF();
int param1 = dis.readInt();
int param2 = dis.readInt();
It will automatically read in the proper number of bytes and convert it to the proper datatype.

EDIT: Actually, I made a mistake. DataInputStream reads and writes binary files. If you want to read a text file, you will want to just use a FileInputStream.
jonbonazza is offline  
Last edited by jonbonazza; October 13th, 2011 at 10:49 AM.
Reply With Quote
Reply
Tags
2d image, android, draw, file, fscanf, image, java, map, opengl, read


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:43 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.