Exemple #1
0
        public async Task <ActionResult <object> > PostImg()
        {
            string root = "pcx/";

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            PCXcontainer containerTemp = new PCXcontainer();

            containerTemp.IPaddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            ImgUpload temp = new ImgUpload();

            Request.Headers["filename"] = Regex.Replace(Request.Headers["filename"], "[^a-zA-Z0-9% ._]", string.Empty);
            containerTemp.filename      = Request.Headers["filename"] + ".pcx";
            containerTemp.originalImg   = root + DateTime.Now.ToString("dd-MM-yyyy-hh_mm-ss-ffff") + "_" + Request.Headers["filename"] + ".pcx";
            temp.FileName = containerTemp.filename;
            using (var fs = new FileStream("wwwroot/" + containerTemp.originalImg, FileMode.Create))
            {
                Request.Body.CopyTo(fs);
            }

            try
            {
                var      extension       = ImageExtensions.GetImageFormat(Request.Headers["extension"]);
                var      stringExtension = Request.Headers["extension"];
                PCXImage image           = new PCXImage("wwwroot/" + containerTemp.originalImg);
                containerTemp.version = image.FileVersion;
                Bitmap convertedImage = new Bitmap(image.Image);
                image.Dispose();

                using (var bitmap = new Bitmap(convertedImage))
                {
                    string filename = root + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss-ffff") + "_" + Request.Headers["filename"] + stringExtension;
                    bitmap.Save("wwwroot/" + filename, extension);
                    containerTemp.convertedImg = filename;
                }
                containerTemp.dateTime       = DateTime.Now;
                containerTemp.downloadFormat = stringExtension;
                containerTemp.height         = convertedImage.Height;
                containerTemp.width          = convertedImage.Width;
                convertedImage.Dispose();
                _context.PCXcontainers.RemoveRange(_context.PCXcontainers.OrderBy(x => x.dateTime).Take(_context.PCXcontainers.Count() - 4));
                _context.PCXcontainers.Add(containerTemp);
                await _context.SaveChangesAsync();

                temp.id = _context.PCXcontainers.Last().id;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                return(NotFound());
            }
            return(temp);
        }
