How to generate a PDF using android drawing commands? - android

I have an android program which draws lines and text to a canvas. (These are all vector drawing operations.) Does anyone have any advice for exporting that canvas to a PDF? I've looked into changing the Bitmap.CompressFormat that the canvas is based upon, hoping there'd be a PDF (or some sort of vector) format, but no luck there.
My goal is to output some sort of Vector file suitable for printing.
I'd appreciate any advice. Thanks!

There is nothing in Android for this. You can take a shot at seeing if somebody has a PDF library for Java (e.g., iText) working on Android, but these libraries may be large.
A better solution may be for you to save in something simpler (e.g., SVG, an XML format) and have your server convert that to PDF or anything else desired.

That was very long ago. If anybody happens to find this question nowadays, Android has it since KitKat: PrintedPdfDocument.

Related

How to reduce Android app size by compressing images?

I am developing an Android app which has hundreds of .jpg files (over 300) each one of around 40kB. I would like to know if there is a way of reducing the size of my app. I looked at a similar question here Reducing Android App Size, but the problem still exists. Is there perhaps a way to compress the images and decompress them in real time when needed, or any other way to make my app more space efficient while not sacrificing speed?
If you have used tinypng for every resource you did your best with this kind of solution. In general, it's better to use vector graphics where the general icon will be <1kb. Also, a vector resource can be animated. If it's quite simply bitmaps, you can generate them in code on demand. Also, you can divide your app by dynamic features and each will be downloaded on demand with their part of the resources.
Is there perhaps a way to compress the images and decompress them in real-time when needed?
There is no standard Android solution out of the box. Probably, you can write something on your own. But this looks like too much effort.
Still, the most practical solution: use vector graphics as max as possible, generate in code what you can generate, compress with tinypng the others. That should be enough or you should have a very good reason for making some extra work.
For more info about vector graphics in android. For standard vector graphic import right in the android studio.
Web-site where you can download icons and insert them into the project.

How to improve image quality for OCR reader in Android

I've made an app which uses the phone's camera to take a photo and then parses this photo (with Tesseract OCR) into a string.
The problem is that the string I obtain is very ugly, it contains wrong or unreadable characters.
I've read here that a filter to reduce image's noise may improve OCR's result. I've googled some of them and I've found this website which contains a lot of image filters written in Java. The issue is that they use BufferedImage class, which is not in Android SDK.
Does anyone know any other library which performs this operation in android?
You should use Bitmap. https://developer.android.com/reference/android/graphics/Bitmap.html
It's the equivalent (in theory, not in api) with BufferedImage.
Chek this post too:
How to load BufferedImage in android?

I have a map that's a vector image. Whats the best way of showing this in android?

I want to add a vector that's a map. I want to show this to the user, but I'm unsure of the best way to do this.
The only requirements I have are:
Show a vector
Start "zoomed" in (start at a specific point of the the map)
Work on 4.0 and up
I'm up for suggestion on which file type to use
Ah, that is definitely not how I interpreted "I don't want to specify one".
SVG is probably the lightest-weight solution. There are libraries that can display SVG in an ImageView as a Drawable, though these will only handle a subset of SVG. WebView on Android 3.0+ is supposed to be able to handle SVG files, though I haven't tried it.
Many, perhaps most, Android users have a PDF viewer, so if you're willing to open up a third-party app, you can do that easily enough. There are PDF libraries as well, though PDF is a more complex file format than is SVG, and therefore the libraries suffer.
I am not aware of any easy way to show an AI file directly, and those are the primary 2D vector formats in use today.

9-patch images in Android WebView

Do 9-patch images work inside an Android WebView? I haven't found anything that definitively answers it one way or another. I know there's a project that uses Javascript to mimic it on the web (https://github.com/chrislondon/9-Patch-Image-for-Websites), so I figure to use that as a workable alternative but wondered if anyone else had ideas.
I think it is feasible and there are several ways that we could have a try.
Do it in js/css. Just as you mentioned, there are several js plugin that support parsing 9patch. And css3 also has a new feature named border-image, which could achieve the same result.
Do it in android. If it is only used in android, we can use WebView.addJavascriptInterface() and enable js to invoke android code. When javascript want a image, it send the image uri and desired size of the image to android. Android try to load the image and use NinePatchDrawable to parse it. Convert it to a bitmap and return back.

Are there any other GIF creation libraries for Android?

I'd really love to know if there are better GIF file creation libraries for Android development. I've already tried this one as well an NDK based one called gifflen (it's really old apparently). Both I've found are slow and produce low colour amount GIFs with incredibly big inflated file sizes with quality settings that don't seem to do anything. Worst comes to worst I could just write the thing myself but it would save a lot of trouble if anyone knows of an existing one, thanks in advance.

Categories

Resources