/// <summary> /// Construct picture information from its parts /// </summary> /// <param name="tagType">Type of the containing tag (see static fields in <see cref="ATL.AudioData.MetaDataIOFactory"/></param> /// <param name="nativePicCode">Native code of the picture, as stated in its containing format's specs</param> /// <param name="position">Position of the picture among the other pictures of the same file (default : 1)</param> public PictureInfo(int tagType, object nativePicCode, int position = 1) { PicType = PIC_TYPE.Unsupported; NativeFormat = ImageFormat.Undefined; TagType = tagType; Position = position; string picCodeStr = nativePicCode as string; if (picCodeStr != null) { NativePicCodeStr = picCodeStr; NativePicCode = -1; } else if (nativePicCode is byte) { NativePicCode = (byte)nativePicCode; } else if (nativePicCode is int) { NativePicCode = (int)nativePicCode; } else { LogDelegator.GetLogDelegate()(Log.LV_WARNING, "nativePicCode type is not supported; expected byte, int or string; found " + nativePicCode.GetType().Name); } }
/// <summary> /// Construct picture information from its parts /// </summary> /// <param name="picType">Type of the picture</param> /// <param name="tagType">Type of the containing tag (see static fields in <see cref="ATL.AudioData.MetaDataIOFactory"/></param> /// <param name="nativePicCode">Native code of the picture, as stated in its containing format's specs</param> /// <param name="position">Position of the picture among the other pictures of the same file</param> /// <param name="binaryData">Raw binary data of the picture</param> private PictureInfo(PIC_TYPE picType, int tagType, object nativePicCode, int position, byte[] binaryData) { PicType = picType; TagType = tagType; Position = position; string picCodeStr = nativePicCode as string; if (picCodeStr != null) { NativePicCodeStr = picCodeStr; NativePicCode = -1; } else if (nativePicCode is byte) { NativePicCode = (byte)nativePicCode; } else if (nativePicCode is int) { NativePicCode = (int)nativePicCode; } else { LogDelegator.GetLogDelegate()(Log.LV_WARNING, "nativePicCode type is not supported; expected byte, int or string; found " + nativePicCode.GetType().Name); } PictureData = binaryData; NativeFormat = ImageUtils.GetImageFormatFromPictureHeader(PictureData); }
/// <summary> /// Construct picture information from its raw, binary data /// </summary> /// <param name="stream">Stream containing raw picture data, positioned at the beginning of picture data</param> /// <param name="length">Length of the picture data to read inside the given stream</param> /// <param name="picType">Type of the picture (default : Generic)</param> /// <param name="tagType">Type of the containing tag (see static fields in <see cref="ATL.AudioData.MetaDataIOFactory"/>(default : TAG_ANY)</param> /// <param name="nativePicCode">Native code of the picture, as stated in its containing format's specs (default : not set)</param> /// <param name="position">Position of the picture among the other pictures of the same file (default : 1)</param> /// <returns></returns> public static PictureInfo fromBinaryData(Stream stream, int length, PIC_TYPE picType, int tagType, object nativePicCode, int position = 1) { if (null == stream || length < 3) { throw new ArgumentException("Stream should not be null and be at least 3 bytes long"); } byte[] data = new byte[length]; stream.Read(data, 0, length); return(new PictureInfo(picType, tagType, nativePicCode, position, data)); }
// ---------------- STATIC CONSTRUCTORS /// <summary> /// Construct picture information from its raw, binary data /// </summary> /// <param name="data">Raw picture data</param> /// <param name="picType">Type of the picture (default : Generic)</param> /// <param name="tagType">Type of the containing tag (see static fields in <see cref="ATL.AudioData.MetaDataIOFactory"/>(default : TAG_ANY)</param> /// <param name="nativePicCode">Native code of the picture, as stated in its containing format's specs (default : not set)</param> /// <param name="position">Position of the picture among the other pictures of the same file (default : 1)</param> /// <returns></returns> public static PictureInfo fromBinaryData(byte[] data, PIC_TYPE picType = PIC_TYPE.Generic, int tagType = TAG_ANY, object nativePicCode = null, int position = 1) { if (null == data || data.Length < 3) { throw new ArgumentException("Data should not be null and be at least 3 bytes long"); } if (null == nativePicCode) { nativePicCode = 0; // Can't default with 0 in params declaration } return(new PictureInfo(picType, tagType, nativePicCode, position, data)); }
// ---------------- CONSTRUCTORS public PictureInfo(PictureInfo picInfo, bool copyPictureData = true) { this.PicType = picInfo.PicType; this.NativeFormat = picInfo.NativeFormat; this.Position = picInfo.Position; this.TagType = picInfo.TagType; this.NativePicCode = picInfo.NativePicCode; this.NativePicCodeStr = picInfo.NativePicCodeStr; this.Description = picInfo.Description; if (copyPictureData && picInfo.PictureData != null) { this.PictureData = new byte[picInfo.PictureData.Length]; picInfo.PictureData.CopyTo(this.PictureData, 0); } this.PictureHash = picInfo.PictureHash; this.MarkedForDeletion = picInfo.MarkedForDeletion; this.TransientFlag = picInfo.TransientFlag; }
// ---------------- CONSTRUCTORS public PictureInfo(PictureInfo picInfo, Boolean copyPictureData = true) { PicType = picInfo.PicType; NativeFormat = picInfo.NativeFormat; Position = picInfo.Position; TagType = picInfo.TagType; NativePicCode = picInfo.NativePicCode; NativePicCodeStr = picInfo.NativePicCodeStr; Description = picInfo.Description; if (copyPictureData && picInfo.PictureData != null) { PictureData = new Byte[picInfo.PictureData.Length]; picInfo.PictureData.CopyTo(PictureData, 0); } PictureHash = picInfo.PictureHash; MarkedForDeletion = picInfo.MarkedForDeletion; Flag = picInfo.Flag; }
public PictureInfo(ImageFormat nativeFormat, PIC_TYPE picType, int tagType, object nativePicCode, int position = 1) { PicType = picType; NativeFormat = nativeFormat; TagType = tagType; Position = position; if (nativePicCode is string) { NativePicCodeStr = (string)nativePicCode; NativePicCode = -1; } else if (nativePicCode is byte) { NativePicCode = (byte)nativePicCode; } else if (nativePicCode is int) { NativePicCode = (int)nativePicCode; } else { LogDelegator.GetLogDelegate()(Log.LV_WARNING, "nativePicCode type is not supported; expected byte, int or string; found " + nativePicCode.GetType().Name); } }
public PictureInfo(ImageFormat nativeFormat, Int32 tagType, Object nativePicCode, Int32 position = 1) { PicType = PIC_TYPE.Unsupported; NativeFormat = nativeFormat; TagType = tagType; Position = position; if (nativePicCode is String) { NativePicCodeStr = (String)nativePicCode; NativePicCode = -1; } else if (nativePicCode is Byte) { NativePicCode = (Byte)nativePicCode; } else if (nativePicCode is Int32) { NativePicCode = (Int32)nativePicCode; } else { LogDelegator.GetLogDelegate()(Log.LV_WARNING, "nativePicCode type is not supported; expected byte, int or string; found " + nativePicCode.GetType().Name); } }
private bool Init(string strFileName, PIC_TYPE pictype, Test3DEngine engine, bool bForceRefresh) { m_forceRefresh = bForceRefresh; this.time = File.GetLastWriteTime(strFileName); this.sprFileName = strFileName; string strExt = Enum.GetName(typeof(PIC_TYPE), pictype).ToLower(); this.cachePath = string.Format(@"{0}\_cache\{1}\", Application.StartupPath, strExt); this.tgaFolderName = this.cachePath; this.tgaFileName = string.Format("{0}{1}", this.cachePath, ConverFileName(strFileName)); if (!Directory.Exists(cachePath)) { Directory.CreateDirectory(cachePath); } int nFrameCount = 0; //GetFrameCount(strFileName) 思豪的获取帧总数的函数 strFileName = strFileName.ToLower(); if (strFileName.EndsWith(".mdl") || strFileName.EndsWith(".mesh")) { nFrameCount = 1; } else if (strFileName.EndsWith(".ani") || strFileName.EndsWith(".tani")) { nFrameCount = 20; } for (int i = 1; i <= nFrameCount; i++) { string ii = i.ToString(); while (ii.Length < 3) { ii = "0" + ii; } TGAList[i.ToString()] = string.Format("{0}{1}.JPG", this.tgaFileName, ii); } string imageFileName = string.Format("{0}001.jpg", tgaFileName); switch (FileChanged()) { case -1: { Image image = Helper.GetHelper().GetImageFromCache(GetTGAFileName(), "TGA"); if (image != null) { if (!File.Exists(imageFileName)) { File.Create(imageFileName).Close(); if (saveImageTable[imageFileName] == null) { try { image.Save(imageFileName, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (ExternalException ex) { Helper.GetHelper().RecordLog(string.Format("保存图片文件{0}错误:{1}", imageFileName, ex.Message)); } finally { saveImageTable[imageFileName] = "1"; } } } } iconImage = image; break; } case 0: { if (!File.Exists(imageFileName)) // 本地图片文件不存在的话需要创建出来 { Image image = Helper.GetHelper().GetImageFromCache(GetTGAFileName(), "TGA"); if (image != null) { File.Create(imageFileName).Close(); if (saveImageTable[imageFileName] == null) { try { image.Save(imageFileName, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (ExternalException ex) { ; } finally { saveImageTable[imageFileName] = "1"; } } } iconImage = image; } break; } case 1: { try { engine.FileToImage(strFileName, this.tgaFileName); } catch(Exception ex) { Helper.GetHelper().RecordLog(string.Format("保存图片文件{0}错误:{1}", imageFileName, ex.Message)); } finally { saveImageTable[imageFileName] = "1"; } Helper.GetHelper().UpdateIcon(GetTGAFileName(), "TGA", imageFileName, GetLastWriteTime()); break; } } return true; }
public SPRItem(string strFileName, PIC_TYPE pictype, Test3DEngine engine, bool bForceRefresh) { Init(strFileName, pictype, engine, bForceRefresh); }
//for other public SPRItem(string strFileName, PIC_TYPE pictype, Test3DEngine engine) { Init(strFileName, pictype, engine, false); }
private bool Init(string strFileName, PIC_TYPE pictype, Test3DEngine engine, bool bForceRefresh) { m_forceRefresh = bForceRefresh; this.time = File.GetLastWriteTime(strFileName); this.sprFileName = strFileName; string strExt = Enum.GetName(typeof(PIC_TYPE), pictype).ToLower(); this.cachePath = string.Format(@"{0}\_cache\{1}\", Application.StartupPath, strExt); this.tgaFolderName = this.cachePath; this.tgaFileName = string.Format("{0}{1}", this.cachePath, ConverFileName(strFileName)); if (!Directory.Exists(cachePath)) { Directory.CreateDirectory(cachePath); } int nFrameCount = 0; //GetFrameCount(strFileName) 思豪的获取帧总数的函数 strFileName = strFileName.ToLower(); if (strFileName.EndsWith(".mdl") || strFileName.EndsWith(".mesh")) { nFrameCount = 1; } else if (strFileName.EndsWith(".ani") || strFileName.EndsWith(".tani")) { nFrameCount = 20; } for (int i = 1; i <= nFrameCount; i++) { string ii = i.ToString(); while (ii.Length < 3) { ii = "0" + ii; } TGAList[i.ToString()] = string.Format("{0}{1}.JPG", this.tgaFileName, ii); } string imageFileName = string.Format("{0}001.jpg", tgaFileName); switch (FileChanged()) { case -1: { Image image = Helper.GetHelper().GetImageFromCache(GetTGAFileName(), "TGA"); if (image != null) { if (!File.Exists(imageFileName)) { File.Create(imageFileName).Close(); if (saveImageTable[imageFileName] == null) { try { image.Save(imageFileName, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (ExternalException ex) { Helper.GetHelper().RecordLog(string.Format("保存图片文件{0}错误:{1}", imageFileName, ex.Message)); } finally { saveImageTable[imageFileName] = "1"; } } } } iconImage = image; break; } case 0: { if (!File.Exists(imageFileName)) // 本地图片文件不存在的话需要创建出来 { Image image = Helper.GetHelper().GetImageFromCache(GetTGAFileName(), "TGA"); if (image != null) { File.Create(imageFileName).Close(); if (saveImageTable[imageFileName] == null) { try { image.Save(imageFileName, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (ExternalException ex) { ; } finally { saveImageTable[imageFileName] = "1"; } } } iconImage = image; } break; } case 1: { try { engine.FileToImage(strFileName, this.tgaFileName); } catch (Exception ex) { Helper.GetHelper().RecordLog(string.Format("保存图片文件{0}错误:{1}", imageFileName, ex.Message)); } finally { saveImageTable[imageFileName] = "1"; } Helper.GetHelper().UpdateIcon(GetTGAFileName(), "TGA", imageFileName, GetLastWriteTime()); break; } } return(true); }
public PictureInfo(ImageFormat nativeFormat, Int32 tagType, Byte nativePicCode, Int32 position = 1) { PicType = PIC_TYPE.Unsupported; NativePicCode = nativePicCode; NativeFormat = nativeFormat; TagType = tagType; Position = position; }
public PictureInfo(ImageFormat nativeFormat, PIC_TYPE picType, int position = 1) { PicType = picType; NativeFormat = nativeFormat; Position = position; }
/// <summary> /// Construct picture information from its parts /// </summary> /// <param name="picType">Type of the picture</param> /// <param name="position">Position of the picture among the other pictures of the same file (default : 1)</param> public PictureInfo(PIC_TYPE picType, int position = 1) { PicType = picType; NativeFormat = ImageFormat.Undefined; Position = position; }
public PictureInfo(ImageFormat nativeFormat, int tagType, string nativePicCode, int position = 1) { PicType = PIC_TYPE.Unsupported; NativePicCodeStr = nativePicCode; NativePicCode = -1; NativeFormat = nativeFormat; TagType = tagType; Position = position; }