public void loadImage() { gifImage = ByteArrayToImage(www.bytes); if (gifImage == null) { return; } debugText.text = "Creating Image"; var dimension = new System.Drawing.Imaging.FrameDimension(gifImage.FrameDimensionsList[0]); int frameCount = gifImage.GetFrameCount(dimension); for (int i = 0; i < frameCount; i++) { gifImage.SelectActiveFrame(dimension, i); var frame = new System.Drawing.Bitmap(gifImage.Width, gifImage.Height); System.Drawing.Graphics.FromImage(frame).DrawImage(gifImage, System.Drawing.Point.Empty); Texture2D frameTexture = new Texture2D(frame.Width, frame.Height); //Debug.logger.Log("width: " + frame.Width + " height: " + frame.Height + " frame count: " + frameCount + " total: " + (frame.Width * frame.Height * frameCount)); for (int x = 0; x < frame.Width; x++) { for (int y = 0; y < frame.Height; y++) { System.Drawing.Color sourceColor = frame.GetPixel(x, y); frameTexture.SetPixel(frame.Width - 1 + x, -y, new Color32(sourceColor.R, sourceColor.G, sourceColor.B, sourceColor.A)); // for some reason, x is flipped } } frameTexture.Apply(); gifFrames.Add(frameTexture); } debugText.text = "Created Image"; canOnGUI = true; }
public static void StartScreen() { Console.Title = "FROGGER by Serpent Fly\u2122"; Console.CursorVisible = false; Image Picture = Image.FromFile(@"..\..\startscreen.png"); //Console.SetWindowSize(140, 49); //Console.SetBufferSize((Picture.Width * 0x2), (Picture.Height * 0x2)); FrameDimension Dimension = new FrameDimension(Picture.FrameDimensionsList[0x0]); int FrameCount = Picture.GetFrameCount(Dimension); int Left = Console.WindowLeft, Top = Console.WindowTop; char[] Chars = { '#', '#', '@', '%', '=', '+', '*', ':', '-', '.', ' ' }; Picture.SelectActiveFrame(Dimension, 0x0); for (int i = 0x0; i < Picture.Height; i++) { for (int x = 0x0; x < Picture.Width; x++) { Color Color = ((Bitmap)Picture).GetPixel(x, i); int Gray = (Color.R + Color.G + Color.B) / 0x3; int Index = (Gray * (Chars.Length - 0x1)) / 0xFF; Console.Write(Chars[Index]); } Console.Write('\n'); } Console.SetCursorPosition(Left, Top); //Console.Read(); }
public bool addFrameToSpriteSheet(String filename) { //Create Frame from filename Image img1 = Image.FromFile(filename); // //Trick to allow Annimated Gif importation // FrameDimension dimension = new FrameDimension(img1.FrameDimensionsList[0]); // Get Frame count of Image File int frameCount = img1.GetFrameCount(dimension); // Browse frame list for (int i = 0; i < frameCount; i++) { // Select current frame img1.SelectActiveFrame(dimension, i); // Add normaly the image to the spritesheet Image img = new Bitmap(img1); SpriteFrame newFrame = new SpriteFrame(filename, this.sheet.Frames.Count, img, sheet); this.sheet.Frames.Add(newFrame); } //Clean img1.Dispose(); return true; }
public static string[] ConvertTiffToJpeg(string fileName) { using (Image imageFile = Image.FromFile(fileName)) { FrameDimension frameDimensions = new FrameDimension( imageFile.FrameDimensionsList[0]); // Gets the number of pages from the tiff image (if multipage) int frameNum = imageFile.GetFrameCount(frameDimensions); string[] jpegPaths = new string[frameNum]; for (int frame = 0; frame < frameNum; frame++) { // Selects one frame at a time and save as jpeg. imageFile.SelectActiveFrame(frameDimensions, frame); using (Bitmap bmp = new Bitmap(imageFile)) { jpegPaths[frame] = String.Format("{0}\\{1}{2}.jpg", Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName), frame); bmp.Save(jpegPaths[frame], ImageFormat.Jpeg); } } return jpegPaths; } }
public AnimatedImage(Image Image) { gifImage = Image; //initialize dimension = new FrameDimension(gifImage.FrameDimensionsList[0]); //gets the GUID frameCount = gifImage.GetFrameCount(dimension); //total frames in the animation _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed); }
public void ConvertToSinglePageTiffs(string fileName, string destFolder) { Image image = Image.FromFile(fileName); ImageCodecInfo codecInfo = GetCodecInfo(TIFF_CODEC); FrameDimension frameDim = new FrameDimension(image.FrameDimensionsList[0]); EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, ENCODING_SCHEME); for (int i = 0; i < image.GetFrameCount(frameDim); i++) { image.SelectActiveFrame(frameDim, i); string fileNameWOExt = Path.GetFileNameWithoutExtension(fileName); string newFileName = string.Concat(fileNameWOExt, "_", (i + 1).ToString(), TIFF_FILE_EXTENSION); string folder = Path.Combine(Path.GetDirectoryName(fileName), destFolder); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } image.Save(Path.Combine(folder, newFileName), codecInfo, encoderParams); } }
private void LoadImg(string path) { var img = Image.FromFile(path); var fd = new FrameDimension(img.FrameDimensionsList[0]); var count = img.GetFrameCount(fd); var ms = new MemoryStream(); Texture2D texture; TimeSpan frametime = new TimeSpan(0,0,0); FrameImg.Clear(); int i; for(i=0;i<count;i++) { for (int j = 0; j < img.PropertyIdList.Length; j++) { if ((int)img.PropertyIdList.GetValue(j) == 0x5100) { PropertyItem pItem = (PropertyItem)img.PropertyItems.GetValue(j); byte[] delayByte = new byte[4]; delayByte[0] = pItem.Value[i * 4]; delayByte[1] = pItem.Value[1 + i * 4]; delayByte[2] = pItem.Value[2 + i * 4]; delayByte[3] = pItem.Value[3 + i * 4]; int delay = BitConverter.ToInt32(delayByte, 0) * 10; frametime = new TimeSpan(0, 0, 0, 0, delay); break; } } img.SelectActiveFrame(fd, i); img.Save(ms, ImageFormat.Png); texture = Texture2D.FromStream(GraphicsDevice, ms); FrameImg.Add(new GifFrame(texture,frametime)); ms = new MemoryStream(); } FrameTime = frametime; }
static void Main(string[] args) { for (int j = 0; j < args.Length; j++) { Console.WriteLine("Convert File of:"+args[j]); using(Image gif = Image.FromFile(args[j])){ FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]); int count = gif.GetFrameCount(fd); using(Image target= new Bitmap(count*150, 150)) using(Graphics g = Graphics.FromImage(target)){ g.Clear(Color.Transparent); for (int i = 0; i < count; i++) { gif.SelectActiveFrame(fd, i); g.DrawImage(gif,new Point(150/2-gif.Width/2+i*150,150/2-gif.Height/2)); //gif.Save( Path.GetFileNameWithoutExtension(args[j])+ // string.Format("_{0}", i) // + ".png", ImageFormat.Png); } target.Save(Path.GetFileNameWithoutExtension(args[j])+".png",ImageFormat.Png); } } } Console.WriteLine("Convert Fine. Press any key to continue... "); Console.ReadKey(true); }
internal static string[] ConvertTiffToJpeg(string fileName) { using (Image imageFile = Image.FromFile(fileName)) { FrameDimension frameDimensions = new FrameDimension(imageFile.FrameDimensionsList[0]); int frameNum = imageFile.GetFrameCount(frameDimensions); string[] jpegPaths = new string[frameNum]; for (int frame = 0; frame < frameNum; frame++) { imageFile.SelectActiveFrame(frameDimensions, frame); using (Bitmap bmp = new Bitmap(imageFile)) { string tempFileName = Path.GetTempFileName(); FileInfo fileInfo = new FileInfo(tempFileName); fileInfo.Attributes = FileAttributes.Temporary; jpegPaths[frame] = tempFileName; bmp.Save(jpegPaths[frame], ImageFormat.Jpeg); bmp.Dispose(); } } return jpegPaths; } }
/// <summary> /// /// </summary> /// <param name="stream"></param> public GifReader(Stream stream) { _gifImage = Image.FromStream(stream); //initialize _dimension = new FrameDimension(_gifImage.FrameDimensionsList[0]); //gets the GUID _frameCount = _gifImage.GetFrameCount(_dimension); //total frames in the animation }
//------------------------------------------------------------------------------- // public ImageAnimation(Image img) { _image = img; FrameDimension = new FrameDimension(img.FrameDimensionsList[0]); MaxFrameCount = img.GetFrameCount(FrameDimension); PropertyItem pItemFrameDelay = img.GetPropertyItem(FRAME_DELAY); PropertyItem pItemFrameNum = img.GetPropertyItem(FRAME_NUM); FrameDelays = new int[MaxFrameCount]; for (int i = 0; i < MaxFrameCount; i++) { FrameDelays[i] = BitConverter.ToInt32(pItemFrameDelay.Value, 4 * i); } MaxLoopCount = BitConverter.ToInt16(pItemFrameNum.Value, 0); LoopInfinity = (MaxLoopCount == 0); _timer = new Timer(Timer_Elapsed, null, Timeout.Infinite, Timeout.Infinite); try { _image.SelectActiveFrame(FrameDimension, 0); } catch (InvalidOperationException/* ex*/) { //Log.DebugLog(ex); //Debug.Assert(false, "Image.SelectActiveFrame失敗"); } }
public void Equals () { FrameDimension fd = new FrameDimension (new Guid ("7462dc86-6180-4c7e-8e3f-ee7333a7a483")); // equals Assert.IsTrue (fd.Equals (FrameDimension.Page), "Page"); // but ToString differs! Assert.AreEqual ("[FrameDimension: 7462dc86-6180-4c7e-8e3f-ee7333a7a483]", fd.ToString (), "ToString"); }
//----------------------------------------------------------------------------------------------------x /// <summary>Adds a report object to the container.</summary> /// <param name="rX">X-coordinate of the report object</param> /// <param name="rY">Y-coordinate of the report object</param> /// <param name="repObj">Report object to add to the container</param> public new void Add(Double rX, Double rY, RepObj repObj) { //Added By TechnoGuru - [email protected] - http://www.borie.org/ //Here we handle image comosed of severals images if (repObj is RepImage) { #if !WindowsCE RepImage repImage = repObj as RepImage; using (Image image = Image.FromStream(repImage.stream)) { if (image.RawFormat.Equals(ImageFormat.Tiff)) { Guid objGuid = (image.FrameDimensionsList[0]); System.Drawing.Imaging.FrameDimension objDimension = new System.Drawing.Imaging.FrameDimension(objGuid); // Numbre of image in the tiff file int totFrame = image.GetFrameCount(objDimension); if (totFrame > 1) { // Saves every frame in a seperate file. for (int i = 0; i < totFrame; i++) { image.SelectActiveFrame(objDimension, i); string tempFile = Path.GetTempFileName() + ".tif"; if (image.PixelFormat.Equals(PixelFormat.Format1bppIndexed)) { ImageCodecInfo myImageCodecInfo; myImageCodecInfo = GetEncoderInfo("image/tiff"); EncoderParameters myEncoderParameters; myEncoderParameters = new EncoderParameters(1); myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4); image.Save(tempFile, myImageCodecInfo, myEncoderParameters); } else { image.Save(tempFile, ImageFormat.Tiff); } FileStream stream = new System.IO.FileStream(tempFile, FileMode.Open, FileAccess.Read); if (i == 0) { repImage.stream = stream; repObj = repImage as RepObj; } else { new Page(report); RepImage di = new RepImageMM(stream, Double.NaN, Double.NaN); report.page_Cur.AddMM(0, 0, di); } } } } } #endif } base.Add(rX, rY, repObj); }
private void button2_Click(object sender, EventArgs e) { if (listBox1.Items.Count > 0) { using (SaveFileDialog dialog = new SaveFileDialog()) { dialog.Filter = "Png Image (*.png)|*.png"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Bitmap[,] matrix = new Bitmap[200, 200]; int y = 0; int maxFrames = 0; foreach (string fileName in listBox1.Items) { var image = Image.FromFile(fileName); var dimension = new FrameDimension(image.FrameDimensionsList[0]); int frameCount = image.GetFrameCount(dimension); for (int frame = 0; frame < frameCount; frame++) { image.SelectActiveFrame(dimension, frame); matrix[y, frame] = new Bitmap(image); } maxFrames = Math.Max(maxFrames, frameCount); y++; } var final = new Bitmap(maxFrames * matrix[0, 0].Width, y * matrix[0, 0].Height); using (var fx = Graphics.FromImage(final)) { for (int g = 0; g < y; g++) { for (int x = 0; x < 200; x++) { if (matrix[g, x] != null) { MessageBox.Show((x * matrix[g, x].Width).ToString() + " " + x); fx.DrawImage((Image)matrix[g, x], new Point(x * matrix[g, x].Width, g * matrix[g, x].Height)); } } } fx.Flush(); } final.Save(dialog.FileName, ImageFormat.Png); } } } }
/// <summary> /// Returns information about the given <see cref="System.Drawing.Image"/>. /// </summary> /// <param name="image"> /// The image to extend. /// </param> /// <param name="format"> /// The image format. /// </param> /// <param name="fetchFrames"> /// Whether to fetch the images frames. /// </param> /// <returns> /// The <see cref="ImageInfo"/>. /// </returns> public static ImageInfo GetImageInfo(this Image image, ImageFormat format, bool fetchFrames = true) { ImageInfo info = new ImageInfo { Height = image.Height, Width = image.Width, // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags IsIndexed = (image.PixelFormat & PixelFormat.Indexed) != 0 }; if (image.RawFormat.Guid == ImageFormat.Gif.Guid && format.Guid == ImageFormat.Gif.Guid) { if (ImageAnimator.CanAnimate(image)) { info.IsAnimated = true; if (fetchFrames) { FrameDimension frameDimension = new FrameDimension(image.FrameDimensionsList[0]); int frameCount = image.GetFrameCount(frameDimension); int last = frameCount - 1; int delay = 0; int index = 0; List<GifFrame> gifFrames = new List<GifFrame>(); for (int f = 0; f < frameCount; f++) { int thisDelay = BitConverter.ToInt32(image.GetPropertyItem(20736).Value, index); int toAddDelay = thisDelay * 10 < 20 ? 20 : thisDelay * 10; // Minimum delay is 20 ms // Find the frame image.SelectActiveFrame(frameDimension, f); // TODO: Get positions. gifFrames.Add(new GifFrame { Delay = toAddDelay, Image = (Image)image.Clone() }); // Reset the position. if (f == last) { image.SelectActiveFrame(frameDimension, 0); } delay += toAddDelay; index += 4; } info.GifFrames = gifFrames; info.AnimationLength = delay; // Loop info is stored at byte 20737. info.LoopCount = BitConverter.ToInt16(image.GetPropertyItem(20737).Value, 0); info.IsLooped = info.LoopCount != 1; } } } return info; }
public GifImage(Image path) { gifImage = path; //initialize dimension = new FrameDimension(gifImage.FrameDimensionsList[0]); //gets the GUID //total frames in the animation frameCount = gifImage.GetFrameCount(dimension); }
public PlainImage(awt.Image image, awt.Image [] thumbnails, ImageFormat format, float xRes, float yRes, FrameDimension dimension) { _nativeObject = image; _thumbnails = thumbnails; _imageFormat = format; _xResolution = xRes; _yResolution = yRes; _dimension = dimension; }
public GifHandler( Image Image ) { mImage = Image.Clone() as Image; mFrameDimension = new FrameDimension( mImage.FrameDimensionsList[ 0 ] ); mFrameCount = mImage.GetFrameCount( mFrameDimension ); mFrameTimes = new int[ mFrameCount ]; byte[] times = mImage.GetPropertyItem( 0x5100 ).Value; for( int i = 0; i < mFrameCount; i++ ) mFrameTimes[ i ] = BitConverter.ToInt32( times, 4 * i ) * 10; }
public void Empty () { FrameDimension fd = new FrameDimension (Guid.Empty); Assert.AreEqual ("00000000-0000-0000-0000-000000000000", fd.Guid.ToString (), "Guid"); Assert.AreEqual (Guid.Empty.GetHashCode (), fd.GetHashCode (), "GetHashCode"); Assert.AreEqual ("[FrameDimension: 00000000-0000-0000-0000-000000000000]", fd.ToString (), "ToString"); Assert.IsTrue (fd.Equals (new FrameDimension (Guid.Empty)), "Equals(Empty)"); Assert.IsFalse (fd.Equals (null), "Equals(null)"); }
internal void SetNewSize(Size size, string sizeMode) { Point destLocation = getDestinationPos(size, sizeMode); Bitmap newSrcImage = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(newSrcImage); Brush fondo = new SolidBrush(preferences.SrcBackgroundColor); FrameDimension frameDimensions = new FrameDimension(newSrcImage.FrameDimensionsList[0]); FrameDimension oldFrameDimensions = new FrameDimension(this.srcImage.FrameDimensionsList[0]); EncoderParameters tiffParams = new EncoderParameters(1); EncoderParameter param = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.MultiFrame); tiffParams.Param[0] = param; ImageCodecInfo tiffEncoder = getCodecInfo("image/tiff"); string filePath = System.IO.Path.GetTempFileName(); for (int frame = 0; frame < numFrames; frame++) { Bitmap tempImage = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb); Graphics tempGr = Graphics.FromImage(tempImage); this.srcImage.SelectActiveFrame(oldFrameDimensions, frame); tempGr.FillRectangle(fondo, 0, 0, newSrcImage.Width, newSrcImage.Height); tempGr.DrawImage(this.srcImage, destLocation); if (frame == 0) { g.DrawImage(this.srcImage, destLocation); newSrcImage.Save(filePath, tiffEncoder, tiffParams); } else { tiffParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage); newSrcImage.SaveAdd(tempImage, tiffParams); } tempImage.Dispose(); GC.Collect(); } tiffParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.Flush); newSrcImage.SaveAdd(tiffParams); newSrcImage.Dispose(); GC.Collect(); Image temp = this.srcImage; this.SrcImage = Bitmap.FromFile(filePath); temp.Dispose(); fondo.Dispose(); g.Dispose(); }
private void GifBox(Image gif, PictureBox pic) { FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]); int count = gif.GetFrameCount(System.Drawing.Imaging.FrameDimension.Time); for (int i = 0; i < count; i++) { gif.SelectActiveFrame(fd, i); pic.Image = gif; } }
public static void Main(string[] args) { Image gif = Image.FromFile("test2.gif"); FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]); int count = gif.GetFrameCount(fd); for (int i = 0; i < count; i++) { gif.SelectActiveFrame(fd, i); gif.Save("test2_" + string.Format("{0:00}", i) + ".jpg", ImageFormat.Jpeg); } }
public void gif_to_images(string GifPath) { Image gifImg = Image.FromFile(GifPath); FrameDimension dimension = new FrameDimension(gifImg.FrameDimensionsList[0]); int frameCount = gifImg.GetFrameCount(dimension); Image[] obrazky_gif = new Image[frameCount]; for (int poc = 0; poc < frameCount; poc++) { gifImg.SelectActiveFrame(dimension, poc); images[poc] = new Bitmap(gifImg); } }
public GifImage(string path) { _lastRequest = DateTime.Now; _gifImage = Image.FromFile(path); //initialize _dimension = new FrameDimension(_gifImage.FrameDimensionsList[0]); //gets the GUID FrameCount = _gifImage.GetFrameCount(_dimension); //total frames in the animation Source = path; var item = _gifImage.GetPropertyItem(0x5100); // FrameDelay in libgdiplus _delay = (item.Value[0] + item.Value[1]*256)*10; // Time is in 1/100th of a second }
/// <summary> /// 实例化一个AnimateImage。 /// </summary> /// <param name="img">动画图片。</param> public AnimateImage(Image img) { image = img; lock (image) { mCanAnimate = ImageAnimator.CanAnimate(image); if (mCanAnimate) { Guid[] guid = image.FrameDimensionsList; frameDimension = new FrameDimension(guid[0]); mFrameCount = image.GetFrameCount(frameDimension); } } }
/// <summary> /// Converts an image to PDF using Aspose.Words for .NET. /// </summary> /// <param name="inputFileName">File name of input image file.</param> /// <param name="outputFileName">Output PDF file name.</param> public static void ConvertImageToPdf(string inputFileName, string outputFileName) { Console.WriteLine("Converting " + inputFileName + " to PDF ...."); // ExStart:ConvertImageToPdf // Create Document and DocumentBuilder. // The builder makes it simple to add content to the document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Read the image from file, ensure it is disposed. using (Image image = Image.FromFile(inputFileName)) { // Find which dimension the frames in this image represent. For example // The frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension". FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]); // Get the number of frames in the image. int framesCount = image.GetFrameCount(dimension); // Loop through all frames. for (int frameIdx = 0; frameIdx < framesCount; frameIdx++) { // Insert a section break before each new page, in case of a multi-frame TIFF. if (frameIdx != 0) builder.InsertBreak(BreakType.SectionBreakNewPage); // Select active frame. image.SelectActiveFrame(dimension, frameIdx); // We want the size of the page to be the same as the size of the image. // Convert pixels to points to size the page to the actual image size. PageSetup ps = builder.PageSetup; ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution); ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution); // Insert the image into the document and position it at the top left corner of the page. builder.InsertImage( image, RelativeHorizontalPosition.Page, 0, RelativeVerticalPosition.Page, 0, ps.PageWidth, ps.PageHeight, WrapType.None); } } // Save the document to PDF. doc.Save(outputFileName); // ExEnd:ConvertImageToPdf }
/// <summary> /// bm is the main background image and p is the overlay image index from the plant life overlay for this scene /// </summary> /// <param name="bm"></param> /// <param name="p"></param> /// <returns></returns> public Bitmap appplyOverlayImage(Bitmap bm, int p = 0, int overlayX =0, int overlayY = 0, bool fade = false) { //TODO overlay image2 onto image1 try{ Bitmap finalImage = (Bitmap)bm.Clone(); FrameDimension dimension = new FrameDimension(getPlantLifeImageByKey(p).FrameDimensionsList[0]); // Number of frames int frameCount = plantLifeImagesOver[0].PlantImage.GetFrameCount(dimension); Bitmap[] overlayBMframes = ParseFrames( plantLifeImagesOver[0].PlantImage); Bitmap img2 = overlayBMframes[currentOverlayFrame++]; if(currentOverlayFrame>=frameCount) currentOverlayFrame=0; using (Graphics g = Graphics.FromImage(finalImage)) { //go through each image and draw it on the final image (Notice the offset; since I want to overlay the images i won't have any offset between the images in the finalImage) int offsetX = 0; int offsetY = 0; // only using hte main image adn overlay (initially it's a butterfly on crazy green background //foreach (Bitmap image in images) //{ g.DrawImage(bm, new Rectangle(offsetX, offsetY, bm.Width, bm.Height)); // TODO set the overlay position based on face head position offsetX = bm.Width / 4; offsetY = bm.Height / 4; // Create a new color matrix and set the alpha value to 0.5 ColorMatrix cm = new ColorMatrix(); cm.Matrix00 = cm.Matrix11 = cm.Matrix22 = cm.Matrix44 = 1; cm.Matrix33 = 0.5f; // Create a new image attribute object and set the color matrix to // the one just created ImageAttributes ia = new ImageAttributes(); ia.SetColorMatrix(cm); //g.DrawImage(img2, new Rectangle(offsetX, offsetY, img2.Width, img2.Height)); // Draw the original image with the image attributes specified if (fade) g.DrawImage(img2, new Rectangle(overlayX, overlayY, img2.Width, img2.Height), 0, 0, img2.Width, img2.Height, GraphicsUnit.Pixel,ia); else g.DrawImage(img2, new Rectangle(overlayX, overlayY, img2.Width, img2.Height)); } bm =finalImage; } catch(Exception errbm) { Console.WriteLine("ERROR - appplyOverlayImage = " + errbm); } return bm; }
public static bool IsGIFAnimation(Image image) { System.Guid[] frameDimensionsList = image.FrameDimensionsList; for (int i = 0; i < frameDimensionsList.Length; i++) { System.Guid guid = frameDimensionsList[i]; FrameDimension dimension = new FrameDimension(guid); if (image.GetFrameCount(dimension) > 1) { return true; } } return false; }
public static IEnumerable<Frame> LoadGif(string filename) { using (Bitmap bitmap = new Bitmap(filename)) { FrameDimension dim = new FrameDimension(bitmap.FrameDimensionsList[0]); for (int i = 0; i < bitmap.GetFrameCount(dim); i++) { bitmap.SelectActiveFrame(dim, i); var frame = new MutableFrame(); frame.LoadBitmap(bitmap); yield return frame; } } }
/*/// <summary> * /// This method converts the read in byte arry to a System.Drawing.Bitmap * /// </summary> * /// <param name="data"> the byte array to be convereted</param> * /// <returns></returns> * public System.Drawing.Bitmap byteArrayToBitMap(byte[] data){ * System.Drawing.Bitmap bmp; * * System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter(); * bmp = (System.Drawing.Bitmap)ic.ConvertFrom(data); * //Debug.Log("Converted byteArray to bit map"); * return bmp; * * }*/ /* * public void byteArrayToTexture2D(byte[] data) * { * int width = data[6]; * int height = data[8]; * Debug.Log("Width: " + width + " Height: " + height); * Texture2D bmp = new Texture2D(width, height); * bmp.LoadRawTextureData(data); * myRawImage.texture = bmp; * }*/ /// <summary> /// This handles loading all fo the data from the given url and converts it into a readable image type and then allows the OnGUI function to draw the gif /// </summary> public void loadImage() { //Debug.Log("Called Load Image BACK"); gifImage = ByteArrayToImage(www.bytes); if (gifImage == null) { return; } isGif = true; var dimension = new System.Drawing.Imaging.FrameDimension(gifImage.FrameDimensionsList[0]); int frameCount = gifImage.GetFrameCount(dimension); Debug.Log("Dimensions: Frames: " + frameCount + " Width: " + gifImage.Width + " Height: " + gifImage.Height + " Pixels: " + (gifImage.Width * gifImage.Height)); int width = 0; int height = 0; for (int i = 0; i < frameCount; i++) { gifImage.SelectActiveFrame(dimension, i); var frame = new System.Drawing.Bitmap(gifImage.Width, gifImage.Height); System.Drawing.Graphics.FromImage(frame).DrawImage(gifImage, Point.Empty); Texture2D frameTexture = new Texture2D(frame.Width, frame.Height); for (int x = 0; x < frame.Width; x++) { for (int y = 0; y < frame.Height; y++) { System.Drawing.Color sourceColor = frame.GetPixel(x, y); frameTexture.SetPixel(frame.Width + x + 1, -y, new Color32(sourceColor.R, sourceColor.G, sourceColor.B, sourceColor.A)); // for some reason, x is flipped } } frameTexture.Apply(); gifFrames.Add(frameTexture); width = frame.Width; height = frame.Height; } byteArrayTextConversion(bytearrayholder); //Debug.Log("Starting ON GUI!"); canOnGUI = true; }
private void buttonExplodeGif(object sender, EventArgs e) { var gifImg = Image.FromFile(GifFile); var dimension = new FrameDimension(gifImg.FrameDimensionsList[0]); // Number of frames var count = gifImg.GetFrameCount(dimension); // Return an Image at a certain index for (var i = 0; i < count; i++) { gifImg.SelectActiveFrame(dimension, i); var b = new Bitmap(gifImg); var fName = FrameName(i); b.Save(fName); } }
//------------------------------------------------------------------------------- // public ImageAnimation(Image img) { _image = img; FrameDimension = new FrameDimension(img.FrameDimensionsList[0]); MaxFrameCount = img.GetFrameCount(FrameDimension); PropertyItem pItemFrameDelay = img.GetPropertyItem(FRAME_DELAY); PropertyItem pItemFrameNum = img.GetPropertyItem(FRAME_NUM); FrameDelays = new int[MaxFrameCount]; for (int i = 0; i < MaxFrameCount; i++) { FrameDelays[i] = BitConverter.ToInt32(pItemFrameDelay.Value, 4 * i); } MaxLoopCount = BitConverter.ToInt16(pItemFrameNum.Value, 0); LoopInfinity = (MaxLoopCount == 0); _timer = new Timer(Timer_Elapsed, null, Timeout.Infinite, Timeout.Infinite); _image.SelectActiveFrame(FrameDimension, 0); }
/// <summary> /// Constructor. /// </summary> /// <param name="project">The project that this asset is associated with.</param> /// <param name="name">The name of the asset that is displayed to the user.</param> /// <param name="filename">The name of the asset file.</param> public MultiFrameImageAsset(StudioProject project, String name, String filename) : base(project, name, filename) { try { string path = Path.Combine(Project.GetAssetDirectory(), filename); // Load the image and get the frame count using (Image img = Image.FromFile(path)) { FrameDimension dimension = new FrameDimension(img.FrameDimensionsList[0]); frameCount = img.GetFrameCount(dimension); } thumbnails = new Image[frameCount]; } catch (Exception x) { Error = x; } }
public static List <Texture2D> GetGifImage(byte[] bt) { List <Texture2D> t2s = new List <Texture2D>(); MemoryStream ms = new MemoryStream(bt); Image imgGif = Image.FromStream(ms); if (System.Drawing.ImageAnimator.CanAnimate(imgGif)) { System.Drawing.Imaging.FrameDimension imgFrmDim = new System.Drawing.Imaging.FrameDimension(imgGif.FrameDimensionsList[0]); // 获取帧数 int nFdCount = imgGif.GetFrameCount(imgFrmDim); for (int i = 0; i < nFdCount; i++) { // 把每一帧保存为jpg图片 imgGif.SelectActiveFrame(imgFrmDim, i); Texture2D t2 = new Texture2D(imgGif.Width, imgGif.Height); t2.LoadImage(ImageToByteArray(imgGif)); t2s.Add(t2); } } return(t2s); }
internal static Strcut_CFCBlock GetFaceBlockFromImage(Emoticon emoticon) { string filePath = IOUtil.ResolvePath(emoticon.ImageSrc); Strcut_CFCBlock fb = new Strcut_CFCBlock(); //���ļ��� //����ļ��Ƿ�ɾ�� if (!IOUtil.ExistsFile(filePath)) { return(null); } FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); byte[] faceData = new byte[fs.Length]; fs.Read(faceData, 0, (int)fs.Length); //��ȡͼ�� Image img; try { img = Image.FromStream(fs); } catch { fs.Close(); return(null); } //Image thumbnail = img.GetThumbnailImage(20, 20, null, IntPtr.Zero); MemoryStream ms = new MemoryStream(); //����ͼͼת����byte���� ImageHelper.CreateThunmbnailImage(img, ms, 20, 20, ImageFormat.Bmp); byte[] thumbnailData = ms.ToArray(); ms.Close(); ms.Dispose(); //thumbnail.Dispose(); //�õ�һ��Ψһ��MD5�ַ��� string md5 = GetMD5(fs); fs.Close(); //fs.Dispose(); //�ļ�������ʽΪ:md5 + ��չ�� string fileName = md5 + Path.GetExtension(emoticon.ImageSrc); //����ͼ�ļ�������ʽΪ��md5 + fixed.bmp string thumbnailName = string.Format("{0}fixed.bmp", md5); //����һ����ݼ� string uintcuts = emoticon.Shortcut; //ȡ���ܵ�֡�� System.Drawing.Imaging.FrameDimension fd = System.Drawing.Imaging.FrameDimension.Resolution; int frameCount = img.FrameDimensionsList.Length; img.Dispose(); fb.MD5 = md5; fb.MD5Length = (uint)md5.Length; fb.uintcuts = uintcuts; fb.uintcutLength = (uint)uintcuts.Length; fb.FaceName = uintcuts; fb.FaceNameLength = (uint)uintcuts.Length; fb.FaceFileName = fileName; fb.FaceFileNameLength = (uint)fileName.Length; fb.ThumbnailFileName = thumbnailName; fb.ThumbnailFileNameLength = (uint)thumbnailName.Length; fb.FaceData = File.ReadAllBytes(IOUtil.ResolvePath(emoticon.ImageSrc)); fb.FileLength = (uint)fb.FaceData.Length; fb.ThumbnailData = thumbnailData; fb.ThumbnailFileLength = (uint)thumbnailData.Length; fb.FrameLength = (uint)frameCount; return(fb); }
public static SystemDrawingImageAdapter TryGet(Stream stream) { using (var img = sd.Image.FromStream(stream)) { if (img.FrameDimensionsList.Length == 0) { return(null); } var dimension = new sdi.FrameDimension(img.FrameDimensionsList[0]); int frames = img.GetFrameCount(dimension); if (frames <= 1) { return(null); } byte[] delayBytes = img.PropertyItems.FirstOrDefault(r => r.Id == 0x5100)?.Value; if (delayBytes == null || delayBytes.Length < 4) { return(null); } // In mono we have to get the delay for each frame, unlike windows which returns the entire block var useFrameDelay = delayBytes.Length != frames * 4; //var loop = BitConverter.ToInt16(img.GetPropertyItem(0x5101).Value, 0) != 1; var transparentIndex = img.PropertyItems.FirstOrDefault(r => r.Id == 0x5104)?.Value[0]; var images = new List <SystemDrawingImageFrame>(); for (int frame = 0; frame < frames; frame++) { img.SelectActiveFrame(dimension, frame); int delayIndex; if (useFrameDelay) { delayBytes = img.GetPropertyItem(0x5100).Value; if (delayBytes.Length < 4) { return(null); } delayIndex = 0; } else { delayIndex = frame * 4; } int delayInMilliseconds = BitConverter.ToInt32(delayBytes, delayIndex) * 10; var frameImage = new sd.Bitmap(img); if (global::Eto.EtoEnvironment.Platform.IsMono) { // bug in mono, windows preserves the transparency if (transparentIndex != null) { frameImage.MakeTransparent(frameImage.Palette.Entries[transparentIndex.Value]); } else { frameImage.MakeTransparent(); } } images.Add(new SystemDrawingImageFrame(TimeSpan.FromMilliseconds(delayInMilliseconds), frameImage)); } return(new SystemDrawingImageAdapter(new Size(img.Width, img.Height), images)); } }
public void Append(byte[] bytes) { using (var ms = new MemoryStream(bytes)) { switch (LibPDFTools.GetImageFileType(bytes)) { case ImageFileType.PDF: using (var pdfDoc = new PDFLibNet.PDFWrapper("")) { pdfDoc.LoadPDF(ms); for (var i = 1; i <= pdfDoc.PageCount; i++) { pdfDoc.CurrentPage = i; pdfDoc.CurrentX = 0; pdfDoc.CurrentY = 0; pdfDoc.RenderDPI = this.resolution; Bitmap pageBuffer = null; using (var oPictureBox = new PictureBox()) { pdfDoc.RenderPage(oPictureBox.Handle); pageBuffer = new Bitmap(pdfDoc.PageWidth, pdfDoc.PageHeight); pdfDoc.ClientBounds = new System.Drawing.Rectangle(0, 0, pdfDoc.PageWidth, pdfDoc.PageHeight); using (var g = Graphics.FromImage(pageBuffer)) { var hdc = g.GetHdc(); pdfDoc.DrawPageHDC(hdc); g.ReleaseHdc(); } } SaveAddTiffPage(pageBuffer); pageBuffer.Dispose(); currPageNum++; } } break; case ImageFileType.TIFF: { using (var image = System.Drawing.Image.FromStream(ms)) { var fd = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]); int numberOfPages = image.GetFrameCount(fd); for (int pageNum = 0; pageNum < numberOfPages; pageNum++) { image.SelectActiveFrame(fd, pageNum); if (currPageNum == 0) { backbuffer = (System.Drawing.Image)image.Clone(); backbuffer.Save(outStream, codec, encoderParameters_MultiFrame); } else { backbuffer.SaveAdd(image, encoderParameters_FrameDimensionPage); } currPageNum++; } } } break; default: { var pageBuffer = System.Drawing.Image.FromStream(ms); SaveAddTiffPage(pageBuffer); } currPageNum++; break; } } }
void OnGUI() { string sourcePath = Application.dataPath + assetPath.Substring(6); GUILayout.BeginHorizontal(); GUILayout.Label("Convert Settings", EditorStyles.boldLabel); GUILayout.Label(assetPath, EditorStyles.boldLabel); GUILayout.EndHorizontal(); GUILayout.Space(10); splitValue = EditorGUILayout.IntPopup("Split", splitValue, splitOptionsDisplay, splitOptions); autoGenerateAnimation = EditorGUILayout.Toggle("Auto Generate Animation", autoGenerateAnimation); #region OutputFolder Selection GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Animation Output Folder"); GUIStyle alignLeft = new GUIStyle(GUI.skin.button); alignLeft.alignment = TextAnchor.MiddleLeft; if (GUILayout.Button(animationOutputPath.Length == 0 ? "Click To Select Path" : animationOutputPath, alignLeft)) { string returnPath = EditorUtility.OpenFolderPanel("Select Output Directory", animationOutputPath.Length == 0 ? Application.dataPath : Application.dataPath + animationOutputPath.Substring("Assets".Length), ""); if (returnPath.Length > 0) { if (returnPath.Contains(Application.dataPath)) { returnPath = returnPath.Substring(Application.dataPath.Length); returnPath = "Assets" + returnPath; } animationOutputPath = returnPath; } } GUILayout.EndHorizontal(); #endregion GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Cancel")) { Close(); } else if (GUILayout.Button("Convert")) { animationOutputPath += "/" + filename + ".anim"; if (autoGenerateAnimation) { // Delete existing animation AssetDatabase.DeleteAsset(animationOutputPath); } #if UNITY_EDITOR_WIN using (Image gifImg = Image.FromFile(sourcePath)) { System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(gifImg.FrameDimensionsList[0]); int frameCount = gifImg.GetFrameCount(dimension); byte[] times = gifImg.GetPropertyItem(0x5100).Value; int gifDuration = 0; for (int i = 0; i < frameCount; i++) { gifDuration += BitConverter.ToInt32(times, i * 4); } frameRate = (float)frameCount / gifDuration * 100.0f; for (int k = 0; k < splitValue; k++) { int frameCountPerSplit = frameCount / splitValue; int extraFrame = frameCount % splitValue; if (k < extraFrame) { frameCountPerSplit++; } int spriteDimension = (Mathf.CeilToInt(Mathf.Sqrt(frameCountPerSplit))); int finalWidth = spriteDimension * (gifImg.Width + 2); int finalHeight = spriteDimension * (gifImg.Height + 2); using (Bitmap finalSprite = new Bitmap(finalWidth, finalHeight)) { using (System.Drawing.Graphics canvas = System.Drawing.Graphics.FromImage(finalSprite)) { int row = 0; int col = 0; for (int i = 0; i < frameCountPerSplit; i++) { row = i / spriteDimension; col = i - row * spriteDimension; gifImg.SelectActiveFrame(dimension, i + k * frameCountPerSplit + (k >= extraFrame? extraFrame : 0)); using (Bitmap frame = new Bitmap(gifImg)) { canvas.DrawImage(frame, col * (gifImg.Width + 2) + 1, row * (gifImg.Height + 2) + 1); } } canvas.Save(); string targetPath = sourcePath.Substring(0, sourcePath.Length - 4) + "-" + k + ".png"; finalSprite.Save(targetPath, System.Drawing.Imaging.ImageFormat.Png); // Tried AssetDatabase.Refresh(); seems like it will cause problem in assetimporter // use ImportAsset() instead string importPath = assetPath.Substring(0, assetPath.Length - 4) + "-" + k + ".png"; AssetDatabase.ImportAsset(importPath); gifProcessor.OnProcessTexture(importPath, filename, frameCountPerSplit, spriteDimension, gifImg.Width, gifImg.Height, autoGenerateAnimation, animationOutputPath, frameRate); } } } } #elif UNITY_EDITOR_OSX #endif Close(); } GUILayout.EndHorizontal(); GUILayout.Space(10); }
public Bitmap LoadIntoBitmap(string a_sFilename) //, ref string actualFilename) { //string sOrg = a_sFilename; //for debugging //a_sFilename = m_endogine.CastLib.FindFile(a_sFilename); a_sFilename = AppSettings.Instance.FindFile(a_sFilename); if (a_sFilename.Length == 0) { if (true) // || m_endogine.CastLib.UseDummiesForFilesNotFound) { //TODO: generalized dummy function a_sFilename = m_endogine.CastLib.DirectoryPath + "Cross.bmp"; } } System.IO.FileInfo finfo = new System.IO.FileInfo(a_sFilename); Name = finfo.Name.Replace(finfo.Extension, ""); FileFullName = a_sFilename; if (!finfo.Exists) { throw new System.IO.FileNotFoundException("Member file not found: " + a_sFilename); } //TODO: only allow >= 24 bpp PixelFormat.Format8bppIndexed - otherwise convert! Bitmap bmpDst = null; bool bStandardLoad = true; if (a_sFilename.IndexOf(".gif") > 0) { Image img = System.Drawing.Image.FromFile(a_sFilename); System.Drawing.Imaging.FrameDimension oDimension = new System.Drawing.Imaging.FrameDimension(img.FrameDimensionsList[0]); int nNumFrames = img.GetFrameCount(oDimension); //calc how big the destination bitmap must be (make it as square as possible) //TODO: it's OK if there's a few uninhabited tiles at end? int nNumFramesOnX = (int)Math.Sqrt(nNumFrames); for (; nNumFramesOnX > 0; nNumFramesOnX--) { if (nNumFrames / nNumFramesOnX * nNumFramesOnX == nNumFrames) { break; } } bmpDst = new Bitmap( img.Size.Width * nNumFramesOnX, img.Size.Height * nNumFrames / nNumFramesOnX, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmpDst); if (nNumFrames > 1) { bStandardLoad = false; //TODO: let picRefs handle the generation animation... for (int i = 0; i < nNumFrames; i++) { int x = i % nNumFramesOnX; int y = i / nNumFramesOnX; img.SelectActiveFrame(oDimension, i); ERectangle rctDst = new ERectangle(x * img.Size.Width, y * img.Size.Height, img.Size.Width, img.Size.Height); g.DrawImageUnscaled(img, rctDst.X, rctDst.Y, rctDst.Width, rctDst.Height); } g.Dispose(); this.m_sizeTotal = new EPoint(bmpDst.Width, bmpDst.Height); this.m_bGotAnimation = true; PicRef.CreatePicRefs(this, nNumFramesOnX, nNumFrames); //AnimateWithinSize = new EPoint(img.Size.Width, img.Size.Height); } img.Dispose(); } if (!bStandardLoad) { } else { bmpDst = (Bitmap)System.Drawing.Bitmap.FromFile(a_sFilename); } m_sizeTotal = new EPoint(bmpDst.Width, bmpDst.Height); m_bmpThumbnail = new Bitmap(32, 32, PixelFormat.Format24bppRgb); Graphics g2 = Graphics.FromImage(m_bmpThumbnail); g2.DrawImage(bmpDst, 0, 0, m_bmpThumbnail.Width, m_bmpThumbnail.Height); g2.Dispose(); this.LoadResourceFile(a_sFilename); return(bmpDst); }