{"id":4194,"date":"2016-09-05T16:18:19","date_gmt":"2016-09-05T08:18:19","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4194"},"modified":"2016-09-05T16:19:34","modified_gmt":"2016-09-05T08:19:34","slug":"fmx-fmx-graphics-android-%e4%b8%ad%e5%af%b9-gif-%e5%88%a4%e6%96%ad%e7%9a%84%e9%97%ae%e9%a2%98%e7%9a%84%e4%bf%ae%e6%ad%a3","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4194","title":{"rendered":"[FMX] FMX.Graphics.Android \u4e2d\u5bf9 GIF \u5224\u65ad\u7684\u95ee\u9898\u7684\u4fee\u6b63"},"content":{"rendered":"<p style=\"text-align: justify;\">\u5173\u4e8e\u8fd9\u4e2a Bug \u7684\u8be6\u60c5\uff0c\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"https:\/\/quality.embarcadero.com\/browse\/RSP-12424\">https:\/\/quality.embarcadero.com\/browse\/RSP-12424<\/a><\/p>\n<p style=\"text-align: justify;\">Berlin \u4e2d\u7684 FMX.Graphics.Android \u5b9e\u73b0\u7684\u539f\u59cb\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">class function TBitmapCodecAndroid.IsGIFStream(const Stream: TStream): Boolean;\r\nconst\r\n  IDCharCount = 3;\r\nvar\r\n  PrevPosition: Int64;\r\n  Builder: TStringBuilder;\r\n  I: Integer;\r\n  Value: Char;\r\nbegin\r\n  if (Stream = nil) or (Stream.Size &lt; IDCharCount) then\r\n    Exit(False);\r\n\r\n  PrevPosition := Stream.Position;\r\n  try\r\n    Builder := TStringBuilder.Create(IDCharCount);\r\n    try\r\n      for I := 0 to 2 do\r\n      begin\r\n        Stream.ReadBuffer(Value, 1);\r\n        Builder.Append(Value);\r\n      end;\r\n\r\n      Result := SameText(Builder.ToString, 'GIF');\r\n    finally\r\n      Builder.Free;\r\n    end;\r\n  finally\r\n    Stream.Position := PrevPosition;\r\n  end;\r\nend;<\/pre>\n<p>\u5b58\u5728\u7684\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u7b2c\u4e00\u4e2a\u5224\u5b9a\u4e0d\u5b8c\u5584\uff0c\u6d41\u7684\u5927\u5c0f\u5927\u4e8e GIF \u5934\u90e8\u5927\u5c0f\u5e76\u4e0d\u4ee3\u8868\u5185\u5bb9\u4ece\u5f53\u524d\u4f4d\u7f6e\u8bfb\u53d6\u5269\u4f59\u7684\u5185\u5bb9\u957f\u5ea6\u5927\u4e8e3\uff0c\u6240\u4ee5\u8fd9\u5757\u5e94\u8be5\u6539\u6210\n<pre class=\"lang:delphi decode:true\">if (Stream = nil) or (Stream.Size-Stream.Position &lt; IDCharCount) then\r\n    Exit(False);<\/pre>\n<\/li>\n<li>\u53e6\u4e00\u4e2a\u95ee\u9898\u662f\u4e00\u4e2a\u4f4e\u7ea7\u7684\u95ee\u9898\uff0cChar \u7c7b\u578b\u5728 Android \u4e0a\u5bf9\u5e94\u7684\u662f WideChar\uff0c\u4e5f\u5c31\u662f\u8bf4\u662f 2 \u4e2a\u5b57\u8282\uff0c\u7136\u540e\u5b83\u6ca1\u6709\u521d\u59cb\u5316\uff0c\u76f4\u63a5\u8bfb\u53d6\u3002\u7531\u4e8e Value \u7684\u503c\u4e3a\u968f\u673a\u503c\uff0c\u6240\u4ee5\uff0c\u6709\u53ef\u80fd\u4e24\u4e2a\u5b57\u8282\u7684\u5185\u5bb9\u4e0d\u4e3a\u7a7a\uff0c\u7ed3\u679c\u5c31\u9020\u6210\u6dfb\u52a0\u65f6\u51fa\u73b0\u95ee\u9898\uff0c\u9020\u6210\u6b63\u786e\u7684GIF\u6587\u4ef6\u683c\u5f0f\u65e0\u6cd5\u8bfb\u53d6\u3002\u5b9e\u9645\u4e0a\u53ea\u9700\u8981 Value \u521d\u59cb\u4e3a 0 \u5c31\u53ef\u4ee5\u4e86\u3002<\/li>\n<li>\u5410\u4e2a\u69fd\uff1a\u8fd9\u4e48\u7b80\u5355\u5224\u5b9a\u4e3a\u5565\u8981\u7528 TStringBuilder\uff1f\u8fd9\u8ba9\u6211\u60f3\u8d77\u4e00\u4e2a\u7b11\u8bdd\uff0c\u8bf4\u662f\u4e3a\u4e86\u8ba9\u7528\u6237\u638f\u94b1\uff0c\u6545\u610f\u5728\u7a0b\u5e8f\u4e2d\u52a0\u5165 Sleep \u6765\u51cf\u6162\u7a0b\u5e8f\u7684\u901f\u5ea6\uff0c\u8fd9\u6837\u4ee5\u540e\u501f\u53e3\u4f18\u5316\u5c31\u53ef\u4ee5\u8ba9\u7528\u6237\u638f\u66f4\u591a\u7684\u94b1\u4e86\u3002\u518d\u600e\u4e48\u8bf4\uff0cTStringBuilder\u4e5f\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u800c\u4e14\u7275\u6d89\u5230\u5185\u5b58\u7684\u989d\u5916\u5206\u914d\u91ca\u653e\uff0c\u7eaf\u5c5e\u8131\u88e4\u5b50\u653e\u5c41\uff0c\u591a\u6b64\u4e00\u4e3e\u3002<\/li>\n<\/ul>\n<p>\u597d\u5427\uff0c\u518d\u8865\u5145\u4e00\u70b9\u5427\uff1aGIF \u5b9e\u9645\u4e0a\u6709\u4e24\u79cd\u5934\uff0c\u4e00\u79cd\u5934\u662f GIF89a\uff0c\u53e6\u5916\u4e00\u79cd\u662f GIF87a\uff0c\u65e0\u8bba\u90a3\u79cd\uff0c\u5934\u90e8\u5b9e\u9645\u4e0a\u662f6\u4e2a\u5b57\u8282\uff0c\u800c\u4e0d\u662f 3 \u4e2a\uff0c\u5982\u679c\u8c61\u4e0a\u9762\u53ea\u5224\u65ad GIF \uff0c\u663e\u7136\u6709\u5931\u4e25\u8c28\u3002<\/p>\n<p>\u7ed9\u4e00\u4e2a\u53c2\u8003\u7684\u4fee\u6b63\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">class function TBitmapCodecAndroid.IsGIFStream(const Stream: TStream): Boolean;\r\nconst\r\n  IDCharCount = 6;\r\n  ID_GIF89a: array [0 .. 7] of Byte = ($47, $49, $46, $38, $39, $61,$00,$00);\r\n  ID_GIF87a: array [0 .. 7] of Byte = ($47, $49, $46, $38, $37, $61,$00,$00);\r\nvar\r\n  PrevPosition: Int64;\r\n  I: Integer;\r\n  Id: Int64;\r\nbegin\r\n  if (Stream = nil) or (Stream.Size - Stream.Position &lt; IDCharCount) then\r\n    Exit(False);\r\n  PrevPosition := Stream.Position;\r\n  try\r\n    Id:=0;\r\n    Stream.ReadBuffer(Id, IDCharCount);\r\n    Result :=(Id=PInt64(@Id_GIF89a[0])^) or (Id=PInt64(@Id_GIF87a[0])^);\r\n  finally\r\n    Stream.Position := PrevPosition;\r\n  end;\r\nend;<\/pre>\n<p>\u8fd9\u91cc\u6545\u610f\u586b\u5145\u4e86ID\u52308\u4f4d\uff0c\u4ee5\u4fbf\u76f4\u63a5\u5c06 GIF \u5934\u5f53\u621064\u4f4d\u6574\u6570\u6765\u6bd4\u8f83\uff0c\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e\u8fd9\u4e2a Bug \u7684\u8be6\u60c5\uff0c\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003\uff1a [&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":[145,69,8,2],"tags":[457,149,482],"class_list":["post-4194","post","type-post","status-publish","format-standard","hentry","category-android","category-c-builder","category-delphi","category-update","tag-android","tag-fmx","tag-gif"],"views":4159,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4194","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=4194"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4194\/revisions"}],"predecessor-version":[{"id":4196,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4194\/revisions\/4196"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}