SwfTagData ISwfTagVisitor <ISwfStreamWriter, SwfTagData> .Visit(DefineBitsJPEG3Tag tag, ISwfStreamWriter writer) { writer.WriteUInt16(tag.CharacterID); writer.WriteUInt32((uint)tag.ImageData.Length); writer.WriteBytes(tag.ImageData); writer.WriteBytes(tag.BitmapAlphaData); return(null); }
SwfTagBase ISwfTagVisitor <ISwfStreamReader, SwfTagBase> .Visit(DefineBitsJPEG3Tag tag, ISwfStreamReader reader) { tag.CharacterID = reader.ReadUInt16(); var alphaDataOffset = reader.ReadUInt32(); tag.ImageData = reader.ReadBytes((int)alphaDataOffset); tag.BitmapAlphaData = reader.ReadRest(); return(tag); }
private ImageData GetDefineBitsJPEG3ImageData(DefineBitsJPEG3Tag defineBitsJPEG3) { var imageData = new ImageData(); imageData.characterID = defineBitsJPEG3.characterID; bool isJpg = defineBitsJPEG3.imageData[0] == 0xFF && (defineBitsJPEG3.imageData[1] == 0xD8 || defineBitsJPEG3.imageData[1] == 0xD9); bool isPng = defineBitsJPEG3.imageData[0] == 0x89 && defineBitsJPEG3.imageData[1] == 0x50 && defineBitsJPEG3.imageData[2] == 0x4E && defineBitsJPEG3.imageData[3] == 0x47 && defineBitsJPEG3.imageData[4] == 0x0D && defineBitsJPEG3.imageData[5] == 0x0A && defineBitsJPEG3.imageData[6] == 0x1A && defineBitsJPEG3.imageData[7] == 0x0A; bool isGif = defineBitsJPEG3.imageData[0] == 0x47 && defineBitsJPEG3.imageData[1] == 0x49 && defineBitsJPEG3.imageData[2] == 0x46 && defineBitsJPEG3.imageData[3] == 0x38 && defineBitsJPEG3.imageData[4] == 0x39 && defineBitsJPEG3.imageData[5] == 0x61; if (isPng) { imageData.type = ImageType.Png; var texture = new Texture2D(16, 16); //宽高可以任意LoadImage()时会自动调整 texture.LoadImage(defineBitsJPEG3.imageData); texture.Apply(); var colors = texture.GetPixels32(); var len = defineBitsJPEG3.bitmapAlphaData.Length; var alphaData = new byte[len]; Array.Copy(defineBitsJPEG3.bitmapAlphaData, alphaData, len); FlipVerticalBitmapAlphaData(alphaData, (ushort)texture.width, (ushort)texture.height); for (var i = 0; i < len; i++) { colors[i].a = alphaData[i]; } texture.SetPixels32(colors); texture.Apply(); imageData.bytes = texture.EncodeToJPG(100); } else if (isJpg || isGif) { imageData.type = ImageType.Jpg; //.gif也导出为jpg imageData.bytes = defineBitsJPEG3.imageData; } return(imageData); }
ITagFormatter ISwfTagVisitor <object, ITagFormatter> .Visit(DefineBitsJPEG3Tag tag, object arg) { return(new DefineBitsJPEG3TagFormatter()); }