M
mmcclaf
Does anyone know how to get all of the header file from a .BMP file
using java?
using java?
Open the file as a binary, not text, file and read the headers.Does anyone know how to get all of the header file from a .BMP file
using java?
Do you google?mmcclaf said:Does anyone know how to get all of the header file from a .BMP file
using java?
Does anyone know how to get all of the header file from a .BMP file
using java?
Have a look at the ImageInfo class part of common11. Seehttp://mindprod.com/products1.html#COMMON11
It handles PNG, GIF and JPG. IF you had docs on BMP format, you could
get info in a similar way.
I took a look at them but I'm still having troubles with a
FileInputStream, or perhaps its the understanding of how it works.
HAs anyone done anything like this with coding before?
I took a look at them but I'm still having troubles with a
FileInputStream, or perhaps its the understanding of how it works. And
then the trouble of trying to split it up into the different sections.
HAs anyone done anything like this with coding before?
I took a look at them but I'm still having troubles with a
FileInputStream, or perhaps its the understanding of how it works. And
then the trouble of trying to split it up into the different sections.
HAs anyone done anything like this with coding before?
There may be easier ways of getting the information you seek,
but just as a kick-start:
[TODO: needs work]
import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.BitSet;
public class BMPTest {
public static void main(String[] args)
throws Exception {
File file = new File(args[0]);
byte[] fileHeaderBytes = new byte[14];
byte[] infoSizeBytes = new byte[4];
int infoSize;
byte[] infoHeader;
InfoHeader header;
FileInputStream inputStream =
new FileInputStream(file);
inputStream.read(fileHeaderBytes);
inputStream.read(infoSizeBytes, 0, 4);
infoSize =
(((int)infoSizeBytes[3]&0xff)<<24) |
(((int)infoSizeBytes[2]&0xff)<<16) |
(((int)infoSizeBytes[1]&0xff)<<8) |
(int)infoSizeBytes[0]&0xff;
if(infoSize == 40) {
infoHeader = new byte[40];
infoHeader[0] = infoSizeBytes[0];
infoHeader[1] = infoSizeBytes[1];
infoHeader[2] = infoSizeBytes[2];
infoHeader[3] = infoSizeBytes[3];
inputStream.read(infoHeader, 4, 36);
}
else if(infoSize == 120) {
infoHeader = new byte[120];
infoHeader[0] = infoSizeBytes[0];
infoHeader[1] = infoSizeBytes[1];
infoHeader[2] = infoSizeBytes[2];
infoHeader[3] = infoSizeBytes[3];
inputStream.read(infoHeader, 4, 116);
}
else if(infoSize == 136) {
infoHeader = new byte[136];
infoHeader[0] = infoSizeBytes[0];
infoHeader[1] = infoSizeBytes[1];
infoHeader[2] = infoSizeBytes[2];
infoHeader[3] = infoSizeBytes[3];
inputStream.read(infoHeader, 4, 132);
}
else throw new Exception();
header = new InfoHeader(infoHeader);
System.out.println(header.toString());
}
}
/**
* <p>The InfoHeader class contains information
* about the dimensions and color format of a
* Windows Device Independant Bitmap.</p>
* <p>For Windows prior to Windows 95:
* Applications can use the BITMAPV4HEADER
* structure for added functionality.</p>
* <p>For Windows 95, Windows NT 4.0:
* Applications can use the BITMAPV4HEADER
* structure for added functionality.</p>
* <p>For Windows 98/Me, Windows 2000/XP:
* Applications can use the BITMAPV5HEADER
* structure for added functionality.</p>
*/
public class InfoHeader {
private final byte[] data;
/**
* The sole constructor for the InfoHeader class.
* @param b
*/
public InfoHeader(byte[] data) {
if( data.length == 40 ||
data.length == 120 ||
data.length != 136) {
this.data = data;
}
else
throw new IllegalArgumentException();
}
/**
*
* @return
*/
public InfoHeaderVersion getVersion() {
if(data.length == 40) {
return InfoHeaderVersion.V0;
}
else if(data.length == 120) {
return InfoHeaderVersion.V4;
}
else {
return InfoHeaderVersion.V5;
}
}
/**
* Specifies the number of bytes required by the structure.
* Applications should use this member to determine which
* bitmap information header structure is being used.
*
* @return
*/
public Long getSize() {
return null;
}
/**
* Specifies the width of the bitmap, in pixels.
*
* <p>If bV5Compression is BI_JPEG or BI_PNG,
* the bV5Width member specifies the width of the
* decompressed JPEG or PNG image in pixels.</p>
*
* @return
*/
public Long getWidth() {
return null;
}
/**
* Specifies the height of the bitmap, in pixels.
* If the value of bV5Height is positive, the bitmap is a
* bottom-up DIB and its origin is the lower-left corner.
* If bV5Height value is negative, the bitmap is a top-down
* DIB and its origin is the upper-left corner.
*
* <p>If bV5Height is negative, indicating a top-down DIB,
* bV5Compression must be either BI_RGB or BI_BITFIELDS.
* Top-down DIBs cannot be compressed.</p>
*
* <p>If bV5Compression is BI_JPEG or BI_PNG,
* the bV5Height member specifies the height of the
* decompressed JPEG or PNG image in pixels.</p>
*
* @return
*/
public Long getHeight() {
return null;
}
/**
* Specifies the number of planes for the target device.
* This value must be set to 1.
*
* @return
*/
public Integer getPlanes() {
return Integer.valueOf(1);
}
/**
* Specifies the number of bits that define each pixel
* and the maximum number of colors in the bitmap.
*
* @return
*/
public Integer getBitCount() {
return null;
}
/**
* Specifies that the bitmap is not compressed.
* The bV5RedMask, bV5GreenMask, and bV5BlueMask members
* specify the red, green, and blue components of each pixel.
* This is valid when used with 16- and 32-bpp bitmaps.
*
* @return
*/
public Compression getV5Compression() {
return null;
}
/**
* Specifies the size, in bytes, of the image.
* This may be set to zero for BI_RGB bitmaps.
*
* <p>If bV5Compression is BI_JPEG or BI_PNG,
* bV5SizeImage is the size of the JPEG or PNG image buffer.</p>
*
* @return
*/
public Long getSizeImage() {
return null;
}
/**
* Specifies the horizontal resolution, in pixels-per-meter,
* of the target device for the bitmap.
* An application can use this value to select a bitmap from
* a resource group that best matches the characteristics of
* the current device.
*
* @return
*/
public Integer getXPelsPerMeter() {
return null;
}
/**
* Specifies the vertical resolution, in pixels-per-meter,
* of the target device for the bitmap.
*
* @return
*/
public Integer getYPelsPerMeter() {
return null;
}
/**
* Specifies the number of color indexes in the color table
* that are actually used by the bitmap. If this value is
* zero, the bitmap uses the maximum number of colors
* corresponding to the value of the bV5BitCount member for
* the compression mode specified by bV5Compression.
*
* <p>If bV5ClrUsed is nonzero and bV5BitCount is less than
* 16, the bV5ClrUsed member specifies the actual number of
* colors the graphics engine or device driver accesses.
* If bV5BitCount is 16 or greater, the bV5ClrUsed member
* specifies the size of the color table used to optimize
* performance of the system color palettes.
* If bV5BitCount equals 16 or 32, the optimal color palette
* starts immediately following the BITMAPV5HEADER.
* If bV5ClrUsed is nonzero,
* the color table is used on palettized devices, and
* bV5ClrUsed specifies the number of entries.</p>
*
* @return
*/
public Integer getClrUsed() {
return null;
}
/**
* Specifies the number of color indexes that are
* required for displaying the bitmap.
* If this value is zero, all colors are required.
*
* @return
*/
public Integer getClrImportant() {
return null;
}
/**
* Color mask that specifies the red component of each pixel,
* valid only if bV5Compression is set to BI_BITFIELDS.
*
* @return
*/
public BitSet getRedMask() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* Color mask that specifies the green component of each pixel,
* valid only if bV5Compression is set to BI_BITFIELDS.
*
* @return
*/
public BitSet getGreenMask() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* Color mask that specifies the blue component of each pixel,
* valid only if bV5Compression is set to BI_BITFIELDS.
*
* @return
*/
public BitSet getBlueMask() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* Color mask that specifies the alpha component of each pixel.
*
* @return
*/
public BitSet getAlphaMask() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* Specifies the color space of the DIB.
*
* @return
*/
public LogicalColorSpace getCSType() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* A CIEXYZTRIPLE structure that specifies the x, y,
* and z coordinates of the three colors that correspond
* to the red, green, and blue endpoints for the logical
* color space associated with the bitmap.
* This member is ignored unless the bV5CSType member
* specifies LCS_CALIBRATED_RGB.
*
* @return
*/
public CIEXYZTriple getEndpoints() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* Toned response curve for red.
* Used if bV5CSType is set to LCS_CALIBRATED_RGB.
* Specified in 16^16 format.
*
* @return
*/
public FixedPoint8Dot8 getGammaRed() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* Toned response curve for green.
* Used if bV5CSType is set to LCS_CALIBRATED_RGB.
* Specified in 16^16 format.
*
* @return
*/
public FixedPoint8Dot8 getGammaGreen() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* Toned response curve for blue.
* Used if bV5CSType is set to LCS_CALIBRATED_RGB.
* Specified in 16^16 format.
*
* @return
*/
public FixedPoint8Dot8 getGammaBlue() {
if(getVersion() == InfoHeaderVersion.V0)
return null;
else
return null;
}
/**
* Rendering intent for bitmap.
*
* @return...
read more »
(e-mail address removed) wrote:
Jeff Higgins said:(e-mail address removed) wrote:
(e-mail address removed) wrote:
But I'm kind of lost as to how to even output the colourtable to screen
I get:
java.lang.OutOfMemoryError: Java heap space
at this line:
pic.optionalPalette = new byte[nNumColors * 4];
using this bitmap file:
<http://preview.tinyurl.com/5263tj>.
The value of nNumColors is: 16777216
at the point of failure.
Is pic.optionalPalette you're "colourtable"?
I haven't had time to look any more just yet.
JH
Thats what I think it is. I mean for this next part that I'm supposed
to do, I'm supposed to output the contents of the colour table to the
screen. So of course, I'm using the palette to find out the colours
and how many there are. But I don't even know how to do this part
correctly. I mean, sure I'm looking at code (http://www.lordjoe.com/
JavaCourse/BMPLoader.html) and trying to follow it, but I'm completely
lost at this part of the code as to how to even read it in.
But I'm kind of lost as to how to even output the colourtable to screen
I'm sure that lordjoe is fine, without even looking, and following
code examples is fine, but have you looked into the horse's mouth?
<http://msdn2.microsoft.com/en-us/library/ms532349(VS.85).aspx>
There's a lot there, look for "Bitmap Storage", BITMAPINFOHEADER,
etc. etc.
I have looked at the coding, but still lost as to what I'm trying to
do. I understand/did the header and the file info stuff.
mmcclaf said:Good news, I managed to get the next part to half work but I don't
think I'm getting the right bytes in for my colours.
Any ideas?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.