Chat on IRC |
Java and BMP
Posted by regretfuldaydreamer [send private reply] at September 25, 2002, 12:23:00 PM
Does anyone know how to get a .bmp file(Windows Format) and input it into an image object. And then to output it as a file?
Lame question, I know, but I need an answer quickly and for the past two days, Google hasn't been very helpful.
Posted by Neumann [send private reply] at September 25, 2002, 12:35:03 PM
Don't use .BMP. It's makes uselessly huge file. Convert your image to GIF (or perhaps PNG) and then you'll have more success on Google.
Posted by regretfuldaydreamer [send private reply] at September 25, 2002, 01:25:39 PM
GIF/PNg aren't lossless. Besides size doesn't matter since its only to input images to test algorithms on. I don't care about size of file / speed.
Posted by Neumann [send private reply] at September 25, 2002, 01:38:29 PM
I'm pretty sure you can do 100% quality GIF/PNG...
Posted by CViper [send private reply] at September 25, 2002, 03:08:43 PM
Don't know about java's image objects, but the headers you're looking for are BITMAPFILEHEADER and BITMAPINFOHEADER.
The msdn has some decent docs on it; if you want i can send some c/c++ source for you to browse. It includes both reading from and writing to disk.
Posted by Neumann [send private reply] at September 25, 2002, 03:13:17 PM
Here we go... after a quick look on Google groups, here is what I found:
My open source ImageJ package at http://rsb.info.nih.gov/ij/ includes a class (ij/plugin/BMP.java) that loads BMP files. In addition, the free Jimi library at http://java.sun.com/products/jimi/ can both load and save BMP files. -wayne I've found this guy replied the same thing several times. I also verified the link and both worked. I'd go for the second one if I was you.
Posted by regretfuldaydreamer [send private reply] at September 25, 2002, 04:42:22 PM
As far as I know JIMI is depreciated... designed for Java 1.1. I'll check th ImageJ though.
- ImageJ is downloading and I will get back about this. Thanks. It loos up to date etc. Thanks
Posted by mop [send private reply] at September 25, 2002, 05:29:47 PM
I've always used PNGs
public class whatever extends Applet blah blah blah { Image bird; public void init() { bird = getImage(getCodeBase(), "bird.png"); } Something like that to declare it, then later when you want to draw: public void paint (Graphics g) { g.drawImage(bird, 0, 0, 32, 32,); } Well that wouldn't compile but you should get the point. You most likely have the right packages imported too..
Posted by buzgub [send private reply] at September 26, 2002, 03:06:36 AM
If you ever want to find file format information, I believe http://wotsit.org/ is considered the definitive source.
Posted by AnyoneEB [send private reply] at September 26, 2002, 05:32:25 AM
mop's code works for .gif, .jpg, and .bmp's too.
Posted by mop [send private reply] at September 26, 2002, 08:53:48 AM
yeah, its great with GIFs if you want transparancy for the images in your program (so they are not all blocks) or if you want them animated. I've tried with jpegs too but have only really gone with PNGs.
I wasn't bothering to try BMPs, but thanks for tellimg me they do work. I'm pretty sure there are some other obscure formats you could use as well.
Posted by CViper [send private reply] at September 26, 2002, 08:57:20 AM
what about tga? it features transparency (alpha-channels, so you can blend images) and a lossless compression (rle; bad results with some images)
Posted by mop [send private reply] at September 26, 2002, 09:00:48 AM
I tried using the alpha channels in a gif once- no, you can only use the complete transparacy. It just "solidifies" the colour that was made not completely transparent.
So I'd be very surprised it you could do so with tga, I'll try it after school.
Posted by CViper [send private reply] at September 26, 2002, 10:23:52 AM
you can save a 32 bit tga (eg. RGBA); most applications will probably ignore the alpha channel though.
Personally I use 32 bit tga images as textures with an alpha channel.
Posted by regretfuldaydreamer [send private reply] at September 26, 2002, 11:00:48 AM
BMP is convenient for me ( I do normally use JPG/GIF to store images though)
Register as a new user | |||||||||||||||||