{"id":959,"date":"2013-02-13T15:18:31","date_gmt":"2013-02-13T14:18:31","guid":{"rendered":"https:\/\/ridgesolutions.ie\/?p=959"},"modified":"2022-05-20T13:59:37","modified_gmt":"2022-05-20T12:59:37","slug":"c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example","status":"publish","type":"post","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/","title":{"rendered":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example"},"content":{"rendered":"<p>Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference!<\/p>\n<p>This code copies each byte (8 bit pixel) in the 8bit image into an array of 32bit pixels (4 bytes per pixel) and then saves it to disk. Note that you have to build your project with the &#8216;Allow unsafe code&#8217; checkbox checked (go to project properties \/ Build and you will see the &#8216;Allow unsafe code&#8217; checkbox.)<\/p>\n<div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public void SaveAsBitmap(string fileName, int width, int height, byte[] imageData)\r\n{\r\n    \/\/ Need to copy our 8 bit greyscale image into a 32bit layout.\r\n    \/\/ Choosing 32bit rather than 24 bit as its easier to calculate stride etc.\r\n    \/\/ This will be slow enough and isn't the most efficient method.\r\n    var data = new byte[width * height * 4];\r\n\r\n    int o = 0;\r\n\r\n    for (var i = 0; i &lt; width * height; i++)\r\n    {\r\n        var value = imageData[i];\r\n\r\n        \/\/ Greyscale image so r, g, b, get the same\r\n        \/\/ intensity value.\r\n        data[o++] = value;\r\n        data[o++] = value;\r\n        data[o++] = value;\r\n        data[o++] = 0; \/\/ Alpha isn't actually used\r\n    }\r\n\r\n    unsafe\r\n    {\r\n        fixed (byte* ptr = data)\r\n        {\r\n            \/\/ Create a bitmap wit a raw pointer to the data\r\n            using (Bitmap image = new Bitmap(width, height, width * 4,\r\n            PixelFormat.Format32bppRgb, new IntPtr(ptr)))\r\n            {\r\n                \/\/ And save it.\r\n                image.Save(Path.ChangeExtension(fileName, \".bmp\"));\r\n            }\r\n        }\r\n    }\r\n}<\/pre>\n<\/div>\n<p>Thanks to all on this <a href=\"http:\/\/stackoverflow.com\/questions\/742236\/how-to-create-a-bmp-file-from-byte-in-c-sharp\">thread<\/a> for the pointers!<\/p>\n<div><\/div>\n<p><strong>Update, 02\/2014:<br \/>\n<\/strong><br \/>\nThis code will save the 8 bit bitmap in a compressed (but perfectly valid) format, to have your software save it in an uncompressed format take a look at <a href=\"https:\/\/ridgesolutions.ie\/index.php\/2014\/02\/06\/save-8-bit-uncompressed-windows-bitmap-file-bmp-in-c-net\/\">this<\/a> post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[191,67,185],"class_list":["post-959","post","type-post","status-publish","format-standard","hentry","category-tech-stuff","tag-bitmap","tag-c","tag-image"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Kevin Godden\"\/>\n\t<meta name=\"google-site-verification\" content=\"Kyj52YLp6GOPA44PVBffo9fjW8rgWHYYRF0ZYjfy6ss\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Systems and Embedded Software Engineering, Ireland. | Some thoughts of a busy Computer Engineer\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example\" \/>\n\t\t<meta property=\"og:description\" content=\"Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2013-02-13T14:18:31+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-05-20T12:59:37+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#article\",\"name\":\"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example\",\"headline\":\"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example\",\"author\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/wp-content\\\/uploads\\\/2013\\\/09\\\/ridge_logo1.jpg\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#articleImage\",\"width\":400,\"height\":81},\"datePublished\":\"2013-02-13T15:18:31+00:00\",\"dateModified\":\"2022-05-20T13:59:37+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#webpage\"},\"articleSection\":\"Tech Stuff, bitmap, c#, image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ridgesolutions.ie\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"name\":\"Tech Stuff\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"position\":2,\"name\":\"Tech Stuff\",\"item\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#listItem\",\"name\":\"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#listItem\",\"position\":3,\"name\":\"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"name\":\"Tech Stuff\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\",\"name\":\"Ridge Solutions, Software Development and Software Engineering, Ireland.\",\"description\":\"Some thoughts of a busy Computer Engineer\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/wp-content\\\/uploads\\\/2013\\\/09\\\/ridge_logo1.jpg\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#organizationLogo\",\"width\":400,\"height\":81},\"image\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/\",\"name\":\"Kevin Godden\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2833f41e59a25cf2a9741a05ec383bfdd278762a5e0798a90940e7ab0a107a2?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Kevin Godden\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#webpage\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/\",\"name\":\"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example\",\"description\":\"Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2013\\\/02\\\/13\\\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"datePublished\":\"2013-02-13T15:18:31+00:00\",\"dateModified\":\"2022-05-20T13:59:37+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/\",\"name\":\"Ridge Solutions, Software Development and Software Engineering, Ireland.\",\"description\":\"Some thoughts of a busy Computer Engineer\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example","description":"Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in","canonical_url":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"google-site-verification":"Kyj52YLp6GOPA44PVBffo9fjW8rgWHYYRF0ZYjfy6ss","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#article","name":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example","headline":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example","author":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"publisher":{"@id":"https:\/\/www.ridgesolutions.ie\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/www.ridgesolutions.ie\/wp-content\/uploads\/2013\/09\/ridge_logo1.jpg","@id":"https:\/\/www.ridgesolutions.ie\/#articleImage","width":400,"height":81},"datePublished":"2013-02-13T15:18:31+00:00","dateModified":"2022-05-20T13:59:37+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#webpage"},"isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#webpage"},"articleSection":"Tech Stuff, bitmap, c#, image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie#listItem","position":1,"name":"Home","item":"https:\/\/www.ridgesolutions.ie","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","name":"Tech Stuff"}},{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","position":2,"name":"Tech Stuff","item":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#listItem","name":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#listItem","position":3,"name":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example","previousItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","name":"Tech Stuff"}}]},{"@type":"Organization","@id":"https:\/\/www.ridgesolutions.ie\/#organization","name":"Ridge Solutions, Software Development and Software Engineering, Ireland.","description":"Some thoughts of a busy Computer Engineer","url":"https:\/\/www.ridgesolutions.ie\/","logo":{"@type":"ImageObject","url":"https:\/\/www.ridgesolutions.ie\/wp-content\/uploads\/2013\/09\/ridge_logo1.jpg","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#organizationLogo","width":400,"height":81},"image":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author","url":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/","name":"Kevin Godden","image":{"@type":"ImageObject","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d2833f41e59a25cf2a9741a05ec383bfdd278762a5e0798a90940e7ab0a107a2?s=96&d=mm&r=g","width":96,"height":96,"caption":"Kevin Godden"}},{"@type":"WebPage","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#webpage","url":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/","name":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example","description":"Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/#website"},"breadcrumb":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/#breadcrumblist"},"author":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"creator":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"datePublished":"2013-02-13T15:18:31+00:00","dateModified":"2022-05-20T13:59:37+00:00"},{"@type":"WebSite","@id":"https:\/\/www.ridgesolutions.ie\/#website","url":"https:\/\/www.ridgesolutions.ie\/","name":"Ridge Solutions, Software Development and Software Engineering, Ireland.","description":"Some thoughts of a busy Computer Engineer","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.ridgesolutions.ie\/#organization"}}]},"og:locale":"en_US","og:site_name":"Systems and Embedded Software Engineering, Ireland. | Some thoughts of a busy Computer Engineer","og:type":"article","og:title":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example","og:description":"Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in","og:url":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/","article:published_time":"2013-02-13T14:18:31+00:00","article:modified_time":"2022-05-20T12:59:37+00:00","twitter:card":"summary","twitter:title":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example","twitter:description":"Here is a quick, dirty and inefficient example of how to save an 8bit Grey scale image stored in a C# byte array as a 32bit bitmap file (.bmp). Saving bitmaps can be quite suprisingly difficult in .NET so I am posting this for future reference! This code copies each byte (8 bit pixel) in"},"aioseo_meta_data":{"post_id":"959","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-634ed6aa42501","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-09-13 13:56:43","updated":"2025-07-15 22:06:24","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ridgesolutions.ie\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/\" title=\"Tech Stuff\">Tech Stuff<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tC# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.ridgesolutions.ie"},{"label":"Tech Stuff","link":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/"},{"label":"C# Save Grayscale byte array Image (byte[]) as Bitmap file (.bmp) example","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2013\/02\/13\/c-save-grayscale-bytearray-image-byte-as-bitmap-file-bmp-example\/"}],"_links":{"self":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/comments?post=959"}],"version-history":[{"count":0,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/959\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/media?parent=959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/categories?post=959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/tags?post=959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}