document.write("<div class=\"pastie\">\n");
document.write("  <link href=\"http://pastie.org/stylesheets/embed.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n");
document.write("  <link href=\"http://pastie.org/stylesheets/clean.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n");
document.write("  \n");
document.write("\n");
document.write("  \n");
document.write("  \n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("	\n");
document.write("	<div class=\"allcode\">\n");
document.write("		<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n");
document.write("		<tr>\n");
document.write("			<td>\n");
document.write("				\n");
document.write("				<pre class=\"textmate-source-numbers\">1\n");
document.write("2\n");
document.write("3\n");
document.write("4\n");
document.write("5\n");
document.write("6\n");
document.write("7\n");
document.write("8\n");
document.write("9\n");
document.write("10\n");
document.write("11\n");
document.write("12\n");
document.write("13\n");
document.write("14\n");
document.write("15\n");
document.write("16\n");
document.write("17\n");
document.write("18\n");
document.write("19\n");
document.write("20\n");
document.write("21\n");
document.write("22\n");
document.write("23\n");
document.write("24\n");
document.write("25\n");
document.write("26\n");
document.write("27\n");
document.write("28\n");
document.write("29\n");
document.write("30\n");
document.write("31\n");
document.write("<\/pre>\n");
document.write("			<\/td>\n");
document.write("		<td>\n");
document.write("		<pre class=\"textmate-source\"><pre class=\"sunburst\"><span class=\'meta meta_definition meta_definition_method meta_definition_method_csharp\'>        <span class=\'storage storage_modifier storage_modifier_csharp\'>public static <\/span><span class=\'storage storage_type storage_type_csharp\'>Bitmap<\/span> <span class=\'entity entity_name entity_name_function entity_name_function_csharp\'>UnsafeBytesToBmp<\/span><span class=\'meta meta_definition meta_definition_param-list meta_definition_param-list_csharp\'>(<span class=\'storage storage_type storage_type_csharp\'>byte<\/span>[] bmpBytes, Size imageSize<\/span>)<\/span>\n");
document.write("        {\n");
document.write("            var bmp = <span class=\'keyword keyword_operator keyword_operator_csharp\'>new<\/span> Bitmap(imageSize.Width, imageSize.Height);\n");
document.write("\n");
document.write("            BitmapData bData = bmp.LockBits(<span class=\'keyword keyword_operator keyword_operator_csharp\'>new<\/span> Rectangle(<span class=\'keyword keyword_operator keyword_operator_csharp\'>new<\/span> Point(), bmp.Size),\n");
document.write("                ImageLockMode.WriteOnly,\n");
document.write("                PixelFormat.Format24bppRgb);\n");
document.write("\n");
document.write("            <span class=\'comment comment_line comment_line_double-slash comment_line_double-slash_csharp\'>// Copy the bytes to the bitmap object<\/span>\n");
document.write("            Marshal.Copy(bmpBytes, <span class=\'constant constant_numeric constant_numeric_csharp\'>0<\/span>, bData.Scan0, bmpBytes.Length);\n");
document.write("            bmp.UnlockBits(bData);\n");
document.write("            <span class=\'keyword keyword_control keyword_control_csharp\'>return<\/span> bmp;\n");
document.write("        }\n");
document.write("\n");
document.write("        <span class=\'storage storage_modifier storage_modifier_csharp\'>public<\/span> <span class=\'storage storage_modifier storage_modifier_csharp\'>static<\/span> <span class=\'storage storage_type storage_type_csharp\'>byte<\/span>[] UnsafeBmpToBytes(Bitmap bmp)\n");
document.write("        {\n");
document.write("            BitmapData bData = bmp.LockBits(<span class=\'keyword keyword_operator keyword_operator_csharp\'>new<\/span> Rectangle(<span class=\'keyword keyword_operator keyword_operator_csharp\'>new<\/span> Point(), bmp.Size),\n");
document.write("                ImageLockMode.ReadOnly,\n");
document.write("                PixelFormat.Format24bppRgb);\n");
document.write("            <span class=\'comment comment_line comment_line_double-slash comment_line_double-slash_csharp\'>// number of bytes in the bitmap<\/span>\n");
document.write("            var byteCount = bData.Stride * bmp.Height;\n");
document.write("            var bmpBytes = <span class=\'keyword keyword_operator keyword_operator_csharp\'>new<\/span> <span class=\'storage storage_type storage_type_csharp\'>byte<\/span>[byteCount];\n");
document.write("\n");
document.write("            <span class=\'comment comment_line comment_line_double-slash comment_line_double-slash_csharp\'>// Copy the locked bytes from memory<\/span>\n");
document.write("            Marshal.Copy(bData.Scan0, bmpBytes, <span class=\'constant constant_numeric constant_numeric_csharp\'>0<\/span>, byteCount);\n");
document.write("\n");
document.write("            <span class=\'comment comment_line comment_line_double-slash comment_line_double-slash_csharp\'>// don\'t forget to unlock the bitmap!!<\/span>\n");
document.write("            bmp.UnlockBits(bData);\n");
document.write("\n");
document.write("            <span class=\'keyword keyword_control keyword_control_csharp\'>return<\/span> bmpBytes;\n");
document.write("        }\n");
document.write("<\/pre><\/pre>\n");
document.write("		<\/td>\n");
document.write("		<\/tr>\n");
document.write("		<\/table>\n");
document.write("	\n");
document.write("	<\/div>\n");
document.write("\n");
document.write("\n");
document.write("  \n");
document.write("  \n");
document.write("  <div class=\"credit\">\n");
document.write("    <div class=\"buttons\">\n");
document.write("      <a href=\"http://pastie.org/pastes/698299.txt\">\n");
document.write("      <img src=\"http://pastie.org/images/view.png\" height=\"20\" width=\"67\" /><\/a>\n");
document.write("    <\/div>\n");
document.write("  \n");
document.write("    <a href=\"http://pastie.org/698299\">Pastie #698299<\/a> linked directly from <a href=\"http://pastie.org/\">Pastie<\/a>.\n");
document.write("  <\/div><\/div>");