Exemple #2
0
        public static PCXImage GetPCXImage(PCXImage pcximage)
        {
            PCXImage pImage = new PCXImage();

            pImage.IsBinary    = pcximage.IsBinary;
            pImage.IsDraw      = pcximage.IsDraw;
            pImage.OldFilename = pcximage.OldFilename;
            pImage.PcxData     = pcximage.PcxData;
            pImage.PcxSize     = pcximage.PcxSize;
            return(pImage);
        }
        public static void SetSelectedPCXImage(string dirPath)
        {
            DirectoryInfo dir = new DirectoryInfo(dirPath);

            DirectoryInfo[] ChildDirectory;             //子目录集
            FileInfo[]      files = dir.GetFiles();
            ChildDirectory = dir.GetDirectories("*.*"); //得到子目录集

            int number = 0;

            //if (pcxlist.Count > 20) // pcxlist.Count > 20 逻辑思维有错误,因为是递归调用
            //{
            //    pcxlist = new List<PCXImage>();
            //}
            foreach (FileInfo file in files)
            {
                // 首先是初始化,PCX图片是自己处理的对象
                if (file.Extension.ToLower().Equals(".pcx"))
                {
                    number += 1;
                    Image    image    = PCXHelper.LoadPCX(file.FullName);
                    PCXImage pcximage = PCXHelper.GetPCXImage(file.FullName);
                    PCXImage pImage   = PCXHelper.GetPCXImage(pcximage);
                    pcxlist.Add(pImage); // 这里的一个错误就是就是直接添加pcxlist.Add(pcximage)

                    #region Linq to object
                    //var bindFileList = from fileList in userfilelist
                    //                   select new BindFile
                    //                   {
                    //                       IconPath = ImageIconBind(fileList.FileExtend),
                    //                       LastWriteTime = fileList.LastWriteTime,
                    //                       Length = fileList.Length + "b",
                    //                       Name = fileList.FullName,
                    //                       FullName = fileList.FullName,
                    //                       UploaderInfo = fileList.UploaderInfo
                    //                   };
                    #endregion

                    pcxlist.ToList();
                }
            }
            pcxlist             = pcxlist.ToList();
            selPcxImage.DirPath = dirPath;
            selPcxImage.Number  = number;
            selPcxImage.PcxList = pcxlist;

            //递归子目录
            foreach (DirectoryInfo dirInfo in ChildDirectory)
            {
                SetSelectedPCXImage(dirInfo.FullName);
            }
        }
        /*
         * ToolStripMenuItem控件所处理的事件
         */

        #region 文件菜单

        // 关于"打开"菜单的单击事件
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofdlg = new OpenFileDialog();
            ofdlg.InitialDirectory = @"C:\";
            //ofdlg.Filter = "Image Files (*.pcx,*.bmp, *.jpg,*png)|*.pcx;*.jpg;*.bmp;*.png";
            ofdlg.Filter = "Image Files (*.pcx)|*.pcx|All Files (*.*)|*.*";
            if (ofdlg.ShowDialog() == DialogResult.OK)
            {
                string filename = ofdlg.FileName;
                //this.pictureBox.Image = Image.FromFile(filename); //C#中不能直接操作PCX图片
                Image imageToSet = null;
                imageToSet = PCXHelper.LoadPCX(filename);
                this.pcxImage = PCXHelper.GetPCXImage(filename);
                pictureBox.Image = imageToSet;
            }
        }
        public void TestWrite()
        {
            pcx = new PCXImage(16, 16);
            for (int i = 0; i < pcx.Data.Length; ++i)
            {
                pcx.Data[i]    = (byte)i;
                pcx.Palette[i] = new Color(255, i, i, i);
            }
            pcx.Hdpi = 72;
            pcx.Vdpi = 72;

            byte[] data;
            using (MemoryStream ms = new MemoryStream())
            {
                pcx.Write(ms);
                data = ms.ToArray();
            }

            Assert.AreEqual(TestUtils.GetArrayFromResourceStream("carpet.pcx"), data);
        }
        private void confirmButton_Click(object sender, EventArgs e)
        {
            if (selectedSampleListBox.Items.Count == 0)
            {
                MessageBox.Show(this, "你没有选择训练样本,请先选择", "提示信息", MessageBoxButtons.OK);
            }
            else
            {
                List <PCXImage> pcxList = new List <PCXImage>();
                int             count   = selectedSampleListBox.Items.Count;
                IList           list    = selectedSampleListBox.Items;
                List <string>   strlist = (List <string>)SelectedPCXHelper.ListConvert(list);
                foreach (string str in strlist)
                {
                    string   filename = string.Format(@"{0}", str);
                    Image    image    = PCXHelper.LoadPCX(filename);
                    PCXImage pcximage = PCXHelper.GetPCXImage(filename);
                    PCXImage pImage   = PCXHelper.GetPCXImage(pcximage);
                    pcxList.Add(pImage);
                }
                pcxList = pcxList.ToList();
                SelectedPCXHelper.SetSelPCXFromLB(pcxList, textDirPath.Text);

                List <PCXImage> unselpcxList = new List <PCXImage>();
                IList           unsellist    = unSelSampleListBox.Items;
                List <string>   unselstrlist = (List <string>)SelectedPCXHelper.ListConvert(unsellist);
                foreach (string str in unselstrlist)
                {
                    string   filename = string.Format(@"{0}", str);
                    Image    image    = PCXHelper.LoadPCX(filename);
                    PCXImage pcximage = PCXHelper.GetPCXImage(filename);
                    PCXImage pImage   = PCXHelper.GetPCXImage(pcximage);
                    unselpcxList.Add(pImage);
                }
                unselpcxList = unselpcxList.ToList();
                SelectedPCXHelper.SetUnselPCXList(unselpcxList, textDirPath.Text);
                this.Close();
            }
        }
