Reading ICO file in android along with all sub-images - android

I have found Is there a way to decode a .ICO file to a resolution bigger than 16x16? from 2 years ago and the best suggestion was to use image4j. Unfortunately it does not work under android in particular (also), because the classes "IndexColorModel", "BufferedImage" and "WritableRaster" are not available.
While working around "BufferedImage" by replacing it with "Bitmap" may perhaps work and not using "WritableRaster", but instead setting individual (or a group of) pixels using setPixel may work as well, I cannot manage to replace "IndexColorModel", because I cannot wrap my head around it.
I am currently downloading a favicon from a website, which stores usually more than one image inside of it. The images are of different size. I read up on the structure of ICO files and analyzed image4j as much as I could. Yet I have troubles refactoring the various classes to not use AWT.
BitmapFactory is able to load ICO files; unfortunately it only loads the first image (this is my guess at least) and thus does not let me decide which image to load (let alone load them all and let me chose).
Does anyone know if anything changed from 2 years ago and/or would anyone be willing to help me refactor e.g. BMPDecoder from image4j? Or is there perhaps a totally different, easier approach to it?

I have created a library based on image4j that will allow reading ICO files into a List of Bitmap-objects. In contrast to image4j ico4a does not use any AWT-classes, but instead only makes use of Bitmap / Bitmap.createBitmap.
See https://github.com/divStar/ico4a .
While the library's performance might not be the best as it uses a Bitmap-object's setPixel method in a loop, it gets the work done and it's good enough for me.
In comparison to image4j my library (ico4a) only decodes/reads files. While saving ICO files could be done probably relatively easy, I have not done so since I do not need it myself.
If you have further questions or issues with the library, post them on gitHub and I will see if I can help.

Related

Best Tess-two configuration to get optimal recognition results?

I'm currently working on an android app utilizing the open source OCR library "Tesseract" to make an app for receipt recognition. I've gotten the library working with the "Tess-two" fork of Tesseract. The problem I'm having is that the recognition is very inconsistent. Even when provided with a good image that is cropped properly, the recognition isn't great. I'd say that when given what I would consider ideal situations, the recognition is about 90% accurate. When provided with any number sub-optimal conditions (dim lighting, blurry image, uncropped, etc...) I find that I'll often get virtually 0% accuracy.
For the purpose of my app, even 90% accuracy pretty much unacceptable, as I need to be able to get the exact information and numbers from the receipt "perfectly" without needing to worry about improperly read information.
So my question: what is the best way to configure Tess-two to get the highest accuracy possible?
In a nutshell, this is what I have done to set up the library:
//prior to running this code, I create the directory for /tessdata and copy my eng.traineddata file in there from the app's assets folder.
baseApi.setVariable("save_best_choices", "T");
baseApi = new TessBaseAPI();
baseApi.init(DATA_PATH, "eng");
baseApi.setVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$.!?/,+=-*\"'<:&"); //I was experimenting with this to try and improve accuracy, it didn't seem to help tremendously.
baseApi.setImage(photo);//photo is a bitmap that is selected from the phone's gallery.
String tmp = baseApi.getUTF8Text();
Is there something here that I'm doing wrong, or that I could be doing better?
Are there any files other than eng.traineddata that I should be including? I know there are multiple files for each language, but honestly I couldn't figure what was what, and what actually needed to be included. From what I could gather, I got the only file that was needed.
Are there any other settings that I could/should be modifying with the "setVariable" function?
Additionally, does Tess-two have any built in support for "deskewing" images, or adjusting contrast of provided images? I have not messed with either of these techniques much yet, but this would probably help out, right?
Any help is appreciated!
In case your android app should expect on dictionary words, then have a look at the Minimum Edit Distance algorithm and apply it on the results given by tesseract.

Android: How to load a vector drawable image into a webview?

Sorry if this is a repeat but I searched diligently and didn't find this question asked yet...
So back in ye olden days of Android, you could just add something like this to a WebView's source html:
<img src='file:///android_res/drawable/my.png'/>
And it would display my.png correctly in the WebView. But-- Android now supports (and prefers we use) these new-fangled vector drawables, and Android Studio's Vector Asset Studio makes it really easy to import them from SVG files or whatever.
The great thing is that for backwards compatibility, .pngs are automatically generated during the build for various dpi/screen sizes to support older devices. So if you're targeting an older device, there are .png images there.
If only I could reach them. Because, as far as I can tell, using vector graphics does break those file:///android_res/drawable/ img links in WebViews. Which is weird, because as I say there are .png files to see, if it only looked.
I've thought about a few methods to fix this, but none have worked:
Since .pngs are generated on-the-fly and are included in the .apk, I thought maybe I could point directly to one of the generated files with something like file:///android_res/drawable-hdpi-v4/my.png. (I checked the .apk file and that's where one of them was..) But no such luck there. Broken image.
Okay, I thought-- maybe there's a way to get the WebView to display the vector objects directly. That is, maybe the WebView would recognize an <img src="file:///android_res/drawable/my_image.xml"/> or something similar. I mean, Chrome can render svg right? Maybe it supports the .xml vector format too. But no dice here either. (Even if it had worked, it would be unlikely to support older pre-chromium webview versions.)
The third thing I tried is to include just one xxxhdpi-sized .png in res/drawable so that the webview would find it and hopefully display it. Unfortunately, this doesn't work either. It appears that just having an .xml vector in /drawable is enough to have it block the png, no matter if it's in the /drawable or /drawable-xxxhdpi directories.
So the obvious question: Is there a way to get the WebView to either display the vector xml (or the associated support .png that was generated)? How do we access drawables from HTML in a WebView w/Vector drawables? Esp. without having to do anything programmatically?
Anyone know how this is supposed to work? I guess the next thing to do is delve into the chromium/android source to try to find out how file:///android_res/drawable/ works, but that doesn't sound fun, so if anyone has an answer, that would be helpful.
I'm probably missing something really obvious here. Thx in advance!
Update: Other things I tried/ruled out include (1) removing underscores in image names (as I thought they might be replaced with "/"), (2) various permutations of baseurl in loadDataWithBaseUrl()
Well, four years later and the best solution I've come up with is just to have two vector files-- (1) the xml Android vector file for the app, and then (2) the identical image in the .svg format for the webview. This is still a smaller solution compared with providing a seperate .png or .gif for every dpi, etc.
SVG and the vector format are internally very similar, so it's not difficult to convert one to the other. In fact, Android Studio will convert SVG->XML. If you want to go the other way, just compare a few examples.
So just put your svgs in assets/svg/, and then you can access from a webview using <img src='file:///android_asset/svg/mysvg.svg'/> in your HTML.
There's still a storage hit. But svgs are relatively tiny (and you can minify-- ie, scoop out some of the extra fluff in the SVG file that isn't used by the webview) so it's not as bad as the alternative-- providing large binary image files in the apk.

How to convert psd to android xml file

How to convert psd image to xml code to reducing size of android application and work effectively and android xml design improve to application performance fast.
you can use these software for convert the psd to xml
http://www.psd2androidxml.com/
2nd is you can use the png file to drawable folder and use it
There are some ways to achieve this.
One way is to watch tutorials and learn how to do it by yourself.
The second way is to use some automated online tools, however they are not reliable, and you will have to correct the code manually.
The site that was mentioned by Nirav Shah, www.psd2androidxml.com, is a service, not a software. You send the PSD files to them, and they hand code them according to your specifications. It may cost more than the previous two solutions, but the result is better compared to automated online tools.

Diff between getExternalCacheDir vs getExternalFilesDir in android

I read the docs but I can't seem to figure out what the difference is. Is it something subtle that does not really matter? I want to create a cache of ten files. So when I went to use getExternalFilesDir, I noticed there is a getExternalCacheDir. So now I am confuse as to which one I should use (the name does not always tell the whole story). So can anyone put the difference in layman terms for me? thanks.
The ExternalFilesDir is not a cache, it will save your files, and they will remain there until the app is removed or the files manually whereas the cachedir will empty when needed
I'm a newbie to Android but would like to help you with the below link. The below article explores all possible ways / methods to use under different scenarios. It helped me in improving my understanding and hope the same with you and others as well
http://www.grokkingandroid.com/how-to-correctly-store-app-specific-files-in-android/

Android game Image format

I have a problem with an image for an android game. The problem is not a problem with the code because the code that I use I took from a book (Beginning Android 4 Games Developer).
The problem is this: I know the format that I have to use in android: png, but I don't know the settings for this format that I have to use (like RGB565...). Because if I use simply png, when I run the game the images are not good. So I need someone to explain to which settings I need to use for images for android games.
P.S The software that I used is photoshop. If there is better software for this purpose tell me.
I think there is a strong misconception in your understanding of Android and how it implements graphics. You are not constrained to .png for nearly any of your development. The .png and .9.png are only enforced strictly for managing drawable constants.
Android uses Java and has the capability to utilize nearly any graphical format. In particular native support for .bmp, .png, and .jpg are present for every device and Android OS version. You may even create your graphics in realtime byte by byte.
As for a good image editor, there are a number out there. I often use a combination of GIMP and Photoshop, myself.
Hope this helps,
FuzzicalLogic

Categories

Resources