MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SaveBitmapToFile

Method SaveBitmapToFile

Source/Engine/Platform/Base/FileSystemBase.cpp:37–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void FileSystemBase::SaveBitmapToFile(byte* data, uint32 width, uint32 height, uint32 bitsPerPixel, const uint32 padding, const String& path)
38{
39 // Try to open file
40 auto file = File::Open(path, FileMode::CreateAlways, FileAccess::Write, FileShare::None);
41 if (file == nullptr)
42 return;
43
44 const unsigned long headers_size = 54;
45 const unsigned long pixel_data_size = height * ((width * bitsPerPixel / 8) + padding);
46 const unsigned int filesize = headers_size + pixel_data_size;
47 uint8 bmpfileheader[14] = { 'B', 'M', 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0 };
48 uint8 bmpinfoheader[40] = { 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0 };
49 uint8 bmppad[3] = { 0, 0, 0 };
50
51 // Init the file header
52 bmpfileheader[2] = (uint8)(filesize);
53 bmpfileheader[3] = (uint8)(filesize >> 8);
54 bmpfileheader[4] = (uint8)(filesize >> 16);
55 bmpfileheader[5] = (uint8)(filesize >> 24);
56
57 // Init the bitmap info header
58 bmpinfoheader[4] = (uint8)(width);
59 bmpinfoheader[5] = (uint8)(width >> 8);
60 bmpinfoheader[6] = (uint8)(width >> 16);
61 bmpinfoheader[7] = (uint8)(width >> 24);
62 bmpinfoheader[8] = (uint8)(height);
63 bmpinfoheader[9] = (uint8)(height >> 8);
64 bmpinfoheader[10] = (uint8)(height >> 16);
65 bmpinfoheader[11] = (uint8)(height >> 24);
66
67 // Write the file header
68 file->Write(bmpfileheader, sizeof(bmpfileheader));
69
70 // Write the bitmap info header
71 file->Write(bmpinfoheader, sizeof(bmpinfoheader));
72
73 // Write the RGB Data
74 file->Write(data, pixel_data_size);
75
76 // Close the file
77 Delete(file);
78}
79
80bool FileSystemBase::AreFilePathsEqual(const StringView& path1, const StringView& path2)
81{

Callers

nothing calls this directly

Calls 2

DeleteFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected