コード例 #1
0
ファイル: DrawMine.cs プロジェクト: judgeou/OMine
 /// <summary>
 /// 重新创建bitmap
 /// </summary>
 public void CreateNewMap()
 {
     gic.Dispose();
     Pic.Dispose();
     Pic = new Bitmap(cells[0].Length * Size + 1, cells.Length * Size + 1);
     gic = Graphics.FromImage(Pic);
 }
コード例 #2
0
        public static void Rotate90(string fileName)
        {
            Image  Pic;
            string FileNameTemp;

            System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation;
            EncoderParameters EncParms         = new EncoderParameters(1);
            EncoderParameter  EncParm;
            ImageCodecInfo    CodecInfo = GetEncoderInfo("image/jpeg");

            // load the image to change
            Pic = Image.FromFile(fileName);

            Image Pic2 = (Image)Pic.Clone();

            // we cannot store in the same image, so use a temporary image instead
            FileNameTemp = fileName + ".temp";

            // for rewriting without recompression we must rotate the image 90 degrees
            EncParm           = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90);
            EncParms.Param[0] = EncParm;

            // now write the rotated image with new description
            Pic.Save(FileNameTemp, CodecInfo, EncParms);
            Pic.Dispose();
            Pic = null;

            // delete the original file, will be replaced later
            //System.IO.File.Delete(fileName);
            //System.IO.File.Move(FileNameTemp, fileName);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: batuZ/sisTools
        private static void WriteNewDescriptionInImage(string Filename, List <PropertyItem> myProItems)
        {
            Image Pic;
            //int i;
            string FilenameTemp;

            System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation;//编码器
            EncoderParameters EncParms         = new EncoderParameters(1);
            EncoderParameter  EncParm;
            //ImageCodecInfo CodecInfo = GetEncoderInfo("image/jpeg");
            ImageCodecInfo CodecInfo = GetEncoderInfoByExtension(Path.GetExtension(Filename));

            // load the image to change加载图像变化
            Pic = Image.FromFile(Filename);
            foreach (PropertyItem item in myProItems)
            {
                Pic.SetPropertyItem(item);
            }
            // we cannot store in the same image, so use a temporary image instead
            //我们不能存储在相同的图像,所以使用一个临时的图像代替
            FilenameTemp = Filename + ".temp";
            // for lossless rewriting must rotate the image by 90 degrees!无损重写必须图像旋转90度!
            EncParm           = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90);
            EncParms.Param[0] = EncParm;
            // now write the rotated image with new description现在写的旋转图像的新描述
            Pic.Save(FilenameTemp, CodecInfo, EncParms);
            // for computers with low memory and large pictures: release memory now电脑内存和释放内存现在:大图片
            Pic.Dispose();
            Pic = null;
            GC.Collect();
            // delete the original file, will be replaced later删除原始文件,将被替换后
            System.IO.File.Delete(Filename);
            // now must rotate back the written picture现在必须轮流回写图像
            Pic               = Image.FromFile(FilenameTemp);
            EncParm           = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate270);
            EncParms.Param[0] = EncParm;

            Pic.Save(Filename, CodecInfo, EncParms);
            // release memory now释放内存
            Pic.Dispose();
            Pic = null;
            GC.Collect();
            // delete the temporary picture删除临时图片
            System.IO.File.Delete(FilenameTemp);
        }
