public void Set(string stream) { string label = stream.Substring(0, 2); Debug.Log("IMAGE DESCRIPTOR: " + stream); if(ImageSeperator != label) { Debug.LogError("NOT AN IMAGE SEPERATOR"); } string redrawLeftHex = stream.Substring(4, 2) + stream.Substring(2, 2); Left = GifHelper.HexToDecimal(redrawLeftHex); string redrawTopHex = stream.Substring(8, 2) + stream.Substring(6, 2); Top = GifHelper.HexToDecimal(redrawTopHex); string redrawWidthHex = stream.Substring(12, 2) + stream.Substring(10, 2); Width = GifHelper.HexToDecimal(redrawWidthHex); string redrawHeightHex = stream.Substring(16, 2) + stream.Substring(14, 2); Height = GifHelper.HexToDecimal(redrawHeightHex); string PacketField = stream.Substring(18, 2); //Debug.LogWarning("Resize Left: " + Left); //Debug.LogWarning("Resize Top: " + Top); //Debug.LogWarning("Resize Width: " + Width); //Debug.LogWarning("Resize Height: " + Height); //Debug.LogWarning("PacketField: " + PacketField); packetFieldDecrypt(PacketField); }
public void Set(string stream) { SubBlocks = new List <string>(); Debug.Log("IMAGE DATA: " + stream); int index, total, subBlockLength; string temp; LZWCompressionSize = GifHelper.HexToDecimal(stream.Substring(0, 2)); Debug.Log("LZW minimum code size: " + LZWCompressionSize); index = 2; total = 2; for (int i = 0; i < stream.Length; i++) { subBlockLength = GifHelper.HexToDecimal(stream.Substring(index, 2)) * 2; index += 2; if (subBlockLength == 0) { Debug.LogWarning("byte index in image data: " + index + " /" + stream.Length.ToString()); //Debug.Log("number of sub blocks:" + SubBlocks.Count); break; } Debug.Log("sub block length: " + subBlockLength); total += subBlockLength + 2; temp = stream.Substring(index, subBlockLength); index += subBlockLength; SubBlocks.Add(temp); //Debug.LogWarning("byte index in image data: " + index + " /" + stream.Length.ToString()); } DecryptImageData(stream); }
public Texture2D GetCachedTexture(string url) { string key = CFileManager.GetMd5(url.ToLower()); CCachedTextureInfo cachedTextureInfo = this.m_cachedTextureInfoSet.GetCachedTextureInfo(key); if (cachedTextureInfo != null) { TimeSpan span = (TimeSpan)(DateTime.Now - cachedTextureInfo.m_lastModifyTime); if (span.TotalDays < 2.0) { string filePath = CFileManager.CombinePath(s_cachedTextureDirectory, key + ".bytes"); if (!CFileManager.IsFileExist(filePath)) { return(null); } byte[] buffer = CFileManager.ReadFile(filePath); if ((buffer == null) || (buffer.Length <= 0)) { return(null); } Texture2D textured = null; if (cachedTextureInfo.m_isGif) { using (MemoryStream stream = new MemoryStream(buffer)) { return(GifHelper.GifToTexture(stream, 0)); } } textured = new Texture2D(cachedTextureInfo.m_width, cachedTextureInfo.m_height, TextureFormat.ARGB32, false); textured.LoadImage(buffer); return(textured); } } return(null); }
private static void stegImageByImageType(string path, BitArray baBits, int securityLevel) { var trimPath = path.ToLower().Trim(); // Check image type if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG { JpegHelper.StegBinary(path, baBits, securityLevel); } else if (trimPath.EndsWith(".bmp")) // BITMAP { BmpHelper.StegBinary(path, baBits, securityLevel); } else if (trimPath.EndsWith(".png")) // PNG { PngHelper.StegBinary(path, baBits, securityLevel); } else if (trimPath.EndsWith(".gif")) // GIF { GifHelper.StegBinary(path, baBits); } else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF { TifHelper.StegBinary(path, baBits, securityLevel); } else if (!string.IsNullOrEmpty(trimPath)) { MessageBox.Show("Wrong extension.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information); } }
//GIF files use LSB-First packing order so I have to account for this. private void DecryptImageData(string stream) { string builder3 = ""; string builder = ""; string number = ""; string binary = GifHelper.HexToBinary(stream); string binary2 = ""; int pixel = 0; for (int i = 0; i < binary.Length - LZWCompressionSize; i += LZWCompressionSize) { number = Convert.ToInt32(binary.Substring(i, LZWCompressionSize), 2).ToString(); binary2 += binary.Substring(i, 8) + ", "; builder += number + ", "; pixel++; } for (int i = 0; i < stream.Length - 2; i += 2) { builder3 += stream.Substring(i, 2) + " "; } Debug.Log("EST PIXELS: " + pixel); Debug.Log("IMAGE DATA SUBBLOCK 1 DATA: " + builder3); Debug.Log("IMAGE BLOCK BINARY: " + binary2); Debug.Log("IMAGE DATA DECRYPTED: " + builder); }
protected override async Task DownloadAsync( IList <ImageEntry> entries, Action <double>?onProgress = null, CancellationToken cancellationToken = default) { string filename = $"{Illust.Id}.gif"; var details = await Illust.GetAnimatedDetailAsync(cancellationToken).ConfigureAwait(false); var(relative, absolute) = WithDirectory(filename); using var fs = File.Create(absolute, 8192, FileOptions.Asynchronous); using var mms = new MemoryStream(); using (var response = await details.GetZipAsync(cancellationToken).ConfigureAwait(false)) await ReadAsync(response, mms, onProgress, cancellationToken).ConfigureAwait(false); mms.Seek(0, SeekOrigin.Begin); using (var zipArchive = new ZipArchive(mms)) await GifHelper.ComposeGifAsync(zipArchive, details.Frames.Select(x => (x.File, x.Delay)), fs, cancellationToken) .ConfigureAwait(false); await fs.FlushAsync(cancellationToken).ConfigureAwait(false); entries.Add(new(ImageType.Animated, relative) { PostOrderId = 0 });
private void packetFieldDecrypt(string input) { string packetField = GifHelper.HexToBinary(input); LocalColorTableFlag = packetField.Substring(0, 1) == "1"; InterlaceFlag = packetField.Substring(1, 1) == "1"; SortFlag = packetField.Substring(2, 1) =="1"; ResevedForFutureUse = packetField.Substring(3, 2); LocalColorTableSize = GifHelper.HexToDecimal(packetField.Substring(5, 3)); }
private void PacketField(string packetField) { packetField = GifHelper.HexToBinary(packetField); //Debug.LogWarning("GCE PACKET FIELD BINARY: " + packetField); FutureUse = GifHelper.HexToDecimal(packetField.Substring(0, 3)); DisposalMethod = GifHelper.HexToDecimal(packetField.Substring(3, 3)); UserInput = packetField.Substring(6, 1) == "1"; HasTransparency = packetField.Substring(7, 1) == "1"; }
void Start() { string path = @"F:\JoeWorkspace\UnityWorkspace\learn_wangzherongyao_code\Assets\Gif_moudle\tuzi.gif"; byte[] array = File.ReadAllBytes(path);// CFileManager.ReadFile(path); Texture2D texture2D = null; using (MemoryStream memoryStream = new MemoryStream(array)) { rawImage.texture = GifHelper.GifToTexture(memoryStream, 0); } }
public void Set(string stream) { Debug.Log("APPLICATION EXTENSION: " + stream); string extension = stream.Substring(0, 2); string label = stream.Substring(2, 2); if (label != ExtensionLabel) { Debug.LogError("NOT AN APPLICATION EXTENSION"); } BlockSize = GifHelper.HexToDecimal(stream.Substring(4, 2)); ApplicationIdentifier = GifHelper.HexToASCII(stream.Substring(6, 16)); AuthenticationCode = GifHelper.HexToASCII(stream.Substring(22, 6)); }
/// <summary> /// 获取像素的色号集 /// </summary> public byte[] GetColorNumbers() { //目标数据长度 var numbersLength = Height * Width; //Lzw解码 var colorNumbers = GifHelper.LzwDecode(LzwedColorNumberBytesRecorder.GetStream(), numbersLength); //整理交错 if (FlagInterlace) { //Debug.Log("整理交错"); colorNumbers = GifHelper.InterlaceDecode(colorNumbers, Width); } return(colorNumbers); }
private void DecodePacketField(string packetField) { //Debug.LogError("LOGICAL DESCRIPTOR PACKETFIELD: " + packetField); string binary = GifHelper.HexToBinary(packetField); HasGlobalColorTable = binary.Substring(0, 1) == "1"; IsGlobalColorTableSorted = binary.Substring(4, 1) == "1"; long resolution = Convert.ToInt64(binary.Substring(1, 3), 2); ColorResolution = (int)resolution + 1; long size = Convert.ToInt64(binary.Substring(5, 3), 2); GlobalColorTableSize = (int)(Mathf.Pow(2, size + 1) * 3); //Debug.LogError("Global Color Table Size: " + GlobalColorTableSize); }
//The likely hood of this next coding working is minimal at best but I will do my best anyways private void LZW_Decompress(string hex) { List <int> data = new List <int>(); //convert the strig data to a list of integers for (int i = 0; i < hex.Length; i += 2) { string temp = hex.Substring(i, 2); data.Add(GifHelper.HexToDecimal(temp)); } //create our dictionary or code table //our dictionary is the doce table for (int i = 0; i < 256; i++) { codeTable.Add(i, ((char)i).ToString()); } }
public void Set(string stream) { Debug.Log("LOGICAL DESCRIPTOR: " + stream); string widthHex = stream.Substring(2, 2) + stream.Substring(0, 2); string heightHex = stream.Substring(6, 2) + stream.Substring(4, 2); Width = GifHelper.HexToDecimal(widthHex); Height = GifHelper.HexToDecimal(heightHex); string BgColor = stream.Substring(10, 2); BackgroundColorIndex = GifHelper.HexToDecimal(BgColor); string AspectRatio = stream.Substring(12, 2); PixelAspectRatio = GifHelper.HexToDecimal(AspectRatio); DecodePacketField(stream.Substring(8, 2)); }
public void Set(string stream) { Debug.Log("HEADER: " + stream); //Debug.LogError("HEADER: " + stream); Signature = stream.Substring(0, 6); Version = stream.Substring(6, 6); if (GifHelper.HexToASCII(Signature) != "GIF") { Debug.LogError("NOT A GIF"); } string ASCIIVersion = GifHelper.HexToASCII(Version); if (ASCIIVersion != "89a" && ASCIIVersion != "87a") { Debug.LogError("NOT A COMPATIBLE VERSION " + ASCIIVersion); } }
public void Set(string stream) { Debug.Log("GRAPHICS CONTROL EXTENSION: " + stream); ErrorCheck(stream); string size = stream.Substring(4, 2); size = GifHelper.HexToBinary(size); BlockSize = (int)Convert.ToInt64(size, 2); string packetField = stream.Substring(6, 2); PacketField(packetField); string delay = stream.Substring(8, 4); Delay = GifHelper.HexToDecimal(delay); string transparentIndex = stream.Substring(12, 2); TransparencyIndex = GifHelper.HexToDecimal(transparentIndex); //Debug.LogWarning("GCE TRANSPARENCY INDEX: " + TransparencyIndex); }
public Texture2D GetCachedTexture(string url, float validDays) { string md = CFileManager.GetMd5(url.ToLower()); CCachedTextureInfo cachedTextureInfo = this.m_cachedTextureInfoSet.GetCachedTextureInfo(md); if (cachedTextureInfo == null || (DateTime.get_Now() - cachedTextureInfo.m_lastModifyTime).get_TotalDays() >= (double)validDays) { return(null); } string text = CFileManager.CombinePath(CCachedTextureManager.s_cachedTextureDirectory, md + ".bytes"); if (!CFileManager.IsFileExist(text)) { return(null); } byte[] array = CFileManager.ReadFile(text); if (array == null || array.Length <= 0) { return(null); } Texture2D texture2D = null; if (cachedTextureInfo.m_isGif) { using (MemoryStream memoryStream = new MemoryStream(array)) { texture2D = GifHelper.GifToTexture(memoryStream, 0); } } else { texture2D = new Texture2D(cachedTextureInfo.m_width, cachedTextureInfo.m_height, TextureFormat.ARGB32, false); texture2D.LoadImage(array); } return(texture2D); }
private void getSlotsByImageType(string imagePath) { var trimPath = imagePath.ToLower().Trim(); // Check image type if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG { // Available slots not 0 - DCT values 0 won't be overwritten var dctCoeffs = JpegHelper.GetDctCoefficients(imagePath); // 2 bits for each dct coefficient (0 values are skpped) _slots = 2 * dctCoeffs.DctFullAc.Where(s => 0 != s).Count() - HEADER_BITS_LEN; } else if (trimPath.EndsWith(".bmp")) // BITMAP { _slots = BmpHelper.GetAvailableSlots(imagePath) - HEADER_BITS_LEN; } else if (trimPath.EndsWith(".png")) // PNG { _slots = PngHelper.GetAvailableSlots(imagePath) - HEADER_BITS_LEN; } else if (trimPath.EndsWith(".gif")) // GIF { sldSecLevel.Value = 1; _slots = GifHelper.GetAvailableSlots(imagePath) - HEADER_BITS_IDX_LEN; } else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF { sldSecLevel.Value = 1; _slots = TifHelper.GetAvailableSlots(imagePath) - HEADER_BITS_IDX_LEN; } if (_slots < 10) { tbxSlots.Text = tbxSlotsUsed.Text = tbxSlotsLeft.Text = "0"; MessageBox.Show("Image not suitable for embedding content.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information); } }
public void Set(string data) { R = GifHelper.HexToDecimal(data.Substring(0, 2)); G = GifHelper.HexToDecimal(data.Substring(2, 2)); B = GifHelper.HexToDecimal(data.Substring(4, 2)); }
public static string[] SaveImageAs(this HttpPostedFile postedFile, CreateFolderMode mode, WaterMarkInfo waterMarkInfo, params ThumbnailInfo[] thumbnailInfoArray) { string[] vrtualFilePaths = new string[1 + thumbnailInfoArray.Length]; byte[] buffer = new byte[postedFile.ContentLength]; postedFile.InputStream.Read(buffer, 0, buffer.Length); if (FileValidator.ValidateImage(buffer)) { HttpContext context = HttpContext.Current; string vitualFilePath, physicalFilePath; Image image = Image.FromStream(new MemoryStream(buffer)); if (image.RawFormat.Guid == ImageFormat.Gif.Guid) { vitualFilePath = GetFilePath(postedFile, ref mode, waterMarkInfo.SavePath); physicalFilePath = context.Server.MapPath(vitualFilePath); image.Save(physicalFilePath); if (waterMarkInfo.Mode != WaterMarkInfo.ExecuteMode.Skip) { if (waterMarkInfo.Mode == WaterMarkInfo.ExecuteMode.Image) { using (Bitmap waterImg = waterMarkInfo.GetImage()) { float x = image.Width - waterImg.Width - 24F, y = image.Height - waterImg.Height - 24F; GifHelper.WaterMark(physicalFilePath, waterImg, x, y, physicalFilePath); } } else { float x = image.Width - waterMarkInfo.TextSize - 24F, y = image.Height - waterMarkInfo.TextSize - 24F; GifHelper.SmartWaterMark(physicalFilePath, waterMarkInfo.Text, ColorTranslator.FromHtml(waterMarkInfo.TextColor), new Font("宋体", waterMarkInfo.TextSize), x, y, physicalFilePath); } vrtualFilePaths[0] = vitualFilePath; } string srcPhysicalFilePath = physicalFilePath; for (int i = 0; i < thumbnailInfoArray.Length;) { ThumbnailInfo thumbnailInfo = thumbnailInfoArray[i]; vitualFilePath = GetFilePath(postedFile, ref mode, thumbnailInfo.SavePath); physicalFilePath = context.Server.MapPath(vitualFilePath); SizeF size = GDIHelper.GetProportionSize(new SizeF(thumbnailInfo.Width, thumbnailInfo.Height), image.Size); GifHelper.GetThumbnail(srcPhysicalFilePath, (double)size.Width / (double)image.Width, physicalFilePath); vrtualFilePaths[++i] = vitualFilePath; } } else { if (waterMarkInfo.Mode != WaterMarkInfo.ExecuteMode.Skip) { vitualFilePath = GetFilePath(postedFile, ref mode, waterMarkInfo.SavePath); physicalFilePath = context.Server.MapPath(vitualFilePath); if (waterMarkInfo.Mode == WaterMarkInfo.ExecuteMode.Image) { using (Bitmap waterImg = waterMarkInfo.GetImage()) { GDIHelper.MakeWaterMark(image, waterImg, ContentAlignment.BottomRight, 24); } } else { GDIHelper.MakeWaterMark(image, waterMarkInfo.Text, new Font("宋体", waterMarkInfo.TextSize), ColorTranslator.FromHtml(waterMarkInfo.TextColor), ContentAlignment.BottomRight, 24); } image.Save(physicalFilePath); vrtualFilePaths[0] = vitualFilePath; } for (int i = 0; i < thumbnailInfoArray.Length;) { ThumbnailInfo thumbnailInfo = thumbnailInfoArray[i]; vitualFilePath = GetFilePath(postedFile, ref mode, thumbnailInfo.SavePath); physicalFilePath = context.Server.MapPath(vitualFilePath); Bitmap thumbnailImg = GDIHelper.GetThumbnailImage(image, new SizeF(thumbnailInfo.Width, thumbnailInfo.Height), thumbnailInfo.Mode); thumbnailImg.Save(physicalFilePath); vrtualFilePaths[++i] = vitualFilePath; } } image.Dispose(); } return(vrtualFilePaths); }
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string gifPath = openFileDialog1.FileName; sw.Reset(); sw.Start(); switch (e.Argument.ToString()) { case "Monochrome": { GifHelper.Monochrome(pictureBox1.ImageLocation, outGifPath); break; } case "RotateLeft": { GifHelper.Rotate(pictureBox1.ImageLocation, RotateFlipType.Rotate90FlipXY, outGifPath); break; } case "RotateRight": { GifHelper.Rotate(pictureBox1.ImageLocation, RotateFlipType.Rotate270FlipXY, outGifPath); break; } case "FlipH": { GifHelper.Rotate(pictureBox1.ImageLocation, RotateFlipType.RotateNoneFlipX, outGifPath); break; } case "FlipV": { GifHelper.Rotate(pictureBox1.ImageLocation, RotateFlipType.RotateNoneFlipY, outGifPath); break; } case "Thum50%": { GifHelper.GetThumbnail(pictureBox1.ImageLocation, 0.5, outGifPath); break; } case "Thum30%": { GifHelper.GetThumbnail(pictureBox1.ImageLocation, 0.3, outGifPath); break; } case "Thum120%": { GifHelper.GetThumbnail(pictureBox1.ImageLocation, 1.2, outGifPath); break; } case "Thum150%": { GifHelper.GetThumbnail(pictureBox1.ImageLocation, 1.5, outGifPath); break; } case "WaterMark": { GifHelper.WaterMark(pictureBox1.ImageLocation, SizeMode.Large, wmText.Text, wmText.ForceColor, wmText.Font, StartX, StartY, outGifPath); break; } case "WaterMarkWithImage": { GifHelper.WaterMark(pictureBox1.ImageLocation, waterImg, StartX, StartY, outGifPath); break; } case "Corp": { GifHelper.Crop(pictureBox1.ImageLocation, new Rectangle((int)StartX, (int)StartY, (int)(EndX - StartX), (int)(EndY - StartY)), outGifPath); break; } case "Merge": { GifHelper.Merge(mf.SourceFiles, outGifPath); openFileDialog1.FileName = outGifPath; break; } case "Merge1": { GifHelper.Merge(mf.SourceFiles, outGifPath, 50, true); openFileDialog1.FileName = outGifPath; break; } } sw.Stop(); }
void bg_DoWork(object sender, DoWorkEventArgs e) { List <string> sources = GetGifFiles(dir); GifHelper.Merge(sources, outGifPath); }
void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { GifHelper.GetThumbnail(pictureBox1.ImageLocation, 0.5, thGif); }
protected async override Task <UIImage> GenerateImageAsync(string path, ImageSource source, Stream imageData, ImageInformation imageInformation, bool enableTransformations, bool isPlaceholder) { UIImage imageIn = null; if (imageData == null) { throw new ArgumentNullException(nameof(imageData)); } ThrowIfCancellationRequested(); try { // Special case to handle WebP decoding on iOS string ext = null; if (!string.IsNullOrWhiteSpace(path)) { if (source == ImageSource.Url) { ext = Path.GetExtension(new Uri(path).LocalPath).ToLowerInvariant(); } else { ext = Path.GetExtension(path).ToLowerInvariant(); } } if (source != ImageSource.Stream && ext == ".webp") { imageIn = new WebP.Touch.WebPCodec().Decode(imageData); } // Special case to handle gif animations on iOS else if (source != ImageSource.Stream && ext == ".gif") { using (var nsdata = NSData.FromStream(imageData)) imageIn = GifHelper.AnimateGif(nsdata); } else { var nsdata = NSData.FromStream(imageData); int downsampleWidth = Parameters.DownSampleSize?.Item1 ?? 0; int downsampleHeight = Parameters.DownSampleSize?.Item2 ?? 0; if (Parameters.DownSampleUseDipUnits) { downsampleWidth = downsampleWidth.PointsToPixels(); downsampleHeight = downsampleHeight.PointsToPixels(); } imageIn = nsdata.ToImage(new CoreGraphics.CGSize(downsampleWidth, downsampleHeight), ScaleHelper.Scale, NSDataExtensions.RCTResizeMode.ScaleAspectFill, imageInformation); } } finally { imageData?.Dispose(); } ThrowIfCancellationRequested(); if (enableTransformations && Parameters.Transformations != null && Parameters.Transformations.Count > 0) { var transformations = Parameters.Transformations.ToList(); await _decodingLock.WaitAsync().ConfigureAwait(false); // Applying transformations is both CPU and memory intensive try { foreach (var transformation in transformations) { ThrowIfCancellationRequested(); var old = imageIn; try { var bitmapHolder = transformation.Transform(new BitmapHolder(imageIn), path, source, isPlaceholder, Key); imageIn = bitmapHolder.ToNative(); } catch (Exception ex) { Logger.Error(string.Format("Transformation failed: {0}", transformation.Key), ex); throw; } finally { if (old != null && old != imageIn && old.Handle != imageIn.Handle) { old.Dispose(); } } } } finally { _decodingLock.Release(); } } return(imageIn); }
private void byteArrayTextConversion(byte[] byteArrayIn) { System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\Users\\Flannel\\Desktop\\ImageBytes.txt"); //general byte array in System.IO.StreamWriter file2 = new System.IO.StreamWriter("C:\\Users\\Flannel\\Desktop\\ImageBytes2.txt"); //this is the hexidecimal file string hex = ByteArrayToString(byteArrayIn); file.Write(hex); file.Close(); //this is the one that we as humans can read string hex2 = ByteArrayToStringReadable(byteArrayIn); file2.Write(hex2); file2.Close(); int myframeCount = GifHelper.findFrameCount(hex); //here we are splitting up the file for our own purposes into each associated block Header.Set(hex.Substring(0, Header.bits)); curGifByteIndex += Header.bits / 2; Debug.LogWarning("CUR INDEX: " + curGifByteIndex + "/" + (hex.Length / 2)); LogicalScreenDescriptor.Set(hex.Substring(Header.bits, LogicalScreenDescriptor.bits)); curGifByteIndex += LogicalScreenDescriptor.bits / 2; LogicalScreenDescriptor.DebugLog(); Debug.LogWarning("CUR INDEX: " + curGifByteIndex + "/" + (hex.Length / 2)); GlobalColorTable.Set(hex.Substring(curGifByteIndex * 2, LogicalScreenDescriptor.GlobalColorTableSize * 2)); curGifByteIndex += LogicalScreenDescriptor.GlobalColorTableSize; GlobalColorTable.DebugLog(); Debug.LogWarning("GLOBAL COLOR TABLE LENGTH: " + LogicalScreenDescriptor.GlobalColorTableSize); Debug.LogWarning("CUR INDEX: " + curGifByteIndex + "/" + (hex.Length / 2)); GraphicsControlExtension.Set(hex.Substring(curGifByteIndex * 2, GraphicsControlExtension.bits)); curGifByteIndex += GraphicsControlExtension.bits / 2; GraphicsControlExtension.DebugLog(); Debug.LogWarning("CUR INDEX: " + curGifByteIndex + "/" + (hex.Length / 2)); ApplicationExtensionBlock.Set(hex.Substring(curGifByteIndex * 2, ApplicationExtensionBlock.bits)); curGifByteIndex += ApplicationExtensionBlock.bits / 2; ApplicationExtensionBlock.DebugLog(); Debug.LogWarning("CUR INDEX: " + curGifByteIndex + "/" + (hex.Length / 2)); ImageDescriptor.Set(hex.Substring(curGifByteIndex * 2, ImageDescriptor.bits)); curGifByteIndex += ImageDescriptor.bits / 2; ImageDescriptor.DebugLog(); Debug.LogWarning("CUR INDEX: " + curGifByteIndex + "/" + (hex.Length / 2)); //Now that we have everything setup we are on to the drawing data int ImageDataLength = findLengthOfImageData(hex.Substring(curGifByteIndex * 2)); ImageData.Set(hex.Substring(curGifByteIndex * 2, ImageDataLength)); ImageData.bits = ImageDataLength; curGifByteIndex += ImageData.bits / 2; Debug.LogWarning("CUR INDEX: " + curGifByteIndex + "/" + (hex.Length / 2)); }
public async Task <IDecodedImage <Bitmap> > DecodeAsync(Stream stream, string path, ImageSource source, ImageInformation imageInformation, TaskParameter parameters) { var result = new DecodedImage <Bitmap>(); using (var gifDecoder = new GifHelper()) { var insampleSize = 1; // DOWNSAMPLE if (parameters.DownSampleSize != null && (parameters.DownSampleSize.Item1 > 0 || parameters.DownSampleSize.Item2 > 0)) { // Calculate inSampleSize var downsampleWidth = parameters.DownSampleSize.Item1; var downsampleHeight = parameters.DownSampleSize.Item2; if (parameters.DownSampleUseDipUnits) { downsampleWidth = downsampleWidth.DpToPixels(); downsampleHeight = downsampleHeight.DpToPixels(); } await gifDecoder.ReadHeaderAsync(stream).ConfigureAwait(false); insampleSize = BaseDecoder.CalculateInSampleSize(gifDecoder.Width, gifDecoder.Height, downsampleWidth, downsampleHeight, false); } await gifDecoder.ReadAsync(stream, insampleSize).ConfigureAwait(false); gifDecoder.Advance(); imageInformation.SetOriginalSize(gifDecoder.Width, gifDecoder.Height); if (insampleSize > 1) { imageInformation.SetCurrentSize(gifDecoder.DownsampledWidth, gifDecoder.DownsampledHeight); } else { imageInformation.SetCurrentSize(gifDecoder.Width, gifDecoder.Height); } result.IsAnimated = gifDecoder.FrameCount > 1 && Configuration.AnimateGifs; if (result.IsAnimated && Configuration.AnimateGifs) { result.AnimatedImages = new AnimatedImage <Bitmap> [gifDecoder.FrameCount]; for (var i = 0; i < gifDecoder.FrameCount; i++) { var animatedImage = new AnimatedImage <Bitmap> { Delay = gifDecoder.GetDelay(i), Image = await gifDecoder.GetNextFrameAsync() }; result.AnimatedImages[i] = animatedImage; gifDecoder.Advance(); } } else { result.IsAnimated = false; result.Image = await gifDecoder.GetNextFrameAsync(); } if (result.Image != null) { imageInformation.SetOriginalSize(result.Image.Width, result.Image.Height); imageInformation.SetCurrentSize(result.Image.Width, result.Image.Height); } else if (result.AnimatedImages != null) { if (result.AnimatedImages.Length > 0) { if (result.AnimatedImages[0].Image != null) { imageInformation.SetOriginalSize(result.AnimatedImages[0].Image.Width, result.AnimatedImages[0].Image.Height); imageInformation.SetCurrentSize(result.AnimatedImages[0].Image.Width, result.AnimatedImages[0].Image.Height); } } } return(result); } }
// Shamelessly copied from React-Native: https://github.com/facebook/react-native/blob/2cbc9127560c5f0f89ae5aa6ff863b1818f1c7c3/Libraries/Image/RCTImageUtils.m public static UIImage ToImage(this NSData data, CGSize destSize, nfloat destScale, RCTResizeMode resizeMode = RCTResizeMode.ScaleAspectFit, ImageInformation imageinformation = null, bool allowUpscale = false) { using (var sourceRef = CGImageSource.FromData(data)) { var imageProperties = GetImageProperties(sourceRef); if (imageProperties == null) { throw new BadImageFormatException("Image is null"); } if (imageinformation != null) { if (imageProperties.PixelWidth.HasValue && imageProperties.PixelHeight.HasValue) { imageinformation.SetOriginalSize(imageProperties.PixelWidth.Value, imageProperties.PixelHeight.Value); } } var sourceSize = new CGSize((nfloat)imageProperties.PixelWidth, (nfloat)imageProperties.PixelHeight); if (destSize.IsEmpty) { destSize = sourceSize; if (destScale <= 0) { destScale = 1; } } else if (destScale <= 0) { destScale = ScaleHelper.Scale; } // Calculate target size CGSize targetSize = RCTTargetSize(sourceSize, 1, destSize, destScale, resizeMode, allowUpscale); CGSize targetPixelSize = RCTSizeInPixels(targetSize, destScale); int maxPixelSize = (int)Math.Max( Math.Min(sourceSize.Width, targetPixelSize.Width), Math.Min(sourceSize.Height, targetPixelSize.Height) ); var options = new CGImageThumbnailOptions() { ShouldAllowFloat = true, CreateThumbnailWithTransform = true, CreateThumbnailFromImageAlways = true, MaxPixelSize = maxPixelSize, ShouldCache = false, }; UIImage image = null; // gif if (sourceRef.ImageCount > 1) { image = GifHelper.AnimateGif(sourceRef, destScale); } else { // Get thumbnail using (var imageRef = sourceRef.CreateThumbnail(0, options)) { if (imageRef != null) { // Return image image = new UIImage(imageRef, destScale, UIImageOrientation.Up); } } } if (imageinformation != null && image != null) { int width = (int)image.Size.Width; int height = (int)image.Size.Height; imageinformation.SetCurrentSize(width.PointsToPixels(), height.PointsToPixels()); } return(image); } }
private static StegModel unstegImageByImageType(string path) { var sm = new StegModel(); var trimPath = path.ToLower().Trim(); // Check image type if (trimPath.EndsWith(".jpg") || trimPath.EndsWith(".jpeg")) // JPEG { var stegStruct = JpegHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (trimPath.EndsWith(".bmp")) // BITMAP { var stegStruct = BmpHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (trimPath.EndsWith(".png")) // PNG { var stegStruct = PngHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (trimPath.EndsWith(".gif")) // GIF { var stegStruct = GifHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (trimPath.EndsWith(".tif") || trimPath.EndsWith(".tiff")) // TIFF { var stegStruct = TifHelper.UnstegBinary(path); sm.SecurityLevel = stegStruct.SecurityLevel; sm.TotalSize = stegStruct.TotalSize; sm.ContentFull = stegStruct.ContentFull; sm.IsFile = stegStruct.IsFile; sm.ContentSize = stegStruct.ContentSize; sm.Content = stegStruct.Content; } else if (!string.IsNullOrEmpty(trimPath)) { MessageBox.Show("Wrong extension.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information); } return(sm); }