31

I have an external library that relies on the java.awt.Image package. However, the Android library does not contain it. Does anybody know how to add it to Android? Thanks!

rgettman
  • 176,041
  • 30
  • 275
  • 357
wzb5210
  • 735
  • 2
  • 9
  • 16
  • Android has its own image routines (in `android.graphics`) which are somewhat more efficient on hardware with limited resources. Please explain what you want to do with `java.awt.image`, as it may already be available, and you're just not familiar with where it is in the inbuilt libraries. – Mark Allison Jun 14 '11 at 14:00
  • Can you post the import code you're using? – Tom O Jun 14 '11 at 14:03
  • @Mark Allison: I am using ImageJ library, which basically relies on the java.awt.image package. Since Android does not have this package, so I can not use the ImageJ library. The ImageJ library is very powerful and has a lot of image processing operations I need. – wzb5210 Jun 14 '11 at 14:14
  • @Thomas Owers: import ij.IJ; import ij.io.Opener; import ij.ImagePlus; import ij.ImageJ; just import an external library, but it relies on java.awt.image package – wzb5210 Jun 14 '11 at 14:16
  • have you not tried import java.awt.Image; ? – Tom O Jun 14 '11 at 14:20
  • @Thomas Owers: Yes, I have. But you know I can not import it because Android library does not have it – wzb5210 Jun 14 '11 at 14:22

4 Answers4

18

The Java AWT classes contain native code, so unless someone ports that native code to Android, you are out of luck. And, they won't port it, because as it was pointed out above, Android has its own graphics libraries (android.graphics).

miller
  • 1,636
  • 3
  • 26
  • 55
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • If so, I guess I can not use the existing image processing library. – wzb5210 Jun 14 '11 at 15:39
  • 1
    Right, you are not going to be able to use ImageJ. What is it that it does that you need to do in your app? There is a very good chance that there is an existing Android API that covers your use cases. – michaelg Jun 14 '11 at 23:34
  • @michaelg I need to implement SIFT algorithm in Android. There is an implemented sift in java which is a plugin of ImageJ. That's why I want to use ImageJ. What Android API do you suggest for my app? – wzb5210 Jun 15 '11 at 02:49
4

Use JavaCV. http://code.google.com/p/javacv/ Its allready precompiled for Android 2.2 : http://code.google.com/p/javacv/downloads/list

Shorty123
  • 539
  • 1
  • 7
  • 26
0

This answer is to justify Hitesh answer after seeing up votes (which misleads). If am wrong, please correct me.

Well, I have also been enthusiast in using few core concepts of Java like Swings and AWT libraries in Android.

Recently I wanted to use java.awt.Color class because it is much better than android.graphics.Color. So done a small research by reading few threads and concluded as 'No we cannot import'. By seeing Hitesh answer I thought I failed my research and found very easiest solution for my problem. Followed the steps for a sample and run my code. Alas!!!

NoClassDefFoundError exception has thrown.

Once again made a small research for concluding Jeffrey (accepted) answer. I found conclusion here. The comment above the method loadLibraries() explains everything. This method has been called in Color class (line 279).

Aswin
  • 1,154
  • 1
  • 11
  • 29
-4

https://stackoverflow.com/a/33210293/5418475

The AWT package is not supported in Android, you need to change your implementation to use the Android classes.

See these similar questions:

Porting AWT graphics code to Android

How to add java AWT image package in Android

Using AWT with Android

Community
  • 1
  • 1