コード例 #4
0
ファイル: ExifProperties_new.cs プロジェクト: rahodges/Amns
        private static void writeDescriptionInImage(string filename, string newAuthor, string newCopyright, string newDescription)
        {
            Image Pic;

            PropertyItem[]    PropertyItems;
            byte[]            bAuthor      = new Byte[newAuthor.Length];
            byte[]            bCopyright   = new Byte[newCopyright.Length];
            byte[]            bDescription = new Byte[newDescription.Length];
            int               i;
            string            FilenameTemp;
            Encoder           Enc      = Encoder.Transformation;
            EncoderParameters EncParms = new EncoderParameters(1);
            EncoderParameter  EncParm;
            ImageCodecInfo    CodecInfo = GetEncoderInfo("image/jpeg");

            // copy description into byte array
            for (i = 0; i < newAuthor.Length; i++)
            {
                bAuthor[i] = (byte)newAuthor[i];
            }
            for (i = 0; i < newCopyright.Length; i++)
            {
                bCopyright[i] = (byte)newCopyright[i];
            }
            for (i = 0; i < newDescription.Length; i++)
            {
                bDescription[i] = (byte)newDescription[i];
            }


            // load the image to change
            Pic = Image.FromFile(filename);

//			PropertyItem propertyAuthor = CreatePropertyImage();
//			propertyAuthor.Id = 0x013b;
//			propertyAuthor.Type = 2;
//			propertyAuthor.Len = newAuthor.Length;
//			propertyAuthor.Value = bAuthor;
//			Pic.SetPropertyItem(propertyAuthor);
//
//			PropertyItem propertyCopyright = CreatePropertyImage();
//			propertyCopyright.Id = 0x8298;
//			propertyCopyright.Type = 2;
//			propertyCopyright.Len = newCopyright.Length;
//			propertyCopyright.Value = bCopyright;
//			Pic.SetPropertyItem(propertyCopyright);
//
//			PropertyItem propertyDescription = CreatePropertyImage();
//			propertyDescription.Id = 0x010e;
//			propertyDescription.Type = 2;
//			propertyDescription.Len = newDescription.Length;
//			propertyDescription.Value = bDescription;
//			Pic.SetPropertyItem(propertyDescription);

            // put the new description into the right property item
            PropertyItems          = Pic.PropertyItems;
            PropertyItems[0].Id    = 0x010e;        // 0x010e as specified in EXIF standard
            PropertyItems[0].Type  = 2;
            PropertyItems[0].Len   = newDescription.Length;
            PropertyItems[0].Value = bDescription;
            Pic.SetPropertyItem(PropertyItems[0]);

            PropertyItems = Pic.PropertyItems;

            // we cannot store in the same image, so use a temporary image instead
            FilenameTemp = filename + ".temp";

            // for lossless rewriting must rotate the image by 90 degrees!
            EncParm           = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90);
            EncParms.Param[0] = EncParm;

            // now write the rotated image with new description
            Pic.Save(FilenameTemp, CodecInfo, EncParms);

            // for computers with low memory and large pictures: release memory now
            Pic.Dispose();
            Pic = null;
            GC.Collect();

            // delete the original file, will be replaced later
            System.IO.File.Delete(filename);

            // now must rotate back the written picture
            Pic               = Image.FromFile(FilenameTemp);
            EncParm           = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate270);
            EncParms.Param[0] = EncParm;
            Pic.Save(filename, CodecInfo, EncParms);

            // release memory now
            Pic.Dispose();
            Pic = null;
            GC.Collect();

            // delete the temporary picture
            System.IO.File.Delete(FilenameTemp);
        }
