A library to read .ico
/.cur
files in Java. Chingón.
The mejico
a small library to read Microsoft .ico
or .cur
format in java.
- a commercial-friendly license
- no dependencies on third-party libraries
- comprehensively unit tested
- fully compatible with .ico format
All versions should be supported. Hopefully. Please file a bug and help to improve this library
if you find an .ico
or .cur
file in the wild, which can be read by any version of Windows
and this library fails to do so.
I decided to stop publishing to Maven Central, coz it is annoying.
Simply snatch this from it from jitpack. Do not forget to select correct subproject in the dropdown menu!
Should this project find heavy use, I might consider publishing to Maven Central again.
This project is split into multiple subprojects. Your application should depend on one of the first two.
mejico-awt
- decoder which returnsjava.awt.image.BufferedImage
mejico-andorid
- decoder which returnsandroid.graphics.Bitmap
mejico-core
- core decoding routines, mostly coming fromimage4j
mejico-test
- utility classes for unit testing, not intended for public use
Loading of PNG data is delegated to native facilities. This is the main reason why we have
separate Android and AWT artifacts. You might want to depend on mejico-core
only, if you want
to supply your own PNG (or even BMP) decoder.
There are two classes with static factory methods to obtain an IconParser
, depending on the platform:
AwtMejico.getIconParser()
, returnsIconParser<BufferedImage>
AndroidMejico.getIconParser()
, returnsIconParser<Bitmap>
Check IconParser
to see the high level API. It can return a List
of images contained in .ico
file.
Lower level API is in the IconReader
class and allows to retrieve image metadata first (including the hotspot position for .cur
files) and decode
selected images afterwards.
// AWT example
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.deletethis.mejico.awt.AwtMejico;
class Main {
public static void main(String[] args) throws IOException {
InputStream stream = Main.class.getResourceAsStream("bundled_icon.ico");
List<BufferedImage> images = AwtMejico.getIconParser().getIcons(Main.class.getResourceAsStream("bundled_icon.ico"));
// do something with images
}
}
// Android example
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import android.graphics.Bitmap;
import android.app.Activity;
import android.os.Bundle;
import org.deletethis.mejico.android.AndroidMejico;
class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
InputStream stream = getResources().openRawResource(R.raw.resource_id);
List<Bitmap> images = AndroidMejico.getIconParser().getIcons(stream);
// do something with images
} catch(IOException ex) {
throw new IllegalStateException("Cannot open resource");
}
}
}
The mejico
library is licensed under the GNU LGPL v2.1 so you are free to use it in
your Free Software and Open Source projects, as well as commercial projects,
under the terms of the LGPL v2.1.
This is a fork of image4j. I changed the code beyond recognition, added a battery of unit tests, ditched many parts including encoding and general purpose BMP decoder.
I plan to maintain this library. More or less.
If you encounter bugs, please do not hesitate to report them.
- image4j
- The File Formats page at DaubNET for information on various image formats
- GIMP, which we use for editing images
To my or original author knowledge, there are no patents on either the BMP or ICO formats.