Quick and dirty program to dump a bitmap string for a file. We use this in Z2 to embed a couple fallback images and a fallback sound effect, although we also have use C-grade bin2C most of the time to avoid the extra text parsing if possible.

形式
Erlang
投稿日時
2020-10-24 10:20
公開期間
無期限
  1. :- module file_to_bmp.
  2. %=============================================================================%
  3. :- interface.
  4. %=============================================================================%
  5. :- use_module io.
  6. %-----------------------------------------------------------------------------%
  7. :- pred main(io.io::di, io.io::uo) is det.
  8. %=============================================================================%
  9. :- implementation.
  10. %=============================================================================%
  11. :- use_module bitmap.
  12. :- use_module exception.
  13. :- import_module list.
  14. %-----------------------------------------------------------------------------%
  15. main(!IO) :-
  16. io.command_line_arguments(Args, !IO),
  17. (
  18. ( Args = [] ; Args = [_|[_|_]] ),
  19. io.write_string("Usage: file_to_bmp <file>\n", !IO)
  20. ;
  21. Args = [Path|[]],
  22. io.open_binary_input(Path, StreamResult, !IO),
  23. (
  24. StreamResult = io.ok(Stream),
  25. io.read_binary_file_as_bitmap(Stream, BMPResult, !IO),
  26. io.close_binary_input(Stream, !IO),
  27. (
  28. BMPResult = io.ok(BMP),
  29. io.write_string(bitmap.to_string(BMP), !IO)
  30. ;
  31. BMPResult = io.error(Error),
  32. io.write(Error, !IO)
  33. )
  34. ;
  35. StreamResult = io.error(Error),
  36. io.write(Error, !IO)
  37. )
  38. ),
  39. io.nl(!IO).
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト