{"id":4820,"date":"2020-03-24T17:25:36","date_gmt":"2020-03-24T08:25:36","guid":{"rendered":"http:\/\/aval-global.com\/?p=4820"},"modified":"2020-03-24T19:56:17","modified_gmt":"2020-03-24T10:56:17","slug":"c-%e5%9b%be%e5%83%8f%e4%ba%ae%e5%ba%a6%e5%80%bc%e9%87%87%e9%9b%86%e9%80%9f%e5%ba%a6%e7%9a%84%e6%af%94%e8%be%83","status":"publish","type":"post","link":"https:\/\/aval-global.com\/?p=4820&lang=zh","title":{"rendered":"[C#] \u56fe\u50cf\u4eae\u5ea6\u503c\u91c7\u96c6\u901f\u5ea6\u7684\u6bd4\u8f83"},"content":{"rendered":"<p><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:calc( 1150px + 0px );margin-left: calc(-0px \/ 2 );margin-right: calc(-0px \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:0px;--awb-margin-bottom-large:20px;--awb-spacing-left-large:0px;--awb-width-medium:100%;--awb-spacing-right-medium:0px;--awb-spacing-left-medium:0px;--awb-width-small:100%;--awb-spacing-right-small:0px;--awb-spacing-left-small:0px;\"><div class=\"fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-1\"><p>\u5f53\u4f7f\u7528GetPixel\u6216SetPixel\u65b9\u6cd5\u5728C\uff03\u4e2d\u83b7\u53d6\u6216\u8bbe\u7f6e\u56fe\u50cf\u7684\u4eae\u5ea6\u503c\u65f6\uff0c\u901f\u5ea6\u53d8\u6162\uff0c\u56e0\u6b64\uff0c\u901a\u5e38\u901a\u8fc7\u5c06\u6309\u94ae\u7684LockBits\u8bbe\u7f6e\u4e3aUnlockBits\u6765\u83b7\u53d6\u6216\u8bbe\u7f6e\u4eae\u5ea6\u3002 \u8fdb\u800c\u6bd4\u8f83\u4e86\u5904\u7406\u65f6\u95f4\u3002<\/p>\n<table style=\"border-collapse: collapse; width: 37.926%; height: 168px;\" border=\"1\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 10.6962%; background-color: #1940b5; height: 24px;\" colspan=\"2\"><span style=\"color: #ffffff;\">\u73af\u5883\u00a0<\/span><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 10.6962%; height: 24px;\">OS<\/td>\n<td style=\"width: 27.2603%; height: 24px;\">Windows10 64bit ver.1809<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 10.6962%; height: 24px;\">CPU<\/td>\n<td style=\"width: 27.2603%; height: 24px;\">Intel Core i7-7700K 4.2GHz<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 10.6962%; height: 24px;\">Memory<\/td>\n<td style=\"width: 27.2603%; height: 24px;\">32GB<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 10.6962%; height: 24px;\">.NET Framework<\/td>\n<td style=\"width: 27.2603%; height: 24px;\">4.5.2<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 10.6962%; height: 24px;\">\u5e73\u53f0<\/td>\n<td style=\"width: 27.2603%; height: 24px;\">Any CPU (32Bit \u4f18\u5148)<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 10.6962%; height: 24px;\">\u8bc4\u4ef7\u5f71\u50cf<\/td>\n<td style=\"width: 27.2603%; height: 24px;\">JPEG 6,000 x 4,000px 24bit Color<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8be5\u6d4b\u8bd5\u4f7f\u7528\u4e86\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u8be5\u7a0b\u5e8f\u83b7\u53d6R,G,B\u4e2d\u5f69\u8272\u56fe\u50cf\u7684\u4eae\u5ea6\u503c\uff0c\u7136\u540e\u53cd\u8f6c\u5f3a\u5ea6\u503c\u5e76\u518d\u6b21\u66ff\u6362\u5b83\u4eec\u3002<\/p>\n<ol>\n<li>\u5904\u7406\u7ed3\u679c\u5982\u4e0b\uff1a\u4eae\u2192\u6697\u2192\u4eae\u2192\u6697\u3002<\/li>\n<li>\u5904\u7406\u65f6\u95f4\uff1a\u6d4b\u91cf5\u6b21\u8fed\u4ee3\u7684\u5e73\u5747\u65f6\u95f4\u3002<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"alignnone size-800 alignleft\" src=\"https:\/\/imagingsolution.net\/wordpress\/wp-content\/uploads\/2019\/11\/set_get_bright_speed_1.png\" width=\"391\" height=\"353\" \/><img decoding=\"async\" class=\"alignnone size-800 alignleft\" src=\"https:\/\/imagingsolution.net\/wordpress\/wp-content\/uploads\/2019\/11\/set_get_bright_speed_2.png\" width=\"391\" height=\"353\" \/><\/p>\n<\/div><\/div><\/div><\/div><\/div><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-2 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:calc( 1150px + 0px );margin-left: calc(-0px \/ 2 );margin-right: calc(-0px \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-1 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:0px;--awb-margin-bottom-large:20px;--awb-spacing-left-large:0px;--awb-width-medium:100%;--awb-spacing-right-medium:0px;--awb-spacing-left-medium:0px;--awb-width-small:100%;--awb-spacing-right-small:0px;--awb-spacing-left-small:0px;\"><div class=\"fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-2\"><h3>1. GetPixel, SetPixel\u7684\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-1 > .CodeMirror, .fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-1 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:var(--awb-color3);\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_1\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_1\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_1\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-scss\">\/\/\/ <summary>\n\/\/\/ GetPixel\u3001SetPixel \u8bbe\u7f6e\u4eae\u5ea6\u503c\u91c7\u96c6\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"bmp\"><\/param>\nprivate void NegativeImage1(Bitmap bmp)\n{\nvar width = bmp.Width;\nvar height = bmp.Height;\nColor col;\nint r, g, b;\nfor (int y = 0; y < height; y++)\n{\nfor (int x = 0; x < width; x++)\n{\n\/\/ \u83b7\u53d6\u4eae\u5ea6\u503c\ncol = bmp.GetPixel(x, y);\nr = col.R;\ng = col.G;\nb = col.B;\n\/\/ \u53cd\u8f6c\u989c\u8272\ncol = Color.FromArgb(255 - r, 255 - g, 255 - b);\n\/\/ \u8bbe\u5b9a\u4eae\u5ea6\u503c\nbmp.SetPixel(x, y, col);\n}\n}\n}\n\u5e73\u5747\u5904\u7406\u65f6\u95f4 27,439msec\n\n<\/textarea><\/div><div class=\"fusion-text fusion-text-3\"><h3>2. \u5728LockBits~UnlockBits\u83b7\u53d6\u70b9\uff08Scan0\uff09\uff0c\u590d\u5236\u5e76\u5904\u7406\u6570\u636e\u540e\uff0c\u5982\u4f55\u6839\u636e\u7ed3\u679c\u91cd\u65b0\u590d\u5236<\/h3>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-2 > .CodeMirror, .fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-2 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:var(--awb-color3);\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_2\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_2\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_2\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-scss\">\/\/\/ <summary>\n\/\/\/ LockBits\u548cUnlockBits\u83b7\u53d6\u56fe\u50cf\u6570\u636e\u4f5c\u4e3a\u70b9\uff0c\u5e76\u6309\u6570\u7ec4\u987a\u5e8f\u5bf9\u5176\u8fdb\u884c\u5904\u7406\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"bmp\"><\/param>\nprivate void NegativeImage2(Bitmap bmp)\n{\nvar width = bmp.Width;\nvar height = bmp.Height;\n\/\/ \u628aBitmap Lock\nvar bmpData = bmp.LockBits(\nnew Rectangle(0, 0, width, height),\nSystem.Drawing.Imaging.ImageLockMode.ReadWrite,\nbmp.PixelFormat\n);\n\/\/ \u83b7\u53d6\u5185\u5b58\u5bbd\u5ea6\u7684Byte\u6570\nvar stride = Math.Abs(bmpData.Stride);\n\/\/ \u7528\u4e8e\u5b58\u50a8\u56fe\u50cf\u6570\u636e\u7684\u6570\u7ec4\nvar data = new byte[stride * bmpData.Height];\n\/\/ Bitmap\u590d\u5236\u8d44\u6599\nSystem.Runtime.InteropServices.Marshal.Copy(\nbmpData.Scan0,\ndata,\n0,\nstride * bmpData.Height\n);\nbyte r, g, b;\nint lineIndex = 0;\nfor (int y = 0; y < height; y++)\n{\nfor (int x = 0; x < width * 3; x += 3)\n{\n\/\/ \u4eae\u5ea6\u503c\u83b7\u53d6\nr = data[lineIndex + x + 2];\ng = data[lineIndex + x + 1];\nb = data[lineIndex + x]; ;\n\/\/ \u4eae\u5ea6\u503c\u8bbe\u5b9a\ndata[lineIndex + x + 2] = (byte)(255 - r);\ndata[lineIndex + x + 1] = (byte)(255 - g);\ndata[lineIndex + x] = (byte)(255 - b);\n}\nlineIndex += stride;\n}\n\/\/ \u5c06\u6570\u7ec4\u590d\u5236\u5230Bitmap\u6570\u636e\nSystem.Runtime.InteropServices.Marshal.Copy(\ndata,\n0,\nbmpData.Scan0,\nstride * bmpData.Height\n);\n\/\/ Unlock\nbmp.UnlockBits(bmpData);\n}\n\u5e73\u5747\u5904\u7406\u65f6\u95f4\u4e3a 101msec\n<\/textarea><\/div><div class=\"fusion-text fusion-text-4\"><h3>3. \u4f7f\u7528Marshal\u7c7b\u7684ReadByte\u548cWriteByte\u65b9\u6cd5,\u5c06\u503c\u76f4\u63a5\u8bfb\u53d6\u548c\u5199\u5165\u6307\u9488\uff08Scan0\uff09<\/h3>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-3 > .CodeMirror, .fusion-syntax-highlighter-3 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-3 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-3 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-3 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:var(--awb-color3);\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_3\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_3\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_3\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-scss\">\/\/\/ <summary>\n\/\/\/ \u5982\u4f55\u4f7f\u7528Marshal\u7c7b\u7684ReadByte\u548cWriteByte\u83b7\u53d6\u4eae\u5ea6\u503c\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"bmp\"><\/param>\nprivate void NegativeImage3(Bitmap bmp)\n{\nvar width = bmp.Width;\nvar height = bmp.Height;\n\/\/ Bitmap Lock\nvar bmpData = bmp.LockBits(\nnew Rectangle(0, 0, width, height),\nSystem.Drawing.Imaging.ImageLockMode.ReadWrite,\nbmp.PixelFormat\n);\n\/\/ \u83b7\u53d6\u5185\u5b58\u5bbd\u5ea6\u7684Byte\u6570\nvar stride = Math.Abs(bmpData.Stride);\nbyte r, g, b;\nint lineIndex = 0;\nvar ptr = bmpData.Scan0;\nfor (int y = 0; y < height; y++)\n{\nfor (int x = 0; x < width * 3; x += 3)\n{\n\/\/ \u83b7\u5f97\u4eae\u5ea6\u503c\nr = System.Runtime.InteropServices.Marshal.ReadByte(ptr, lineIndex + x + 2);\ng = System.Runtime.InteropServices.Marshal.ReadByte(ptr, lineIndex + x + 1);\nb = System.Runtime.InteropServices.Marshal.ReadByte(ptr, lineIndex + x);\n\/\/ \u4eae\u5ea6\u503c\u8bbe\u5b9a\nSystem.Runtime.InteropServices.Marshal.WriteByte(ptr, lineIndex + x + 2, (byte)(255 - r));\nSystem.Runtime.InteropServices.Marshal.WriteByte(ptr, lineIndex + x + 1, (byte)(255 - g));\nSystem.Runtime.InteropServices.Marshal.WriteByte(ptr, lineIndex + x, (byte)(255 - b));\n}\nlineIndex += stride;\n}\n\/\/ Unlock\nbmp.UnlockBits(bmpData);\n\n\u5e73\u5747\u5904\u7406\u65f6\u95f4\u4e3a273.6msec\n<\/textarea><\/div><div class=\"fusion-text fusion-text-5\"><h3>4. \u5982\u4f55\u76f4\u63a5\u4f7f\u7528Unsafe\u8bfb\u53d6\u548c\u5199\u5165\u6307\u9488\uff08Scan0\uff09<\/h3>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-4 > .CodeMirror, .fusion-syntax-highlighter-4 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-4 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-4 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-4 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:var(--awb-color3);\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_4\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_4\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_4\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-scss\">\/\/\/ <summary>\n\/\/\/ \u5982\u4f55\u4f7f\u7528usafe\u7684\u6307\u9488\u83b7\u53d6\u4eae\u5ea6\u503c\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"bmp\"><\/param>\nprivate void NegativeImage4(Bitmap bmp)\n{\nvar width = bmp.Width;\nvar height = bmp.Height;\n\/\/ Bitmap Lock\nvar bmpData = bmp.LockBits(\nnew Rectangle(0, 0, width, height),\nSystem.Drawing.Imaging.ImageLockMode.ReadWrite,\nbmp.PixelFormat\n);\n\/\/ \u83b7\u53d6\u5185\u5b58\u5bbd\u5ea6\u7684Byte\u6570\nvar stride = Math.Abs(bmpData.Stride);\nunsafe\n{\n\/\/\u7528\u4e8e\u5b58\u50a8\u56fe\u50cf\u6570\u636e\u7684\u6570\u7ec4\nvar ptr = (byte*)bmpData.Scan0;\nbyte r, g, b;\nbyte* pLine = ptr;\nfor (int y = 0; y < height; y++)\n{\n\/\/ \u884c\u7684\u9996\u8282\u70b9\nptr = pLine;\nfor (int x = 0; x < width; x++)\n{\n\/\/ \u4eae\u5ea6\u503c\u83b7\u53d6\nr = ptr[2];\ng = ptr[1];\nb = ptr[0];\n\/\/ \u4eae\u5ea6\u503c\u8bbe\u7f6e\nptr[2] = (byte)(255 - r);\nptr[1] = (byte)(255 - g);\nptr[0] = (byte)(255 - b);\n\/\/ \u5230\u4e0b\u4e00\u4e2a\u50cf\u7d20\nptr += 3;\n}\n\/\/\u5230\u4e0b\u4e00\u884c\npLine += stride;\n}\n}\n\/\/ Unlock\nbmp.UnlockBits(bmpData);\n}\n\u5e73\u5747\u5904\u7406\u65f6\u95f4\u4e3a25.4msec\n<\/textarea><\/div><div class=\"fusion-text fusion-text-6\"><h3>5. \u5982\u4f55\u4f7f\u7528\u6307\u9488\u8fdb\u884c\u8bfb\u5199\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528Parallel.For\u5e76\u884c\u5904\u7406<\/h3>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-5 > .CodeMirror, .fusion-syntax-highlighter-5 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-5 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-5 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-5 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:var(--awb-color3);\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_5\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_5\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_5\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-scss\">\/\/\/ <summary>\n\/\/\/ \u4f7f\u7528usafe\u4e2d\u7684\u6307\u9488\u5e76\u884c\u5316\u83b7\u53d6\u4eae\u5ea6\u503c\u7684\u8bbe\u7f6e\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"bmp\"><\/param>\nprivate void NegativeImage5(Bitmap bmp)\n{\nvar width = bmp.Width;\nvar height = bmp.Height;\n\/\/ Bitmap Lock\nvar bmpData = bmp.LockBits(\nnew Rectangle(0, 0, width, height),\nSystem.Drawing.Imaging.ImageLockMode.ReadWrite,\nbmp.PixelFormat\n);\n\/\/ \u83b7\u53d6\u5185\u5b58\u5bbd\u5ea6\u7684\u5b57\u8282\u6570\nvar stride = Math.Abs(bmpData.Stride);\nunsafe\n{\n\/\/ \u7528\u4e8e\u5b58\u50a8\u56fe\u50cf\u6570\u636e\u7684\u6570\u7ec4\nvar ptr = (byte*)bmpData.Scan0;\nParallel.For(0, height, y =>\n{\n\/\/ \u884c\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5934\u6307\u9488\nbyte* pLine = ptr + y * stride;\nfor (int x = 0; x < width; x++)\n{\n\/\/ \u4eae\u5ea6\u503c\u83b7\u53d6\nbyte r = pLine[2];\nbyte g = pLine[1];\nbyte b = pLine[0];\n\/\/ \u4eae\u5ea6\u503c\u8bbe\u5b9a\npLine[2] = (byte)(255 - r);\npLine[1] = (byte)(255 - g);\npLine[0] = (byte)(255 - b);\n\/\/ \u5230\u4e0b\u4e00\u4e2a\u50cf\u7d20\npLine += 3;\n}\n}\n);\n}\n\/\/ Unlock\nbmp.UnlockBits(bmpData);\n}\n\n\u5e73\u5747\u5904\u7406\u65f6\u95f4\u4e3a11.4msec\n<\/textarea><\/div><div class=\"fusion-text fusion-text-7\"><h3>6. \u52a0\u8f7d\u4e4b\u524d\u5904\u7406\u7684\u8d44\u6599\u5e76\u4f7f\u7528\u7684\u8f6f\u4ef6<\/h3>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-6 > .CodeMirror, .fusion-syntax-highlighter-6 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-6 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-6 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-6 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:var(--awb-color3);\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_6\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_6\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_6\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-scss\">pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;\nvar bmp = new Bitmap(@\"C:\\Temp\\syurijou.JPG\"); \/\/ 6000 x 4000 x 24bit\npictureBox1.Image = bmp;\nvar sw = new System.Diagnostics.Stopwatch();\nMessageBox.Show(\"\u5f00\u59cb\");\nsw.Start();\n\/\/ GetPixel\u3001SetPixel\nNegativeImage1(bmp);\nsw.Stop();\npictureBox1.Refresh();\nMessageBox.Show($\"NegativeImage1: {sw.ElapsedMilliseconds} msec\");\nsw.Reset();\nsw.Start();\n\/\/ \u8003\u8651\u5230\u6392\u5217\u7684\u65b9\u6cd5\nNegativeImage2(bmp);\nsw.Stop();\npictureBox1.Refresh();\nMessageBox.Show($\"NegativeImage2: {sw.ElapsedMilliseconds} msec\");\nsw.Reset();\nsw.Start();\n\/\/ Mershal\u306eReadByte\u3001WriteByte\nNegativeImage3(bmp);\nsw.Stop();\npictureBox1.Refresh();\nMessageBox.Show($\"NegativeImage3: {sw.ElapsedMilliseconds} msec\");\nsw.Reset();\nsw.Start();\n\/\/ usafe\u7684\u6307\u9488\nNegativeImage4(bmp);\nsw.Stop();\npictureBox1.Refresh();\nMessageBox.Show($\"NegativeImage4: {sw.ElapsedMilliseconds} msec\");\nsw.Reset();\nsw.Start();\n\/\/ usafe\u6307\u9488\u7684\u5e76\u884c\u5904\u7406\nNegativeImage5(bmp);\nsw.Stop();\npictureBox1.Refresh();\nMessageBox.Show($\"NegativeImage5: {sw.ElapsedMilliseconds} msec\");\n<\/textarea><\/div><\/div><\/div><\/div><\/div><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-3 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:calc( 1150px + 0px );margin-left: calc(-0px \/ 2 );margin-right: calc(-0px \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-2 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:0px;--awb-margin-bottom-large:20px;--awb-spacing-left-large:0px;--awb-width-medium:100%;--awb-spacing-right-medium:0px;--awb-spacing-left-medium:0px;--awb-width-small:100%;--awb-spacing-right-small:0px;--awb-spacing-left-small:0px;\"><div class=\"fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-8\"><h2>\u7ed3\u8bba<\/h2>\n<h3>\u6839\u636e\u5904\u7406\u65b9\u5f0f\u7684\u5904\u7406\u65f6\u95f4<\/h3>\n<p>\u6839\u636e\u5904\u7406\u65b9\u6cd5\u7684\u5904\u7406\u65f6\u95f4\u56e0\u7248\u672c\u548cBit\u800c\u5f02\uff0c\u5982\u4e0b\u6240\u793a\u3002<br \/>\n\u5f53\u8fd0\u884c32Bit\u65f6\uff0c.NET Framework\u76844.5.2\u548c4.7.2\u4e4b\u95f4\u6ca1\u6709\u663e\u7740\u5dee\u5f02\uff0c\u4f46\u662f\u5728\u76f8\u540c\u7248\u672c\u7684.NET Framework\u4e2d\u6bd4\u8f8332bit\u548c64Bit\u7684\u64cd\u4f5c\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u5f97\u7684\u7ed3\u679c\u4e3a64Bit\u66f4\u5feb\u3002<\/p>\n<ol>\n<li><strong>.NET Framework 4.5.2 &#8211; 32Bit \u57fa\u672c<br \/>\n<\/strong><\/p>\n<table style=\"border-collapse: collapse; width: 56.236%; height: 144px;\" border=\"1\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 38.7976%; background-color: #1755d1; height: 24px;\"><span style=\"color: #ffffff;\">\u65b9\u6cd5<\/span><\/td>\n<td style=\"width: 17.4384%; background-color: #1755d1; height: 24px;\"><span style=\"color: #ffffff;\">\u00a0\u5904\u7406\u65f6\u95f4 (ms)<\/span><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 38.7976%; height: 24px;\">GetPixel, SetPixel<\/td>\n<td style=\"width: 17.4384%; height: 24px;\">27,439<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 38.7976%; height: 24px;\">\u00a0\u8003\u8651\u4f7f\u7528LockBits\u548cUnlockBits\u5b89\u6392\u7684\u5904\u7406<\/td>\n<td style=\"width: 17.4384%; height: 24px;\">101<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 38.7976%; height: 24px;\">Marshal\u7cfb\u5217\u7684ReadByte, WriteByte<\/td>\n<td style=\"width: 17.4384%; height: 24px;\">273.6<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 38.7976%; height: 24px;\">Unsafe \u7528\u6307\u9488\u5904\u7406<\/td>\n<td style=\"width: 17.4384%; height: 24px;\">25.4<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 38.7976%; height: 24px;\">Unsafe\u00a0\u6307\u9488\u5e76\u884c\u5904\u7406<\/td>\n<td style=\"width: 17.4384%; height: 24px;\">11.4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li><strong>.NET Framework 4.7.2 &#8211; 32Bit \u57fa\u672c<br \/>\n<\/strong><\/p>\n<table style=\"border-collapse: collapse; width: 56.236%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 38.7976%; background-color: #1755d1;\"><span style=\"color: #ffffff;\">\u65b9\u6cd5<\/span><\/td>\n<td style=\"width: 17.4384%; background-color: #1755d1;\"><span style=\"color: #ffffff;\">\u00a0\u5904\u7406\u65f6\u95f4 (ms)<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">GetPixel, SetPixel<\/td>\n<td style=\"width: 17.4384%;\">27,293.4<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">\u00a0\u8003\u8651\u4f7f\u7528LockBits\u548cUnlockBits\u5b89\u6392\u7684\u5904\u7406<\/td>\n<td style=\"width: 17.4384%;\">101.8<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">Marshal\u7cfb\u5217\u7684ReadByte, WriteByte<\/td>\n<td style=\"width: 17.4384%;\">290.8<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">Unsafe \u7528\u6307\u9488\u5904\u7406<\/td>\n<td style=\"width: 17.4384%;\">24.4<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">Unsafe\u00a0\u6307\u9488\u5e76\u884c\u5904\u7406<\/td>\n<td style=\"width: 17.4384%;\">9.8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li><strong>.NET Framework 4.7.2 &#8211; 64bit \u57fa\u672c<\/strong><br \/>\n<table style=\"border-collapse: collapse; width: 56.236%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 38.7976%; background-color: #1755d1;\"><span style=\"color: #ffffff;\">\u65b9\u6cd5<\/span><\/td>\n<td style=\"width: 17.4384%; background-color: #1755d1;\"><span style=\"color: #ffffff;\">\u5904\u7406\u65f6\u95f4\u00a0(ms)<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">GetPixel, SetPixel<\/td>\n<td style=\"width: 17.4384%;\">21,281.2<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">\u00a0\u8003\u8651\u4f7f\u7528LockBits\u548cUnlockBits\u5b89\u6392\u7684\u5904\u7406<\/td>\n<td style=\"width: 17.4384%;\">85.4<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">Marshal\u7cfb\u5217\u7684ReadByte, WriteByte<\/td>\n<td style=\"width: 17.4384%;\">213.6<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">Unsafe\u00a0\u7528\u6307\u9488\u5904\u7406<\/td>\n<td style=\"width: 17.4384%;\">27.2<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 38.7976%;\">Unsafe\u00a0\u6307\u9488\u5e76\u884c\u5904\u7406<\/td>\n<td style=\"width: 17.4384%;\">9.2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<\/ol>\n<h3>[\u6ce8\u610f\u4e8b\u9879]<\/h3>\n<ul>\n<li>\u672c\u535a\u5ba2\u7684\u5185\u5bb9\u6458\u81ea\u603b\u90e8\u4f4d\u4e8eAVALDATA\u7684\u8f6f\u4ef6\u5de5\u7a0b\u5e08Akira Yaskawa\u8fd0\u8425\u7684\u535a\u5ba2(<a href=\"http:\/\/www.imagingsolution.net\">Imaging Solution.net<\/a>)\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605Yaskawa\u5148\u751f\u7684\u535a\u5ba2\u3002<\/li>\n<li>\u5bf9\u5171\u4eab\u6216\u5f15\u7528\u6b64\u5185\u5bb9\u6ca1\u6709\u9650\u5236\uff0c\u4f46\u8bf7\u907f\u514d\u672a\u7ecf\u6388\u6743\u7684\u590d\u5236\uff0c\u4fee\u6539\uff0c\u590d\u5236\u548c\u5546\u4e1a\u4f7f\u7528\u3002<\/li>\n<li>\u5bf9\u4e0a\u8ff0\u6750\u6599\u7684\u4f7f\u7528\u6ca1\u6709\u9650\u5236\uff0c\u4f46\u7531\u4e8e\u4f7f\u7528\u5f15\u8d77\u7684\u9519\u8bef\u7531\u7528\u6237\u8d1f\u8d23\uff0c\u56e0\u6b64\u8bf7\u52a1\u5fc5\u5c0f\u5fc3\u3002<\/li>\n<\/ul>\n<\/div><\/div><\/div><\/div><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":3,"featured_media":4831,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[245],"tags":[258],"class_list":["post-4820","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-cn","tag-c-zh"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/aval-global.com\/index.php?rest_route=\/wp\/v2\/posts\/4820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aval-global.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aval-global.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aval-global.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/aval-global.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4820"}],"version-history":[{"count":8,"href":"https:\/\/aval-global.com\/index.php?rest_route=\/wp\/v2\/posts\/4820\/revisions"}],"predecessor-version":[{"id":4836,"href":"https:\/\/aval-global.com\/index.php?rest_route=\/wp\/v2\/posts\/4820\/revisions\/4836"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aval-global.com\/index.php?rest_route=\/wp\/v2\/media\/4831"}],"wp:attachment":[{"href":"https:\/\/aval-global.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aval-global.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aval-global.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}