djthyrax Posted December 20, 2009 at 11:36 PM Report Share #301596 Posted December 20, 2009 at 11:36 PM Boas, estou a usar uma lib que tem esta struct: typedef struct { short version; unsigned char cbeff[LIB_MAX_CBEFF_LEN]; unsigned char facialrechdr[LIB_MAX_FACRECH_LEN]; unsigned char facialinfo[LIB_MAX_FACINFO_LEN]; unsigned char imageinfo[LIB_MAX_IMAGEINFO_LEN]; unsigned char picture[LIB_MAX_PICTUREH_LEN]; unsigned long piclength; } LIB_PIC; E quero guardar o elemento picture num ficheiro. Estou a usar este código: FILE *fp = fopen("imagem.jp2", "w"); fwrite(pic.picture, sizeof(unsigned char), pic.piclength, fp); fclose(fp); Ora, eu sei que o conteudo do picture é um .jp2 (JPEG 2000) válido, pois tenho aqui um exemplo em Java do uso desta lib em que eles se limitam a chamar a função que preenche o pic e depois tudo o que fazem é criar um FileOutputStream e fazer write para o ficheiro do pic.picture. No entanto, quando abro o imagem.jp2 que eu gerei com o código que deixei aqui, o irfanview diz que deu erro a ler o header. Abri o ficheiro com um editor hex, e os magic numbers () em vez de serem: 00 00 00 0C 6A 50 20 20 0D 0A 87 0A 00 00 00 14 66 74 79 70 6A 70 32 são 00 00 00 0C 6A 50 20 20 0D 0D 0A 87 0D 0A 00 00 00 14 66 74 79 70 6A 70 32 Ou seja, o há um \r\n que passou a \r\r\n durante a escrita, e um \n que passou a \r\n. O que é que estou a fazer mal? Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum! Link to comment Share on other sites More sharing options...
Baderous Posted December 21, 2009 at 12:09 AM Report Share #301600 Posted December 21, 2009 at 12:09 AM PORTING ISSUESIf the stream is from a file opened in text mode, linefeed is translated to carriage-return linefeed on output. No such translation occurs for files opened in binary mode. http://www.mkssoftware.com/docs/man3/fwrite.3.asp Link to comment Share on other sites More sharing options...
djthyrax Posted December 21, 2009 at 12:49 AM Author Report Share #301605 Posted December 21, 2009 at 12:49 AM wb, fixed. Thx. Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum! Link to comment Share on other sites More sharing options...
IceBrain Posted December 21, 2009 at 12:52 AM Report Share #301606 Posted December 21, 2009 at 12:52 AM Já agora, isto acontece por estares no Windows - nos SOs Unix-like não existe distinção entre ficheiros abertos com "w" e com "wb". ❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents A list of command line apps Link to comment Share on other sites More sharing options...
djthyrax Posted December 21, 2009 at 12:53 AM Author Report Share #301607 Posted December 21, 2009 at 12:53 AM Já agora, isto acontece por estares no Windows - nos SOs Unix-like não existe distinção entre ficheiros abertos com "w" e com "wb". Sim, eu percebi. Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now