{"id":91,"date":"2014-08-24T01:50:42","date_gmt":"2014-08-23T17:50:42","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=91"},"modified":"2014-08-24T01:50:42","modified_gmt":"2014-08-23T17:50:42","slug":"%e5%9c%a8delphi%e4%b8%ad%e5%9f%ba%e4%ba%8e%e5%86%85%e5%ae%b9%e6%a3%80%e6%b5%8b%e5%9b%be%e7%89%87%e6%a0%bc%e5%bc%8f%ef%bc%88%e9%9d%9e%e6%89%a9%e5%b1%95%e5%90%8d%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=91","title":{"rendered":"\u5728Delphi\u4e2d\u57fa\u4e8e\u5185\u5bb9\u68c0\u6d4b\u56fe\u7247\u683c\u5f0f\uff08\u975e\u6269\u5c55\u540d\uff09"},"content":{"rendered":"<pre class=\"theme:vs2012 lang:delphi decode:true \">type\r\n  TGraphicFormat=(gfUnknown,gfBitmap,gfJpeg,gfPng,gfGif,gfMetafile,gfTga,gfPcx,gfTiff,gfIcon,gfCursor,gfIff,gfAni);\r\n\/\/\/&lt;summary&gt;\u68c0\u6d4b\u56fe\u7247\u683c\u5f0f&lt;\/summary&gt;\r\n\/\/\/&lt;params&gt;\r\n\/\/\/ &lt;param name=\"AStream\"&gt;\u8981\u68c0\u6d4b\u7684\u56fe\u7247\u6570\u636e\u6d41&lt;\/param&gt;\r\n\/\/\/&lt;\/params&gt;\r\n\/\/\/&lt;returns&gt;\u8fd4\u56de\u53ef\u4ee5\u8bc6\u522b\u7684\u56fe\u7247\u683c\u5f0f\u4ee3\u7801&lt;\/returns&gt;\r\n \r\nfunction DetectImageFormat(AStream:TStream):TGraphicFormat;overload;\r\nvar\r\n  ABuf:array[0..7] of Byte;\r\n  ARealType:String;\r\n  AReaded:Integer;\r\nbegin\r\nFillChar(ABuf,8,0);\r\nAReaded:=AStream.Read(ABuf[0],8);\r\nAStream.Seek(-AReaded,soFromCurrent);\/\/\u56de\u5230\u539f\u59cb\u4f4d\u7f6e\r\nif (ABuf[0]=$ff) and (ABuf[1]=$d8) then\/\/JPEG\u6587\u4ef6\u5934\u6807\u8bc6 (2 bytes): $ff, $d8 (SOI) (JPEG \u6587\u4ef6\u6807\u8bc6)\r\n  Result:=gfJpeg\r\nelse if (ABuf[0]=$89) and (ABuf[1]=$50) and (ABuf[2]=$4E) and (ABuf[3]=$47) and (ABuf[4]=$0D) and (ABuf[5]=$0A) and (ABuf[6]=$1A) and (ABuf[7]=$0A) then\r\n  Result:=gfPng\/\/3.PNG\u6587\u4ef6\u5934\u6807\u8bc6 (8 bytes)   89 50 4E 47 0D 0A 1A 0A\r\nelse if (ABuf[0]=$42) and (ABuf[1]=$4D) then\r\n  Result:=gfBitmap\r\nelse if (ABuf[0]=$47) and (ABuf[1]=$49) and (ABuf[2]=$46) and (ABuf[3]=$38) and (ABuf[4] in [$37,$39]) and (ABuf[5]=$61) then\r\n  Result:=gfGif\/\/GIF- \u6587\u4ef6\u5934\u6807\u8bc6 (6 bytes)   47 49 46 38 39(37) 61 G   I   F     8   9 (7)     a\r\nelse if (ABuf[0]=$01) and (ABuf[1]=$00) and (ABuf[2]=$00) and (ABuf[3] =$00) then\r\n  Result:=gfMetafile\/\/EMF 01 00 00 00\r\nelse if (ABuf[0]=$01) and (ABuf[1]=$00) and (ABuf[2]=$09) and (ABuf[3] =$00) and (ABuf[4]=$00) and (ABuf[5]=$03) then\r\n  Result:=gfMetafile\/\/WMF 01 00 09 00 00 03\r\nelse if (ABuf[0]=$00) and (ABuf[1]=$00) and ((ABuf[2]=$02) or (ABuf[2]=$10)) and (ABuf[3]=$00) and (ABuf[4]=$00) then\r\n  Result:=gfTga\/\/TGA- \u672a\u538b\u7f29\u7684\u524d5\u5b57\u8282   00 00 02 00 00,RLE\u538b\u7f29\u7684\u524d5\u5b57\u8282   00 00 10 00 00\r\nelse if (ABuf[0]=$0A) then\r\n  Result:=gfPcx \/\/PCX - \u6587\u4ef6\u5934\u6807\u8bc6 (1 bytes)   0A\r\nelse if ((ABuf[0]=$4D) and (ABuf[1]=$4D)) or ((ABuf[0]=$49) and (ABuf[1]=$49)) then\r\n  Result:=gfTiff\/\/TIFF  - \u6587\u4ef6\u5934\u6807\u8bc6 (2 bytes)   4D 4D \u6216 49 49\r\nelse if (ABuf[0]=$00) and (ABuf[1]=$00) and (ABuf[2]=$01) and (ABuf[3]=$00)\r\n  and (ABuf[4]=$01) and (ABuf[5]=$00) and (ABuf[6]=$20) and (ABuf[7]=$20) then\r\n  Result:=gfIcon\/\/ICO - \u6587\u4ef6\u5934\u6807\u8bc6 (8 bytes)   00 00 01 00 01 00 20 20\r\nelse if (ABuf[0]=$00) and (ABuf[1]=$00) and (ABuf[2]=$02) and (ABuf[3]=$00)\r\n  and (ABuf[4]=$01) and (ABuf[5]=$00) and (ABuf[6]=$20) and (ABuf[7]=$20) then\r\n  Result:=gfCursor\/\/CUR - \u6587\u4ef6\u5934\u6807\u8bc6 (8 bytes)   00 00 02 00 01 00 20 20\r\nelse if (ABuf[0]=$46) and (ABuf[1]=$4F) and (ABuf[2]=$52) and (ABuf[3]=$4D) then\r\n  Result:=gfIFF\/\/IFF - \u6587\u4ef6\u5934\u6807\u8bc6 (4 bytes)   46 4F 52 4D(FORM)\r\nelse if (ABuf[0]=$52) and (ABuf[1]=$49) and (ABuf[2]=$46) and (ABuf[3]=$46) then\r\n  Result:=gfAni\/\/11.ANI- \u6587\u4ef6\u5934\u6807\u8bc6 (4 bytes)   52 49 46 46(RIFF)\r\nelse\r\n  Result:=gfUnknown;\r\nend;\r\n\/\/\/&lt;summary&gt;\u68c0\u6d4b\u56fe\u7247\u683c\u5f0f&lt;\/summary&gt;\r\n\/\/\/&lt;params&gt;\r\n\/\/\/ &lt;param name=\"AFileName\"&gt;\u8981\u68c0\u6d4b\u7684\u56fe\u7247\u6587\u4ef6\u540d&lt;\/param&gt;\r\n\/\/\/&lt;\/params&gt;\r\n\/\/\/&lt;returns&gt;\u8fd4\u56de\u53ef\u4ee5\u8bc6\u522b\u7684\u56fe\u7247\u683c\u5f0f\u4ee3\u7801&lt;\/returns&gt;\r\nfunction DetectImageFormat(AFileName:String):TGraphicFormat;overload;\r\nvar\r\n  AStream:TStream;\r\nbegin\r\nAStream:=TFileStream.Create(AFileName,fmOpenRead or fmShareDenyWrite);\r\ntry\r\n  Result:=DetectImageFormat(AStream);\r\nfinally\r\n  FreeAndNil(AStream);\r\nend;\r\nend;<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #454545;\">\u8fd9\u4e2a\u4e24\u4e2a\u51fd\u6570\u53ea\u7528\u4e8e\u68c0\u6d4b\u683c\u5f0f\uff0c\u5177\u4f53\u52a0\u8f7d\uff0c\u9700\u8981\u4f60\u521b\u5efa\u652f\u6301\u76f8\u5e94\u7c7b\u578b\u7684\u6587\u4ef6\u5b9e\u4f8b\uff0c\u7136\u540e\u52a0\u8f7d\u3002\u5c31\u4e0d\u5199\u793a\u4f8b\u4e86\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>type TGraphicFormat= [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8],"tags":[22,23,24],"class_list":["post-91","post","type-post","status-publish","format-standard","hentry","category-delphi","tag-22","tag-23","tag-24"],"views":4128,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/91","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=91"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions"}],"predecessor-version":[{"id":92,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions\/92"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}