コード例 #5
0
ファイル: DrawMine.cs プロジェクト: judgeou/OMine
 public void Dispose()
 {
     gic.Dispose();
     Pic.Dispose();
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: ruimcoder/PhotoScout
        /// <summary>
        ///
        /// </summary>
        /// <param name="Filename"></param>
        /// <param name="latDeg"></param>
        /// <param name="latMin"></param>
        /// <param name="latSec"></param>
        /// <param name="lonDeg"></param>
        /// <param name="lonMin"></param>
        /// <param name="lonSec"></param>
        private static void WriteLongLat(string Filename, byte latDeg, byte latMin, double latSec, byte lonDeg, byte lonMin, double lonSec)
        {
            const int length = 25;
            Image     Pic;
            byte      secHelper;
            byte      secRemains;

            PropertyItem[] PropertyItems;
            string         FilenameTemp;

            System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation;
            EncoderParameters EncParms         = new EncoderParameters(1);
            EncoderParameter  EncParm;
            ImageCodecInfo    CodecInfo = GetEncoderInfo("image/jpeg");

            // load the image to change
            Pic           = Image.FromFile(Filename);
            PropertyItems = Pic.PropertyItems;
            int oldArrLength = PropertyItems.Length;

            PropertyItem[] newProperties = new PropertyItem[oldArrLength];
            Pic.PropertyItems.CopyTo(newProperties, 0);
            newProperties[0].Id    = 0x0002;
            newProperties[0].Type  = 5;//5-R 4-L 3-S
            newProperties[0].Len   = length;
            newProperties[0].Value = new byte[length];
            try
            {
                for (int i = 0; i < length; i++)
                {
                    newProperties[0].Value[i] = 0;
                }
            }
            catch
            {
            }
            //PropertyItems[0].Value = Pic.GetPropertyItem(4).Value; // bDescription;
            newProperties[0].Value[0] = latDeg;
            newProperties[0].Value[8] = (byte)latMin;
            secHelper  = (byte)(latSec / 2.56);
            secRemains = (byte)((latSec - (secHelper * 2.56)) * 100);
            newProperties[0].Value[16] = secRemains;            // add to the sum bellow x_x_*17_+16
            newProperties[0].Value[17] = secHelper;             // multiply by 2.56
            newProperties[0].Value[20] = 100;
            Pic.SetPropertyItem(newProperties[0]);
            newProperties[1].Id    = 0x0004;
            newProperties[1].Type  = 5;            //5-R 4-L 3-S
            newProperties[1].Len   = length;
            newProperties[1].Value = new byte[length];
            try
            {
                for (int i = 0; i < length; i++)
                {
                    newProperties[1].Value[i] = 0;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error {0}", e.ToString());
            }
            newProperties[1].Value[0] = lonDeg;
            newProperties[1].Value[8] = lonMin;
            secHelper  = (byte)(lonSec / 2.56);
            secRemains = (byte)((lonSec - (secHelper * 2.56)) * 100);
            newProperties[1].Value[16] = secRemains;
            // add to the sum bellow x_x_*17_+16
            newProperties[1].Value[17] = secHelper;
            // multiply by 2.56
            newProperties[1].Value[20] = 100;
            // multiply by 2.56

            //PropertyItem current = Pic.GetPropertyItem(2);
            Pic.SetPropertyItem(newProperties[1]);
            //GPS Version
            newProperties[0].Id       = 0x0000;
            newProperties[0].Type     = 1;
            newProperties[0].Len      = 4;
            newProperties[0].Value[0] = 2;
            newProperties[0].Value[1] = 2;
            newProperties[0].Value[2] = 0;
            newProperties[0].Value[3] = 0;
            Pic.SetPropertyItem(newProperties[0]);

            //GPS Lat REF
            newProperties[0].Id       = 0x0001;
            newProperties[0].Type     = 2;
            newProperties[0].Len      = 2;
            newProperties[0].Value[0] = 78;
            newProperties[0].Value[1] = 0;
            Pic.SetPropertyItem(newProperties[0]);
            //GPS Lon REF
            newProperties[0].Id       = 0x0003;
            newProperties[0].Type     = 2; //5-R 4-L 3-S
            newProperties[0].Len      = 2;
            newProperties[0].Value[0] = 69;
            newProperties[0].Value[1] = 0;
            Pic.SetPropertyItem(newProperties[0]);

            // we cannot store in the same image, so use a temporary image instead
            FilenameTemp = Filename + ".temp";
            // for lossless rewriting must rotate the image by 90 degrees!
            EncParm =
                new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90);
            EncParms.Param[0] = EncParm;
            // now write the rotated image with new description
            Pic.Save(FilenameTemp, CodecInfo, EncParms);
            // for computers with low memory and large pictures: release memory now
            Pic.Dispose();
            Pic = null;
            GC.Collect();
            // delete the original file, will be replaced later
            System.IO.
            File.Delete(Filename);
            // now must rotate back the written picture
            Pic               = Image.FromFile(FilenameTemp);
            EncParm           = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate270);
            EncParms.Param[0] = EncParm;
            Pic.Save(Filename, CodecInfo, EncParms);
            // release memory now
            Pic.Dispose();
            Pic = null;
            GC.Collect();
            // delete the temporary picture
            System.IO.
            File.Delete(FilenameTemp);
        }