Exemple #7
0
        public Bitmap LoadPCX(Stream fs, out System.Drawing.Color[] palette)
        {
            PCXImage img = new PCXImage();

            img.Read(fs);

            Bitmap     res     = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
            BitmapData bmpData =
                res.LockBits(new Rectangle(0, 0, img.Width, img.Height),
                             System.Drawing.Imaging.ImageLockMode.ReadWrite,
                             res.PixelFormat);
            IntPtr ptr    = bmpData.Scan0;
            int    stride = img.Width * 3;

            byte[] rgbData = img.GetRGBData();
            for (int y = 0; y < res.Height; ++y)
            {
                System.Runtime.InteropServices.Marshal.Copy(rgbData, y * stride, ptr + y * bmpData.Stride, stride);
            }
            res.UnlockBits(bmpData);

            palette = Utils.LDPaletteToGDIPalette(img.Palette);
            return(res);
        }
Exemple #8
0
 /// <summary>
 /// Loads water map
 /// </summary>
 /// <returns></returns>
 internal byte[,] LoadWaterMap()
 {
     return(PCXImage.Read(OpenDatFile("water.pcx")));
 }
Exemple #9
0
 /// <summary>
 /// Loads the offset map
 /// </summary>
 /// <returns></returns>
 internal byte[,] LoadOffsetMap()
 {
     return(PCXImage.Read(OpenDatFile("offset.pcx")));
 }
Exemple #10
0
 /// <summary>
 /// Loads the terrain map
 /// </summary>
 /// <returns></returns>
 internal byte[,] LoadTerrainMap()
 {
     return(PCXImage.Read(OpenDatFile("terrain.pcx")));
 }
        public static DataSet InitDataset()
        {
            dt.Columns.Add("文件夹", typeof(string));
            dt.Columns.Add("类别", typeof(string));

            string colname = string.Empty;

            for (int i = 2, j = 1; i < 26; i++, j++)
            {
                colname = string.Format("ET1({0})", j.ToString());
                dt.Columns.Add(colname, typeof(string));
                // featureDataGridView.Columns[colname].Width = 50;
            }

            for (int i = 26, j = 1; i < 50; i++, j++)
            {
                colname = string.Format("DT12({0})", j.ToString());
                dt.Columns.Add(colname, typeof(string));
            }

            #region DataGridView初始化
            //DataGridViewTextBoxColumn column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            //DataGridViewTextBoxColumn column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            //this.SuspendLayout();

            //column1.HeaderText = "文件夹";
            //column1.Name = "Column1";
            //column1.Width = 100;
            //column2.HeaderText = "类别";
            //column2.Name = "Column2";
            //column2.Width = 50;
            //this.featureDataGridView.Columns.AddRange(new DataGridViewColumn[] {
            //column1,
            //column2});

            //for (int i = 2, j = 1; i < 26; i++, j++)
            //{
            //    DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
            //    colname = string.Format("ET1({0})", j.ToString());
            //    column.HeaderText = colname;
            //    column.Width = 50;
            //    this.featureDataGridView.Columns.AddRange(column);
            //}

            //for (int i = 26, j = 1; i < 50; i++, j++)
            //{
            //    DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
            //    colname = string.Format("DT12({0})", j.ToString());
            //    column.HeaderText = colname;
            //    column.Width = 60;
            //    this.featureDataGridView.Columns.AddRange(column);
            //}
            #endregion

            pcxlist     = SelectedPCXHelper.GetSelPCXFromLB();
            testpcxlist = SelectedPCXHelper.GetUnselPCXList();
            foreach (PCXImage pcx in pcxlist)
            {
                DataRow row = dt.NewRow();//ds.Tables[0].NewRow();

                PCXImage pImage = new PCXImage();
                pImage.IsBinary    = pcx.IsBinary;
                pImage.IsDraw      = pcx.IsDraw;
                pImage.OldFilename = pcx.OldFilename;
                pImage.PcxData     = pcx.PcxData;
                pImage.PcxSize     = pcx.PcxSize;
                string filenameF = pImage.OldFilename;
                int    charindex = filenameF.LastIndexOf("\\");
                //获取文件名 而不是路径名
                string filename = filenameF.Substring(charindex + 1);
                int    _index   = filename.IndexOf("-");
                string typename = filename.Substring(_index - 2, 2);
                row[0] = filename;
                row[1] = typename;
                dt.Rows.Add(row);
                //ds.Tables[0].Rows.Add(row);
            }
            ds.Tables.Add(dt);
            //DataView view = ds.Tables[0].DefaultView;
            return(ds);
        }
 public void Setup()
 {
     pcx = new PCXImage();
 }