|
@@ -98,36 +98,36 @@ namespace TEAMModelOS.SDK.Extension
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 判斷圖片格式
|
|
/// 判斷圖片格式
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="fileStream"></param>
|
|
|
|
|
|
+ /// <param name="stream">傳入Stream,注意請自行釋放</param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public static (bool, string) ImageValidateByStream(Stream fileStream)
|
|
|
|
|
|
+ public static (bool, string) ImageValidateByStream(Stream stream)
|
|
{
|
|
{
|
|
- using (BinaryReader br = new BinaryReader(fileStream))
|
|
|
|
|
|
+ int length = 20;
|
|
|
|
+ BinaryReader br = new BinaryReader(stream);
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
+ while (length > 0)
|
|
{
|
|
{
|
|
- int length = 20;
|
|
|
|
- StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
- while (length > 0)
|
|
|
|
- {
|
|
|
|
- byte tempByte = br.ReadByte();
|
|
|
|
- stringBuilder.Append(Convert.ToString(tempByte, 16));
|
|
|
|
- stringBuilder.Append(",");
|
|
|
|
- length--;
|
|
|
|
- }
|
|
|
|
- string fileheader = stringBuilder.ToString().ToUpper();
|
|
|
|
- if (string.IsNullOrWhiteSpace(fileheader))
|
|
|
|
- return (false, "");
|
|
|
|
-
|
|
|
|
- if (fileheader.StartsWith("FF,D8,") || fileheader.StartsWith("42,4D,"))
|
|
|
|
- return (true, "jpg");
|
|
|
|
- if (fileheader.StartsWith("89,50,4E,47,D,A,1A,A,"))
|
|
|
|
- return (true, "png");
|
|
|
|
- if (fileheader.StartsWith("47,49,46,38,39,61,") || fileheader.StartsWith("47,49,46,38,37,61,"))
|
|
|
|
- return (true, "gif");
|
|
|
|
- //if (fileheader.StartsWith("4D,4D") || fileheader.StartsWith("49,49") || fileheader.StartsWith("46,4F,52,4D"))
|
|
|
|
- // return (true, "tif");
|
|
|
|
- return (false, "");
|
|
|
|
|
|
+ byte tempByte = br.ReadByte();
|
|
|
|
+ stringBuilder.Append(Convert.ToString(tempByte, 16));
|
|
|
|
+ stringBuilder.Append(",");
|
|
|
|
+ length--;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ stream.Position = 0; //指針回歸為0
|
|
|
|
+ string fileheader = stringBuilder.ToString().ToUpper();
|
|
|
|
+ if (string.IsNullOrWhiteSpace(fileheader))
|
|
|
|
+ return (false, "");
|
|
|
|
+
|
|
|
|
+ if (fileheader.StartsWith("FF,D8,") || fileheader.StartsWith("42,4D,"))
|
|
|
|
+ return (true, "jpg");
|
|
|
|
+ if (fileheader.StartsWith("89,50,4E,47,D,A,1A,A,"))
|
|
|
|
+ return (true, "png");
|
|
|
|
+ if (fileheader.StartsWith("47,49,46,38,39,61,") || fileheader.StartsWith("47,49,46,38,37,61,"))
|
|
|
|
+ return (true, "gif");
|
|
|
|
+ //if (fileheader.StartsWith("4D,4D") || fileheader.StartsWith("49,49") || fileheader.StartsWith("46,4F,52,4D"))
|
|
|
|
+ // return (true, "tif");
|
|
|
|
+ return (false, "");
|
|
|
|
+
|
|
|
|
+ }
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
|