SVG Path to Polygon/Array of Points/Absolute coordinates - android

In my app, I get a really long SVG path as a string. I need to convert this path to polygon or array of points (absolute coordinates).
All solutions I have found so far are based on Batik (I cannot use this in Android Studio), SVGPathElement (awt.svg also not applicable in android) or JavaScript libraries (Raphael etc.).
So my question is, is there any other possibility to use a function like getPointAtLength(x) to sample the path, or do I have to write programmatically a parser? I have searched for hours to find an answer, unfortunately unsuccessful.
Thank you in advance!
Solution:
path = createPathFromPathData(String pathStr)
path.approximate(error);
returns an array of absolute points

Related

android kitkat Uri to absolute path/input stream

I have tried various methods to extract the absolute path of an image from a Uri. I have checked out google and found a snippet but that does not quite work. It returns a weird address to my file, logcat says file not found.
I would be glad if anyone could share a proper method or snippet that helps me get the actual address of the Uri/ selected Image.
I have tried various methods to extract the absolute path of an image from a Uri
A Uri is not necessarily a file, and so there is not necessarily an absolute path to an image.
I would be glad if anyone could share a proper method or snippet that helps me get the actual address of the Uri/ selected Image.
You don't. You use ContentResolver to access the file contents (openInputStream()), get the MIME type (getType()), etc.

count how many pictures in drawable directory android project

I need help to count how many pictures in drawable with criteria substring filename? like how many pictures with filename starting "SC" ?
You can use reflection for that. Simply use getDeclaredFields() to get all fields of R.drawable.class. Then, just loop through them, look for the search term in the field names and get the drawable using Resources.getDrawable(Field.getInt());.
Well,
I haven't tried it but you can use getFields() to get all the variables
R.drawable.class.getFields()
Then you can perform your search for specific file name accordingly.
See this to know more for Reflections in Java: http://www.ibm.com/developerworks/library/j-dyn0603/

Find Closest Value in an XML file within a Android App

What I have been trying to do, is to use a XML file to access a array of data that I wish to have stored on the web. The file looks like this:
<resources>
<60020> 13.5 </60020>
<50020> 11.2 </50020>
</resources>
The program grabs the user's GPS coordinates and then geocodes them to a zip code, that part I have down. What I wished to do after that, was to compare that zip code to the zip codes in the XML file and then return a integer based on the closest zip code. For instance, if the user has zip code 60013, then the program would see that 60020 is the closest zip code, and then return 13.5 based on that search.
I have already tried making a SAXParser, and I can return the first value, however, I cannot how to force the SAXParser to read through the whole document to find the nearest value. I also already have a algorithm to find the nearest value (simple for loop checking for difference in values), but again, I am stuck on the whole idea of how to check the whole list of values. Am I using the wrong type of storage method? Should I be using SQL? Or a different parser?
Thanks for your help.
I better idea would be to round off the zip code first and then search it in the XML file.
I would recommend Xpath Api for querying the XML file.
I very good tutorial about Xpath can be found here
http://www.ibm.com/developerworks/library/x-javaxpathapi/index.html
and as SAXparser itself will look for tags, it won't roundoff them, allover XPath is more prefered for searching XML documents, as it is relatively easy.

Custom Dictionary for Tesseract

I am currently working on a project for android using Tesseract OCR. I was hoping to fine-tune the results given to the user by adding a dictionary. According to tesseract OCR wiki, the best way to go about this would be to
Replace tessdata/eng.user-words with your own word list, in the same
format - UTF8 text, one word per line.
However there is no eng.user-words file in the tessdata folder, I assume that if I just make a text file with my dictionary in it, it will never be used...
Has anybody had a similar experience and knows what to do?
If you're using tesseract 3 (which I assume you are).
You'll have to rebuild your eng.trainddata file.
I intended to replace the word-dawg file completely to try to get better results (ie - the words I'm detecting are always the same).
You'll need combine_tessdata and wordlist2dawg executables in the training directory when you compile tesseract.
unpack everything (i did this just to back up my eng.word-dawg, you'll also need the unicharset later)
./combine_tessdata -u eng.traineddata
create a textfile of your wordlist (wordlistfile)
create a eng.word-dawg
./wordlist2dawg wordlistfile eng.word-dawg traineddat_backup/.unicharset
replace the word-dawg file
./combine_tessdata -o eng.traineddata eng.word-dawg
that should be it.

Sorting Images on Android

I need images to be sorted by folders. like drawable/Photos, drawable/items, drawable/photos. and put each folder to the registry or at least find way to get them out of there. all I want is something close to php like "../img/photos/photo0.jpg". is there way to do something like this. and folder with Images must contain in apk file.
possible solutions is make link in the R file but I didn't find how to do it, other solution is find command with logic like I will show you here:
ImageView img = (ImageView)CloningTable.findViewById(R.id.img);
String ImgPath = "com.test.test/img/img0.jpg";
img.setImageDrawable(Drawable.createFromPath(ImgPath));
OR
ImageView img = (ImageView)CloningTable.findViewById(R.id.img);
String ImgPath = "com.test.test/img/img0.jpg";
img.setImageResource(ImgPath);
please say me the best way to handle it. AND specify if it contain path how I can know path the file lies in.
File ImgFile = new File("test/test.jpg");
TextView testtext = (TextView)CloningTable.findViewById(R.id.testtext);
if (ImgFile.exists()) {
test.setImageBitmap(BitmapFactory.decodeFile(ImgFile.getPath()));
testtext.setText("asdasuidjasdk");
}
can any one say Why programm can't find file and file exist 100% = /?
filepath: Project> assets/test/test.jpg
found solution: Android Show image by path
It's hard to understand why you need to sort resources that will be static in your APK, but you should not access them directly using paths, but using the API for that purpose.
Take a look at the topics in the dev guide here:
http://developer.android.com/guide/topics/resources/accessing-resources.html
http://developer.android.com/guide/topics/resources/drawable-resource.html
Those will teach you how to access the resources. To create Bitmaps from them, the easiest way is to use the BitmapFactory class
Remember, you know which resources the APK has at building time, so you can work around it. If you want to work with Bitmaps created at runtime, then use the data storage methods instead.
In this case, you should put resources in assets folder, and you can access them by path!
So if you want to save the path string, the best way is creating a class, with 2 variants: 1 Bitmap to store data, and 1 String to store the path.
If not, just create a String array that you may access when you want.
In both case, you need to put the path into the Path String storage before you load the image.
Hope I understood your question.
EDIT: Final answer that meet your requirement:
There's no path for drawable, they are all converted into ID. If you put in asset folder, just call it by their name. For example, you have "Test.bmp" in asset folder, its path is "Test.bmp". If you have "SubTest.bmp" in "TestFolder" in asset folder, its path is "TestFolder/SubTest.bmp". Sorry for long time, I had to sleep, it was mid night at my time zone.

Categories

Resources