适用于 Android 和 Java 的图像处理库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6682878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:55:00  来源:igfitidea点击:

Image processing library for Android and Java

javaandroidimageresize

提问by Octoate

I am currently working on a small project, which shall load an image from an URL, resize and change it's colour depth to only 16 colours using a specified colour palette. The main problem for me is, that I want a program, which I can use on an Android device and on a desktop computer. Do you know a good image processing library which works on both systems?

我目前正在做一个小项目,该项目将从 URL 加载图像,使用指定的调色板调整大小并将其颜色深度更改为仅 16 种颜色。我的主要问题是,我想要一个程序,我可以在 Android 设备和台式计算机上使用它。您知道一个适用于两个系统的良好图像处理库吗?

Thanks in advance.

提前致谢。

采纳答案by Radim Burget

回答by Zhubarb

The answers on this page are quite dated as of February 2014. I was searching to find a free Android image processing libraryand I came across the Stanford lecture notes here: http://www.stanford.edu/class/ee368/Android/index.html

此页面上的答案截至 2014 年 2 月已过时。我正在寻找一个免费的 Android 图像处理库,我在这里看到了斯坦福大学的讲义:http: //www.stanford.edu/class/ee368/Android/索引.html

Investigating a bit further, I found out that they are using OpenCVin their course material. It has a Java interface (along with many other languages), but the library is written natively in C++. They state that:

进一步调查后,我发现他们在课程材料中使用了OpenCV。它有一个 Java 接口(以及许多其他语言),但该库是用 C++ 本地编写的。他们指出:

Along with well-established companies like Google, Yahoo, Microsoft, Intel, IBM, Sony, Honda, Toyota that employ the library, there are many startups such as Applied Minds, VideoSurf, and Zeitera, that make extensive use of OpenCV.

除了谷歌、雅虎、微软、英特尔、IBM、索尼、本田、丰田等使用该库的成熟公司外,还有许多初创公司,如 Applied Minds、VideoSurf 和 Zeitera,广泛使用 OpenCV。

I am excited(!) to have found this, looking forward to going home and giving it a go.

我很高兴(!)找到了这个,期待着回家试一试。

回答by James Lim

The Android NDKallows you to use an existing C/C++ library that does not require java.awt or any of the Android classes. For example, you could easily compile libpng as a shared library for Android and then write a JNI interface to pass images from the Java layer to the png library. Similarly, you will also be able to compile libpng as a shared library for your desktop computer and use it from there.

Android的NDK允许您使用不需要java.awt中或任何安卓类的现有的C / C ++库。例如,您可以轻松地将 libpng 编译为 Android 的共享库,然后编写一个 JNI 接口将图像从 Java 层传递到 png 库。同样,您也可以将 libpng 编译为台式计算机的共享库并从那里使用它。

I recently wrote a tutorialon how to compile open-source libraries for Android. If you browse the Android source, you will find some classes that use the skiagraphics library via jni. I have not used skia before, but since Android has skia in its base framework, it should not be too difficult to get it to work in your app/desktop program.

我最近写了一篇关于如何为 Android 编译开源库的教程。如果你浏览Android源码,你会发现一些通过jni使用skia图形库的类。我之前没有使用过skia,但是由于Android 在其基础框架中具有skia,因此让它在您的应用程序/桌面程序中工作应该不会太困难。

Writing cross-platform programs has been an area of active interest amongst the mobile developers community, and some engines such as libgdxhave gotten really good at it. So what you are attempting is definitely possible.

编写跨平台程序一直是移动开发者社区的一个积极兴趣领域,一些引擎(例如libgdx)已经非常擅长于此。所以你正在尝试的东西绝对是可能的。

回答by Riyad Kalla

Octoate,

八角,

I don't think there is a library that exists that does what you want, the reason for that is on non-mobile platform every graphical operation you are going to use in Java is going to use the Java2D rendering pipeline to some degree. On Android, this doesn't exist.

我认为没有一个库可以满足您的需求,原因是在非移动平台上,您将在 Java 中使用的每个图形操作都将在某种程度上使用 Java2D 渲染管道。在Android上,这不存在。

Android provides its own graphical pipeline for image manipulation and actually simplifies a lot of things that are more complicated in standard Java.

Android 为图像处理提供了自己的图形管道,实际上简化了许多在标准 Java 中更为复杂的事情。

All that being said, it looks like you found a library (JJIL) that acts as an abstraction layer on top of these differences, in that case I would be a bit worried about performance and do some testing in your own code to see how it performs compared to the platform methods. For example, I saw this quote from JJIL:

综上所述,您似乎找到了一个库 (JJIL),它充当这些差异之上的抽象层,在这种情况下,我会有点担心性能并在您自己的代码中进行一些测试以了解它是如何实现的与平台方法相比执行。例如,我看到 JJIL 的这句话:

allows images to be converted from Android bitmaps into JJIL RgbImages

允许将图像从 Android 位图转换为 JJIL RgbImages

When I look at the source for RgbImages, it looks like the image data gets converted and stored in an internal array; all of those layers of abstraction are going to cost you CPU time and memory, especially as images on mobile devices get bigger due to higher resolution cameras and high-bandwidth connections.

当我查看RgbImages的源代码时,看起来图像数据被转换并存储在一个内部数组中;所有这些抽象层都会消耗您的 CPU 时间和内存,尤其是当移动设备上的图像由于更高分辨率的相机和高带宽连接而变得更大时。

This may not be that big of an issue, but again, you'll probably want to do some profiling/testing/performance comparisons.

这可能不是什么大问题,但同样,您可能需要进行一些分析/测试/性能比较。

回答by Barry Fruitman

Any pure Java library should work on both platforms. A Google search of "Java image processing library" produced several results. Try to find the lightest weight lib that serves your purposes since memory and CPU are limited on mobile devices.

任何纯 Java 库都应该在两个平台上工作。谷歌搜索“Java 图像处理库”产生了几个结果。由于移动设备上的内存和 CPU 有限,因此尝试找到最轻量级的库来满足您的需求。

Barry

巴里