c# - Reading file in reverse -


because bmp files written bottom top (in terms of pixels), need read bmp file in reverse (and rid of 54-byte header). code far:

public string createnoheaderbmp(string curbmp)  //copies header    curbmp tempbmp     {         string tempbmp = "c:\\temp.bmp";          stream instream = file.openread(curbmp);         binaryreader br = new binaryreader(instream);          byte[] fullbmp = new byte[(width * height * 3) + 138];         byte[] buffer = new byte[1];         long bytesread;         long totalbytes = 0;          while ((bytesread = br.read(buffer, 0, 1)) > 0)         {             fullbmp[fullbmp.length - 1 - totalbytes] = buffer[0];             totalbytes++;         }          filestream fs = new filestream(tempbmp, filemode.create, fileaccess.write);         fs.write(fullbmp, 54, fullbmp.length - 54);         fs.close();         fs.dispose();          return tempbmp;     } 

for reason fails job completely, , results in image part of right side placed on left. why isn't reversing file? also, these bmp files large (600mb), can't use simple memorystream , seek , swap operation because i'll "out of memory" exception.

i haven't checked bmp specification, , don't have knowledge of it. i'll assume true.

most programs display bitmaps read header find out how big image is, , read data top bottom, painting bitmap bottom top instead. , can seek in files. use instream , seek in that, without ever needing have whole file in memory.

then, if can allocate byte array of 600 mib (i.e. 600 mib structure in memory), surely can allocate memorystream takes 600 mib of memory space. or, if outofmemoryexception, you'll regardless of whether use byte[] or memorystream. latter easier work with.

your idea of reversing fail unless realize thay you've reversed colors of each pixel r-g-b format (or whatever is) b-g-r. , i'm not sure of direction of bmp scan lines, if run left-to-right, reversed bitmap have image flipped horizontally.

the reason have part of image on right side displayed on left because can't reverse bitmap's bytes , expect come out correctly. also, have length of scan line wrong when drawing it.

also, header 54 bytes add 138 bytes array size in fullbmp. check constants: guaranteed never change, make them const. may change? read them bitmap.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -