Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- class app
- {
- public static void Main(String[] args)
- {
- String arquivo;
- try
- {
- arquivo = args[0];
- }
- catch(Exception E)
- {
- Console.Write("Digite o nome de um arquivo BMP");
- return;
- }
- if(!File.Exists(String.Concat(arquivo, ".bmp")))
- {
- Console.Write("Arquivo BMP não encontrado");
- return;
- }
- Encoding tabelaUnicode8 = Encoding.GetEncoding("UTF-8");
- String assinatura;
- Double tamanhoTotal;
- Int32 largura;
- Int32 altura;
- byte[] buffer = new byte[4];
- Stream FileStream = File.OpenRead(arquivo + ".bmp");
- BinaryReader br = new BinaryReader(FileStream);
- FileStream.Position = 0x0;
- assinatura = tabelaUnicode8.GetString(new byte[] {br.ReadByte(), br.ReadByte()});
- FileStream.Position = 0x2;
- tamanhoTotal = br.ReadInt32() + br.ReadInt32() + br.ReadInt32() + br.ReadInt32();
- FileStream.Position = 0x12;
- buffer[0] = br.ReadByte();
- FileStream.Position = 0x13;
- buffer[1] = br.ReadByte();
- FileStream.Position = 0x14;
- buffer[2] = br.ReadByte();
- FileStream.Position = 0x15;
- buffer[3] = br.ReadByte();
- largura = BitConverter.ToInt32(buffer, 0);
- FileStream.Position = 0x16;
- buffer[0] = br.ReadByte();
- FileStream.Position = 0x17;
- buffer[1] = br.ReadByte();
- FileStream.Position = 0x18;
- buffer[2] = br.ReadByte();
- FileStream.Position = 0x19;
- buffer[3] = br.ReadByte();
- altura = BitConverter.ToInt32(buffer, 0);
- br.Close();
- FileStream.Close();
- if(assinatura != "BM")
- {
- Console.WriteLine("---Este arquivo não é BMP---");
- Console.WriteLine("Assinatura: " + assinatura);
- return;
- }
- Console.WriteLine("Assinatura: " + assinatura);
- Console.WriteLine(String.Concat("Tamanho total: ", tamanhoTotal / 1024f / 1024f, " MB"));
- Console.WriteLine(String.Concat("Largura: ", largura));
- Console.WriteLine(String.Concat("Altura: ", altura));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement