{"id":2621,"date":"2024-09-04T13:53:57","date_gmt":"2024-09-04T05:53:57","guid":{"rendered":"https:\/\/support.foxitsoftware.cn\/?p=2621"},"modified":"2024-09-04T13:53:57","modified_gmt":"2024-09-04T05:53:57","slug":"csdk%e4%b8%ad%e7%9a%84foxit-common-bitmap%e5%a6%82%e4%bd%95%e4%b8%8esystem-drawing-bitmap%e4%ba%92%e8%bd%ac%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=2621","title":{"rendered":"C#SDK\u4e2d\u7684foxit.common.Bitmap\u5982\u4f55\u4e0eSystem.Drawing.Bitmap\u4e92\u8f6c\uff1f"},"content":{"rendered":"\n<p>\u4eceSDK 9.2\u7248\u672c\u53ca\u4ee5\u540e\u7684\u7248\u672c\u4e2d\uff0cSDK\u5404\u4e2aAPI\u4e2d\u5e38\u7528\u7684\u4f4d\u56fe\u7c7b\u4ece\u4e4b\u524d\u7684System.Drawing.Bitmap \u8f6c\u53d8\u6210 foxit.common.Bitmap\u3002\u5982\u679c\u5728\u9879\u76ee\u91cc\u5347\u7ea7SDK\uff0c\u53ef\u80fd\u4f1a\u6d89\u53ca\u8fd9\u4e24\u4e2a\u7c7b\u7684\u7c7b\u578b\u8f6c\u6362\u3002\u8f6c\u6362\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>System.Drawing.Bitmap \u8f6c foxit.common.Bitmap:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code has-body-font-family has-medium-font-size\"><code> static public System.Drawing.Bitmap FoxitBitamp2SystemBitmap(Bitmap _bitmap)\n {\n\n     System.Drawing.Imaging.PixelFormat pixel_format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;\n     switch (_bitmap.GetFormat())\n     {\n         case Bitmap.DIBFormat.e_DIBRgb :\n             pixel_format = PixelFormat.Format24bppRgb;\n             break;\n         case Bitmap.DIBFormat.e_DIBArgb:\n             pixel_format = PixelFormat.Format32bppArgb;\n             break;\n         case Bitmap.DIBFormat.e_DIB8bpp :\n             pixel_format = PixelFormat.Format8bppIndexed;\n             break;\n         case Bitmap.DIBFormat.e_DIBRgb32:\n             pixel_format =PixelFormat.Format32bppRgb;\n             break;\n         \/\/ \u6839\u636e\u9700\u8981\u6dfb\u52a0\u5176\u4ed6PixelFormat\u7684case  \n         default:\n             throw new NotSupportedException(\"Unsupported pixel format.\");\n     }\n     System.Drawing.Bitmap  bitmap = new System.Drawing.Bitmap(_bitmap.GetWidth(), _bitmap.GetHeight(), pixel_format);\n     Graphics bitmap_graphics = Graphics.FromImage(bitmap);\n     bitmap_graphics.Clear(System.Drawing.Color.White);\n     bitmap_graphics.Dispose();\n     System.Drawing.Imaging.BitmapData bitmap_data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),\n                                                                                                                     System.Drawing.Imaging.ImageLockMode.ReadWrite, pixel_format);\n     int buffer_size = _bitmap.GetPitch() * _bitmap.GetHeight();\n     byte&#91;] byte_string = new byte&#91;buffer_size];\n     System.Runtime.InteropServices.Marshal.Copy(_bitmap.GetBuffer(), byte_string, 0, buffer_size);\n     System.Runtime.InteropServices.Marshal.Copy(byte_string, 0, bitmap_data.Scan0, buffer_size);\n     bitmap.UnlockBits(bitmap_data);\n     \n     return bitmap;\n }<\/code><\/pre>\n\n\n\n<p>2. System.Drawing.Bitmap \u8f6c foxit.common.Bitmap:<\/p>\n\n\n\n<pre class=\"wp-block-code has-body-font-family has-medium-font-size\"><code>  static public Bitmap FoxitBitamp2SystemBitmap(System.Drawing.Bitmap bitmap)\n    {\n        \n        int buffer_size = CalculateStride(bitmap) * bitmap.Height;\n\n        Bitmap.DIBFormat dIBFormat = Bitmap.DIBFormat.e_DIBArgb;\n        switch (bitmap.PixelFormat )\n        {\n            case PixelFormat.Format24bppRgb:\n                dIBFormat = Bitmap.DIBFormat.e_DIBRgb;\n                break;\n            case PixelFormat.Format32bppArgb:\n                dIBFormat = Bitmap.DIBFormat.e_DIBArgb;\n                break;\n            case PixelFormat.Format8bppIndexed:\n                dIBFormat = Bitmap.DIBFormat.e_DIB8bpp;\n                break;\n            case PixelFormat.Format32bppRgb:\n                dIBFormat = Bitmap.DIBFormat.e_DIBRgb32;\n                break;\n            \/\/ \u6839\u636e\u9700\u8981\u6dfb\u52a0\u5176\u4ed6PixelFormat\u7684case  \n            default:\n                throw new NotSupportedException(\"Unsupported pixel format.\");\n        }\n        byte&#91;] byte_string = new byte&#91;buffer_size];\n        System.Drawing.Imaging.BitmapData bitmap_data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),\n                                                                                                                       System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat);\n        System.Runtime.InteropServices.Marshal.Copy(bitmap_data.Scan0, byte_string, 0, buffer_size);\n      \n        Bitmap _bitmap = new Bitmap(bitmap.Width, bitmap.Height, dIBFormat, bitmap_data.Scan0, CalculateStride(bitmap));\n bitmap.UnlockBits(bitmap_data);\n        return _bitmap;\n    }\n\n  public static int CalculateStride(System.Drawing.Bitmap bitmap)\n  {\n      int width = bitmap.Width;\n      PixelFormat format = bitmap.PixelFormat;\n\n      \/\/ \u8ba1\u7b97\u6bcf\u50cf\u7d20\u7684\u5b57\u8282\u6570  \n      int bytesPerPixel;\n      switch (format)\n      {\n          case PixelFormat.Format24bppRgb:\n              bytesPerPixel = 3;\n              break;\n          case PixelFormat.Format32bppArgb:\n              bytesPerPixel = 4;\n              break;\n          \/\/ \u6839\u636e\u9700\u8981\u6dfb\u52a0\u5176\u4ed6PixelFormat\u7684case  \n          default:\n              throw new NotSupportedException(\"Unsupported pixel format.\");\n      }\n      int stride = width * bytesPerPixel;\n \n      return stride;\n  }<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eceSDK 9.2\u7248\u672c\u53ca\u4ee5\u540e\u7684\u7248\u672c\u4e2d\uff0cSDK\u5404\u4e2aAPI\u4e2d\u5e38\u7528\u7684\u4f4d\u56fe\u7c7b\u4ece\u4e4b\u524d\u7684System.Drawing.Bit [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[],"class_list":["post-2621","post","type-post","status-publish","format-standard","hentry","category-gsdk"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","_links":{"self":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/2621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2621"}],"version-history":[{"count":4,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/2621\/revisions"}],"predecessor-version":[{"id":2678,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/2621\/revisions\/2678"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}