Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. class app
  6. {
  7.     public static void Main(String[] args)
  8.     {
  9.         String arquivo;
  10.  
  11.         try
  12.         {
  13.             arquivo = args[0];
  14.         }
  15.         catch(Exception E)
  16.         {
  17.             Console.Write("Digite o nome de um arquivo BMP");
  18.             return;
  19.         }
  20.  
  21.         if(!File.Exists(String.Concat(arquivo, ".bmp")))
  22.         {
  23.             Console.Write("Arquivo BMP não encontrado");
  24.             return;
  25.         }
  26.  
  27.         Encoding tabelaUnicode8 = Encoding.GetEncoding("UTF-8");
  28.  
  29.         String assinatura;
  30.         Double tamanhoTotal;
  31.         Int32 largura;
  32.         Int32 altura;
  33.  
  34.         byte[] buffer = new byte[4];
  35.  
  36.         Stream FileStream = File.OpenRead(arquivo + ".bmp");
  37.         BinaryReader br = new BinaryReader(FileStream);
  38.  
  39.         FileStream.Position = 0x0;
  40.         assinatura = tabelaUnicode8.GetString(new byte[] {br.ReadByte(), br.ReadByte()});
  41.  
  42.         FileStream.Position = 0x2;
  43.         tamanhoTotal = br.ReadInt32() + br.ReadInt32() + br.ReadInt32() + br.ReadInt32();
  44.  
  45.         FileStream.Position = 0x12;
  46.         buffer[0] = br.ReadByte();
  47.         FileStream.Position = 0x13;
  48.         buffer[1] = br.ReadByte();
  49.         FileStream.Position = 0x14;
  50.         buffer[2] = br.ReadByte();
  51.         FileStream.Position = 0x15;
  52.         buffer[3] = br.ReadByte();
  53.  
  54.         largura = BitConverter.ToInt32(buffer, 0);
  55.  
  56.         FileStream.Position = 0x16;
  57.         buffer[0] = br.ReadByte();
  58.         FileStream.Position = 0x17;
  59.         buffer[1] = br.ReadByte();
  60.         FileStream.Position = 0x18;
  61.         buffer[2] = br.ReadByte();
  62.         FileStream.Position = 0x19;
  63.         buffer[3] = br.ReadByte();
  64.  
  65.         altura = BitConverter.ToInt32(buffer, 0);
  66.  
  67.         br.Close();
  68.         FileStream.Close();
  69.  
  70.         if(assinatura != "BM")
  71.         {
  72.             Console.WriteLine("---Este arquivo não é BMP---");
  73.             Console.WriteLine("Assinatura: " + assinatura);
  74.             return;
  75.         }
  76.  
  77.         Console.WriteLine("Assinatura: " + assinatura);
  78.         Console.WriteLine(String.Concat("Tamanho total: ", tamanhoTotal / 1024f / 1024f, " MB"));
  79.         Console.WriteLine(String.Concat("Largura: ", largura));
  80.         Console.WriteLine(String.Concat("Altura: ", altura));
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement