티스토리 뷰
public class BmpLoader
{
public struct BMPHeader
{
public short type;
public int size;
public short reserved1;
public short reserved2;
public int offset;
}
public struct BMPInfoHeader
{
public int size;
public int width;
public int height;
public short planes;
public short bitsPerPixel;
public uint compression;
public uint imageSize;
public int xPelsPerMeter;
public int yPelsPerMeter;
public int clrUsed;
public int clrImportant;
}
private BMPHeader header;
private BMPInfoHeader infoHeader;
public byte[] Load(string filename, out int width, out int height)
{
BinaryReader reader = new BinaryReader(File.OpenRead(filename));
header.type = reader.ReadInt16();
header.size = reader.ReadInt32();
header.reserved1 = reader.ReadInt16();
header.reserved2 = reader.ReadInt16();
header.offset = reader.ReadInt32();
infoHeader.size = reader.ReadInt32();
infoHeader.width = reader.ReadInt32();
infoHeader.height = reader.ReadInt32();
infoHeader.planes = reader.ReadInt16();
infoHeader.bitsPerPixel = reader.ReadInt16();
infoHeader.compression = reader.ReadUInt32();
infoHeader.compression = reader.ReadUInt32();
infoHeader.xPelsPerMeter = reader.ReadInt32();
infoHeader.yPelsPerMeter = reader.ReadInt32();
infoHeader.clrUsed = reader.ReadInt32();
infoHeader.clrImportant = reader.ReadInt32();
int size = infoHeader.width * infoHeader.height * (infoHeader.bitsPerPixel / 8);
byte[] pixels = reader.ReadBytes(size);
width = infoHeader.width;
height = infoHeader.height;
return pixels;
}
}
'프로그래밍' 카테고리의 다른 글
PHP CDKEY 쿠폰번호 생성 소스 (0) | 2016.11.26 |
---|---|
JavaScript canvas image draw (0) | 2016.10.30 |
Java GC root (0) | 2016.07.21 |
동영상 프레임의 종류 I/P/B 프레임(i-frame, p-frame, b-frame) (0) | 2016.07.21 |
C언어 quick sort 예제 (0) | 2016.07.15 |
- Total
- Today
- Yesterday