Example #1
0
        public static Bitmap Load(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                //check header
                var header = br.ReadStruct <Header>();
                header.checkConst();

                //decompress table
                br.BaseStream.Position = header.tableDataOffset;
                byte[] table = Decomp(new BinaryReaderX(new MemoryStream(br.ReadBytes(header.tableSize1))));
                //File.OpenWrite("table.bin").Write(table,0,table.Length);

                //get decompressed picture data
                br.BaseStream.Position = header.tableDataOffset + header.tableSize2;
                byte[] tex = Decomp(new BinaryReaderX(new MemoryStream(br.ReadBytes(header.imgDataSize))));
                //File.OpenWrite("xi.bin").Write(tex, 0, tex.Length);

                //order pic blocks by table
                byte[] pic = Order(new BinaryReaderX(new MemoryStream(table)), table.Length, new BinaryReaderX(new MemoryStream(tex)), header.width, header.height, header.bitDepth);
                //File.OpenWrite("pic.bin").Write(pic, 0, pic.Length);

                //return decompressed picture data
                var settings = new ImageCommon.Settings
                {
                    Width         = header.width,
                    Height        = header.height,
                    Orientation   = ImageCommon.Orientation.TransposeTile,
                    Format        = ImageCommon.Settings.ConvertFormat(header.imageFormat),
                    PadToPowerOf2 = false
                };
                return(ImageCommon.Load(pic, settings));
            }
        }
Example #2
0
        private async void GetCatsImages(List <Cats> lstCats)
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                ImageCommon imageCommon = new ImageCommon();
                //ProgressBar progress = null;

                foreach (var cat in lstCats)
                {
                    //loading para cada foto enquanto carrega
                    ProgressBar progress = new ProgressBar(Context);
                    llImages.AddView(progress);

                    string urlFoto = cat.url;
                    var    bitmap  = await imageCommon.GetImageBitmapFromUrlAsync(urlFoto);

                    //Criando o imageView para ser adicionado ao LinearLayout Dinamicamente
                    AppCompatImageView imgView = new AppCompatImageView(Context);
                    imgView.SetPadding(20, 20, 20, 20);
                    imgView.SetImageBitmap(bitmap);

                    //Adicionado o imageView ao LinearLayout
                    llImages.AddView(imgView);

                    //retira o loading
                    llImages.RemoveView(progress);
                }
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="httpPostedFile">待传输文件</param>
        /// <param name="orderId"></param>
        /// <param name="imageType">图片类型</param>
        /// <returns></returns>
        public ImgInfo UploadFile(HttpPostedFile httpPostedFile, string uploadType, UploadFrom uploadFrom)
        {
            ImgInfo imgInfo  = new ImgInfo();
            var     fileName = ETS.Util.ImageTools.GetFileName(Path.GetExtension(httpPostedFile.FileName));

            imgInfo.FileName     = fileName;
            imgInfo.OriginalName = httpPostedFile.FileName;
            int fileNameLastDot = fileName.LastIndexOf('.');
            //原图
            string rFileName = string.Format("{0}{1}", fileName.Substring(0, fileNameLastDot), Path.GetExtension(fileName));

            imgInfo.OriginFileName = rFileName;
            string saveDbFilePath;
            string saveDir     = "";
            string basePath    = Ets.Model.ParameterModel.Clienter.CustomerIconUploader.Instance.GetPhysicalPath(uploadFrom);
            string fullFileDir = ETS.Util.ImageTools.CreateDirectory(basePath, uploadType, out saveDbFilePath);

            imgInfo.FullFileDir    = fullFileDir;
            imgInfo.SaveDbFilePath = saveDbFilePath;
            if (fullFileDir == "0")
            {
                imgInfo.FailRemark = "创建目录失败";
                return(imgInfo);
            }
            var fullFilePath = Path.Combine(fullFileDir, rFileName);

            httpPostedFile.SaveAs(fullFilePath);
            var picUrl = saveDbFilePath + fileName;

            imgInfo.RelativePath = EnumUtils.GetEnumDescription(uploadFrom) + picUrl;
            imgInfo.PicUrl       = ImageCommon.ReceiptPicConvert(uploadFrom, picUrl);
            return(imgInfo);
        }
Example #4
0
        /// <summary>
        /// 上传图片   修改:彭宜    20150710
        /// </summary>
        /// <param name="httpPostedFile">待传输文件</param>
        /// <param name="orderId"></param>
        /// <param name="imageType">图片类型</param>
        /// <returns></returns>
        public ImgInfo UploadImg(HttpPostedFile httpPostedFile, UploadFrom uploadFrom)
        {
            ImgInfo imgInfo = new ImgInfo();

            try
            {
                System.Drawing.Image img = System.Drawing.Image.FromStream(httpPostedFile.InputStream);
            }
            catch (Exception)
            {
                imgInfo.FailRemark = "无图片流";
                return(imgInfo);
            }
            var fileName = ETS.Util.ImageTools.GetFileName(Path.GetExtension(httpPostedFile.FileName));

            imgInfo.FileName     = fileName;
            imgInfo.OriginalName = httpPostedFile.FileName;

            int fileNameLastDot = fileName.LastIndexOf('.');
            //原图
            string rFileName = string.Format("{0}{1}{2}", fileName.Substring(0, fileNameLastDot), SystemConst.OriginSize, Path.GetExtension(fileName));

            //原始的
            imgInfo.OriginFileName = rFileName;
            string saveDbFilePath;
            string saveDir     = "";
            string basePath    = Ets.Model.ParameterModel.Clienter.CustomerIconUploader.Instance.GetPhysicalPath(uploadFrom);
            string fullFileDir = ETS.Util.ImageTools.CreateDirectory(basePath, "", out saveDbFilePath);

            imgInfo.FullFileDir    = fullFileDir;
            imgInfo.SaveDbFilePath = saveDbFilePath;
            if (fullFileDir == "0")
            {
                imgInfo.FailRemark = "创建目录失败";
                return(imgInfo);
            }
            //保存原图,
            ///TODO记录图片大小
            var fullFilePath = Path.Combine(fullFileDir, rFileName);

            httpPostedFile.SaveAs(fullFilePath);
            //裁图
            var transformer = new ETS.Compress.FixedDimensionTransformerAttribute(Ets.Model.ParameterModel.Clienter.CustomerIconUploader.Instance.Width, Ets.Model.ParameterModel.Clienter.CustomerIconUploader.Instance.Height, Ets.Model.ParameterModel.Clienter.CustomerIconUploader.Instance.MaxBytesLength / 1024);
            //保存到数据库的图片路径
            var destFullFileName = System.IO.Path.Combine(fullFileDir, fileName);

            transformer.Transform(fullFilePath, destFullFileName);

            var picUrl = saveDbFilePath + fileName;

            imgInfo.RelativePath = EnumUtils.GetEnumDescription(uploadFrom) + picUrl;
            imgInfo.PicUrl       = ImageCommon.ReceiptPicConvert(uploadFrom, picUrl);
            return(imgInfo);
        }
Example #5
0
        private JsonResult UploadImage(HttpPostedFileBase file, Array filters, int maxSize, string dirPath, ImageType type)
        {
            //分析上传的文件信息,返回解析得到的结果
            Dictionary <string, string> result = Save(file, ConfigInfo.ImageFileterArray, maxSize, dirPath);

            if (result["code"] == "1")
            {
                return(Json(new { code = 1, msg = result["msg"] }));
            }
            //裁剪图片
            var isCurOk = ImageCommon.CutImg(result["path"]);

            if (!isCurOk)
            {
                return(Json(new { code = 3, msg = "裁剪图片失败" }));
            }
            //生成缩略图 TODO 这里要从外面传进来
            isCurOk = ImageCommon.MakeThumbnail(result["path"], Server.MapPath(ConfigInfo.SourceSystemThumbnailPath + result["name"]));
            if (!isCurOk)
            {
                return(Json(new { code = 4, msg = "生成缩略图失败" }));
            }


            Image model = new Image
            {
                //TODO   -  UserID,ISize
                Date      = DateTime.Now,
                IFileName = result["name"],
                Type      = type,
                ImageId   = Guid.NewGuid().ToString().Replace("-", ""),
                IName     = result["name"]
            };

            imageApplication.Add(model);
            if (imageApplication.Commit())
            {
                return(Json(new
                {
                    code = 0,
                    id = model.ImageId,
                    name = model.IFileName,
                    data = model.IFileName,
                    img = model.IFileName
                }));
            }
            return(Json(new { code = 2, msg = "插入到数据库失败" }));
        }
Example #6
0
 public static Bitmap Load(Stream input)
 {
     using (var br = new BinaryReaderX(input))
     {
         var texture  = br.ReadBytes((int)br.BaseStream.Length - 40);
         var header   = br.ReadStruct <Header>();
         var settings = new ImageCommon.Settings
         {
             Width       = header.width,
             Height      = header.height,
             Orientation = header.orientation,
             Format      = ImageCommon.Settings.ConvertFormat(header.format)
         };
         return(ImageCommon.Load(texture, settings));
     }
 }
Example #7
0
        public ResultModel <UploadReceiptResultModel> TicketUpload()
        {
            #region 参数验证
            if (HttpContext.Current.Request.Form.Count == 0)
            {
                return(ResultModel <UploadReceiptResultModel> .Conclude(UploadIconStatus.NOFormParameter));
            }

            var orderId = ParseHelper.ToInt(HttpContext.Current.Request.Form["OrderId"], 0); //订单号
            if (orderId == 0)                                                                // 订单id
            {
                return(ResultModel <UploadReceiptResultModel> .Conclude(UploadIconStatus.InvalidOrderId));
            }
            var clienterId = ParseHelper.ToInt(HttpContext.Current.Request.Form["ClienterId"], 0); //骑士的id
            if (clienterId == 0)                                                                   // 骑士Id
            {
                return(ResultModel <UploadReceiptResultModel> .Conclude(UploadIconStatus.ClienterIdInvalid));
            }
            var needUploadCount = ParseHelper.ToInt(HttpContext.Current.Request.Form["NeedUploadCount"], 1);
            //该订单总共需要上传的 小票数量
            var receiptPic   = HttpContext.Current.Request.Form["ReceiptPicAddress"];                  //小票地址更新时
            var orderChildId = ParseHelper.ToInt(HttpContext.Current.Request.Form["OrderChildId"], 0); //子单号
            if (orderChildId == 0)                                                                     //子订单号
            {
                return(ResultModel <UploadReceiptResultModel> .Conclude(UploadIconStatus.NoOrderChildId));
            }

            if (HttpContext.Current.Request.Files.Count == 0) //图片
            {
                return(ResultModel <UploadReceiptResultModel> .Conclude(UploadIconStatus.InvalidFileFormat));
            }
            var file = HttpContext.Current.Request.Files[0]; //照片

            #endregion

            //上传图片
            ImgInfo imgInfo            = new ImageHelper().UploadImg(file, orderId);
            var     uploadReceiptModel = new UploadReceiptModel
            {
                OrderId         = orderId,
                ClienterId      = clienterId,
                OrderChildId    = orderChildId,
                NeedUploadCount = needUploadCount,
                ReceiptPic      = imgInfo.PicUrl
            };
            LogHelper.LogWriter("上传小票", new { orderId = orderId, clienterId = clienterId, orderChildId = orderChildId, ReceiptPic = imgInfo.PicUrl });
            var orderOther = iClienterProvider.UpdateClientReceiptPicInfo(uploadReceiptModel);
            if (orderOther == null)
            {
                return(ResultModel <UploadReceiptResultModel> .Conclude(UploadIconStatus.UpFailed, new UploadReceiptResultModel()
                {
                    OrderId = orderId
                }));
            }
            else
            {
                List <OrderChildImg> listOrderChild = new List <OrderChildImg>();
                listOrderChild.Add(new OrderChildImg()
                {
                    OrderChildId = orderChildId,
                    TicketUrl    = ImageCommon.ReceiptPicConvert(uploadReceiptModel.ReceiptPic)
                });
                if (!string.IsNullOrWhiteSpace(receiptPic))  //当有地址的时候删除
                {
                    ImageHelper imgHelper = new ImageHelper();
                    imgHelper.DeleteTicket(receiptPic);
                }
                //上传成功后返回图片全路径
                return(ResultModel <UploadReceiptResultModel> .Conclude(UploadIconStatus.Success, new UploadReceiptResultModel()
                {
                    OrderId = orderId, OrderChildList = listOrderChild, HadUploadCount = orderOther.HadUploadCount, NeedUploadCount = orderOther.NeedUploadCount
                }));
            }
        }
 /// <summary>
 /// 鉴定图片信息(根据图片文件信息)
 /// </summary>
 /// <param name="formFile">文件信息</param>
 /// <param name="webProxy">代理信息</param>
 /// <param name="cookie">cookie信息</param>
 /// <returns></returns>
 public ContentInfoDto ImgAuthenticateByFile(IFormFile formFile, WebProxy webProxy = null, string cookie = "")
 {
     return(ImgAuthenticateByBase64(ImageCommon.GetBase64(formFile), webProxy));
 }
Example #9
0
        //private void readImages()
        //{
        //    //currentOMC.InitReadPicturesParameters(tVLeft.Nodes.Count, (float)-0.45, (float)-0.5);
        //    int total = tVLeft.Nodes.Count;

        //    ImageCommon imagecommon = new ImageCommon();
        //    int cpucore = imagecommon.availCPUCore(tVLeft.Nodes[0].Name);

        //    if ((cpucore > 1) & (cpucore <= 3))
        //        cpucore = 2;
        //    if ((cpucore >= 4) & (cpucore <= 7))
        //        cpucore = 4;
        //    if (cpucore >= 8)
        //        cpucore = 8;

        //    int num = 0;
        //    //FetchImage fim1; // fim2, fim3, fim4;

        //    var watch = Stopwatch.StartNew();
        //    watch.Start();
        //    if (tVLeft.Nodes.Count > 0)
        //    {
        //        this.pictureBox1.Image = Image.FromFile(tVLeft.Nodes[0].Name);
        //        this.toolStripStatusLabel1.Text = "";
        //        if (this.checkBox1.Checked)
        //            backThread.ReportProgress(1, total); // 第一个进度,10%
        //        else
        //        {
        //            this.toolStripProgressBar1.Maximum = tVLeft.Nodes.Count;
        //            this.toolStripProgressBar1.Value = 1;
        //            this.pictureBox1.Refresh();
        //        }

        //        switch (cpucore)
        //        {
        //            case 1:  // 单核处理器
        //                //fim1 = new FetchImage(currentOMC);

        //                for (int i = 0; i < tVLeft.Nodes.Count; i++)
        //                {
        //                    var curwatch = Stopwatch.StartNew();
        //                    curwatch.Start();

        //                    currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                    //fim1.ReadPicturesByFileName(tVLeft.Nodes[i].Name, i);

        //                    var t1 = new Task(() =>
        //                    {
        //                        readImageTask(num,0);
        //                    });
        //                    t1.Start();

        //                    Task.WaitAll(t1);
        //                    num += 1;

        //                    curwatch.Stop();
        //                    this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 1))).ToString("0.0") + " 秒";

        //                    this.pictureBox1.Image = Image.FromFile(tVLeft.Nodes[i].Name);
        //                    if (this.checkBox1.Checked)
        //                        backThread.ReportProgress(i+1, total); // 第一个进度,10%
        //                    else
        //                    {
        //                        this.toolStripProgressBar1.Value = i+1;
        //                        this.pictureBox1.Refresh();
        //                    }

        //                }
        //                //fim1.Destroy();
        //                GC.Collect();
        //                break;
        //            case 2:  // 2 核处理器
        //                #region
        //                for (int i = 0; i < tVLeft.Nodes.Count; )
        //                {
        //                    var curwatch = Stopwatch.StartNew();
        //                    curwatch.Start();

        //                    currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                    var t1 = new Task(() =>
        //                    {
        //                        readImageTask(num,0);
        //                    });
        //                    t1.Start();
        //                    i++;

        //                    if (i < tVLeft.Nodes.Count)
        //                    {
        //                        currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                        var t2 = new Task(() =>
        //                        {
        //                            readImageTask(num + 1,0);
        //                        });
        //                        t2.Start();
        //                        try
        //                        {
        //                            Task.WaitAll(t1, t2);
        //                        }
        //                        catch
        //                        {
        //                            MessageBox.Show("并行计算出错!");
        //                        }
        //                        num += 2;
        //                        curwatch.Stop();
        //                        this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 2))).ToString("0.0") + " 秒";

        //                        i++;
        //                    }
        //                    else
        //                    {
        //                        Task.WaitAll(t1);

        //                        num += 1;
        //                        curwatch.Stop();
        //                        this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 1))).ToString("0.0") + " 秒";
        //                    }

        //                   this.pictureBox1.Image = Image.FromFile(tVLeft.Nodes[i - 1].Name);
        //                   if (this.checkBox1.Checked)
        //                        backThread.ReportProgress(i, total); // 第一个进度,10%
        //                    else
        //                    {
        //                        this.toolStripProgressBar1.Value = i;
        //                        this.Refresh();
        //                     }

        //                    GC.Collect();
        //                }
        //                #endregion
        //                break;
        //            case 4:  // 4 核处理器
        //                #region
        //                for (int i = 0; i < tVLeft.Nodes.Count; )
        //                {
        //                    var curwatch = Stopwatch.StartNew();
        //                    curwatch.Start();

        //                    currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                    var t1 = new Task(() =>
        //                    {
        //                        readImageTask(num,0);
        //                    });
        //                    t1.Start();
        //                    i++;

        //                    if (i < tVLeft.Nodes.Count)  // 启动 2 号任务
        //                    {
        //                        currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                        var t2 = new Task(() =>
        //                        {
        //                            readImageTask(num + 1,0);
        //                        });
        //                        t2.Start();
        //                        i++;

        //                        if (i < tVLeft.Nodes.Count)  // 启动 3 号任务
        //                        {
        //                            currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                            var t3 = new Task(() =>
        //                            {
        //                                readImageTask(num + 2,0);
        //                            });
        //                            t3.Start();
        //                            i++;

        //                            if (i < tVLeft.Nodes.Count) //启动 4 号任务
        //                            {
        //                                currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                                var t4 = new Task(() =>
        //                                {
        //                                    readImageTask(num + 3,0);
        //                                });
        //                                t4.Start();
        //                                i++;

        //                                Task.WaitAll(t1, t2, t3, t4);

        //                                num += 4;
        //                                curwatch.Stop();
        //                                this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 4))).ToString("0.0") + " 秒";

        //                            }
        //                            else
        //                            {
        //                                Task.WaitAll(t1, t2, t3);

        //                                num += 3;
        //                                curwatch.Stop();
        //                                this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 3))).ToString("0.0") + " 秒";
        //                            }
        //                        }
        //                        else
        //                        {
        //                            Task.WaitAll(t1, t2);

        //                            num += 2;
        //                            curwatch.Stop();
        //                            this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 2))).ToString("0.0") + " 秒";
        //                        }
        //                    }
        //                    else
        //                    {
        //                        Task.WaitAll(t1);

        //                        num += 1;
        //                        curwatch.Stop();
        //                        this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 1))).ToString("0.0") + " 秒";
        //                    }

        //                    this.pictureBox1.Image = Image.FromFile(tVLeft.Nodes[i - 1].Name);
        //                    if (this.checkBox1.Checked)
        //                        backThread.ReportProgress(i, total); // 第一个进度,10%
        //                    else
        //                    {
        //                        this.toolStripProgressBar1.Value = i;
        //                        this.pictureBox1.Refresh();
        //                    }

        //                    GC.Collect();
        //                }
        //                #endregion
        //                break;
        //            case 8: // 8 核处理器
        //                #region
        //                for (int i = 0; i < tVLeft.Nodes.Count; )
        //                {
        //                    var curwatch = Stopwatch.StartNew();
        //                    curwatch.Start();

        //                    currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字

        //                    var t1 = new Task(() =>
        //                    {
        //                        readImageTask(num,0);
        //                    });
        //                    t1.Start();
        //                    i++;

        //                    if (i < tVLeft.Nodes.Count)  // 启动 2 号任务
        //                    {
        //                        currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                        var t2 = new Task(() =>
        //                        {
        //                            readImageTask(num + 1,0);
        //                        });
        //                        t2.Start();
        //                        i++;

        //                        if (i < tVLeft.Nodes.Count)  // 启动 3 号任务
        //                        {
        //                            currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                            var t3 = new Task(() =>
        //                            {
        //                                readImageTask(num + 2,0);
        //                            });
        //                            t3.Start();
        //                            i++;

        //                            if (i < tVLeft.Nodes.Count) //启动 4 号任务
        //                            {
        //                                currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                                var t4 = new Task(() =>
        //                                {
        //                                    readImageTask(num + 3,0);
        //                                });
        //                                t4.Start();
        //                                i++;

        //                                if (i < tVLeft.Nodes.Count) // 启动 5 号任务
        //                                {
        //                                    currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                                    var t5 = new Task(() =>
        //                                    {
        //                                        readImageTask(num + 4,0);
        //                                    });
        //                                    t5.Start();
        //                                    i++;

        //                                    if (i < tVLeft.Nodes.Count)  // 启动 6 号任务
        //                                    {
        //                                        currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                                        var t6 = new Task(() =>
        //                                        {
        //                                            readImageTask(num + 5,0);
        //                                        });
        //                                        t6.Start();
        //                                        i++;

        //                                        if (i < tVLeft.Nodes.Count) // 启动 7 号任务
        //                                        {
        //                                            currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                                            var t7 = new Task(() =>
        //                                            {
        //                                                readImageTask(num + 6,0);
        //                                            });
        //                                            t7.Start();
        //                                            i++;

        //                                            if (i < tVLeft.Nodes.Count) //启动 8 号任务
        //                                            {
        //                                                currentOMC.readFileNames[i] = tVLeft.Nodes[i].Name; // 保存读入的文件名字
        //                                                var t8 = new Task(() =>
        //                                                {
        //                                                    readImageTask(num + 7,0);
        //                                                });
        //                                                t8.Start();
        //                                                i++;

        //                                                Task.WaitAll(t1, t2, t3, t4, t5, t6, t7, t8);

        //                                                num += 8;
        //                                                curwatch.Stop();
        //                                                this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 8))).ToString("0.0") + " 秒";

        //                                            }
        //                                            else
        //                                            {
        //                                                Task.WaitAll(t1, t2, t3, t4, t5, t6, t7);

        //                                                num += 7;
        //                                                curwatch.Stop();
        //                                                this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 7))).ToString("0.0") + " 秒";
        //                                            }
        //                                        }
        //                                        else
        //                                        {
        //                                            Task.WaitAll(t1, t2, t3, t4, t5, t6);

        //                                            num += 6;
        //                                            curwatch.Stop();
        //                                            this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 6))).ToString("0.0") + " 秒";
        //                                        }
        //                                    }
        //                                    else
        //                                    {
        //                                        Task.WaitAll(t1, t2, t3, t4, t5);

        //                                        num += 5;
        //                                        curwatch.Stop();
        //                                        this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 5))).ToString("0.0") + " 秒";
        //                                    }
        //                                }
        //                                else
        //                                {
        //                                    Task.WaitAll(t1, t2, t3, t4);

        //                                    num += 4;
        //                                    curwatch.Stop();
        //                                    this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 4))).ToString("0.0") + " 秒";
        //                                }
        //                            }
        //                            else
        //                            {
        //                                Task.WaitAll(t1, t2, t3);

        //                                num += 3;
        //                                curwatch.Stop();
        //                                this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 3))).ToString("0.0") + " 秒";
        //                            }
        //                        }
        //                        else
        //                        {
        //                            Task.WaitAll(t1, t2);

        //                            num += 2;
        //                            curwatch.Stop();
        //                            this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 2))).ToString("0.0") + " 秒";
        //                        }
        //                    }
        //                    else
        //                    {
        //                        Task.WaitAll(t1);

        //                        num += 1;
        //                        curwatch.Stop();
        //                        this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  当前照片用时:" + ((float)(curwatch.ElapsedMilliseconds / (1000 * 1.0 * 1))).ToString("0.0") + " 秒";
        //                    }

        //                    this.pictureBox1.Image = Image.FromFile(tVLeft.Nodes[i - 1].Name);
        //                    if (this.checkBox1.Checked)
        //                        backThread.ReportProgress(i, total); // 第一个进度,10%
        //                    else
        //                    {
        //                        this.toolStripProgressBar1.Value = i;
        //                        this.pictureBox1.Refresh();
        //                    }

        //                    GC.Collect();
        //                }
        //                #endregion

        //                break;
        //        }
        //    }
        //    watch.Stop();
        //    this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  总用时:" + ((float)(watch.ElapsedMilliseconds / 1000 * 1.0)).ToString("0.0") + " 秒,平均用时: " + ((float)(watch.ElapsedMilliseconds / (1000 * total * 1.0))).ToString("0.0") + " 秒, 照片总数:" + total.ToString();

        //}
        private void readImagesUseBatch()
        {
            // 按照片处理批次数量 进行照片读取
            //currentOMC.InitReadPicturesParameters(tVLeft.Nodes.Count, (float)-0.45, (float)-0.5);
            int total = tVLeft.Nodes.Count;

            ImageCommon imagecommon = new ImageCommon();
            int         cpucore     = imagecommon.availCPUCore(tVLeft.Nodes[0].Name);

            if ((cpucore > 1) & (cpucore <= 3))
            {
                cpucore = 2;
            }
            if ((cpucore >= 4) & (cpucore <= 7))
            {
                cpucore = 4;
            }
            if (cpucore >= 8)
            {
                cpucore = 8;
            }

            if (tVLeft.Nodes.Count > 0)
            {
                this.pictureBox1.Image          = Image.FromFile(tVLeft.Nodes[0].Name);
                this.toolStripStatusLabel1.Text = "";
                if (this.checkBox1.Checked)
                {
                    backThread.ReportProgress(1, total); // 第一个进度,10%
                }
                else
                {
                    this.toolStripProgressBar1.Maximum = tVLeft.Nodes.Count;
                    this.toolStripProgressBar1.Value   = 1;
                    this.pictureBox1.Refresh();
                }
            }

            int nper = currentOMC.numInProBatch;
            int k    = this.tVLeft.Nodes.Count;
            int nb   = 0;

            if (Math.Round((float)k / nper) * nper == k)
            {
                nb = (int)Math.Round((float)k / nper);
            }
            else
            {
                nb = (int)Math.Round((float)k / nper + 0.5);
            }
            // 定义 按批量数量 读取照片时,可以分为 多少 批次 读取

            int start = 0, end = 0;

            var watch = Stopwatch.StartNew();

            watch.Start();
            for (int a = 0; a < nb; a++)
            {
                start = a * nper;
                if (a * nper + nper < total)
                {
                    end = a * nper + nper;
                }
                else
                {
                    end = total;
                }
                readBatch(start, end, cpucore, total); // 每批次读取照片
                currentOMC.SaveTmpData(start, end, a);
                if (a > 0)
                {
                    currentOMC.ClearDataArray((a - 1) * nper, (a - 1) * nper + nper); // 把上一批次读取的 pictureCodeDataArray 数组内容失效
                }
            }
            watch.Stop();
            this.toolStripStatusLabel1.Text = "多核心运行:" + cpucore.ToString() + "  总用时:" + ((float)(watch.ElapsedMilliseconds / 1000 * 1.0)).ToString("0.0") + " 秒,平均用时: " + ((float)(watch.ElapsedMilliseconds / (1000 * total * 1.0))).ToString("0.0") + " 秒, 照片总数:" + total.ToString();
        }
Example #10
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file"></param>
        /// <param name="filters"></param>
        /// <param name="maxSize"></param>
        /// <param name="dirPath"></param>
        /// <param name="type"></param>
        /// <param name="isCut">是否不需要裁剪</param>
        /// <returns></returns>
        private JsonResult UploadImage(HttpPostedFileBase file, Array filters, int maxSize, string dirPath, string thumbnailPath, ImageType type, bool isCut)
        {
            //TODO  这里要支持不裁剪!!!!!

            //分析上传的文件信息,返回解析得到的结果
            Dictionary <string, string> result = Save(file, ConfigInfo.ImageFileterArray, maxSize, dirPath);
            int intImageType = (int)type;

            if (result["code"] == "1")
            {
                return(Json(new { code = 1, msg = result["msg"] }));
            }
            //裁剪图片
            var isCurOk = true;

            if (isCut)
            {
                if (type == ImageType.Music)//音乐需要特殊的裁剪
                {
                    isCurOk = ImageCommon.CutImg(result["path"], 200, 200);
                }
                else
                {
                    isCurOk = ImageCommon.CutImg(result["path"]);
                }
                if (!isCurOk)
                {
                    return(Json(new { code = 3, msg = "裁剪图片失败" }));
                }
            }

            if (string.Empty != thumbnailPath)//不需要生成缩略图
            {
                isCurOk = ImageCommon.MakeThumbnail(result["path"], Server.MapPath(thumbnailPath) + result["name"]);
                if (!isCurOk)
                {
                    return(Json(new { code = 4, msg = "生成缩略图失败" }));
                }
            }
            Image model = new Image
            {
                //TODO   -  UserID
                Date           = DateTime.Now,
                IFileName      = result["name"],
                Type           = type,
                ReferenceCount = 0,
                ISize          = file.ContentLength,//TODO 这里要显示裁剪字节信息,不能用原始的
                ImageId        = SaidCommon.GUID,
                IName          = result["name"]
            };

            imageApplication.Add(model);
            if (imageApplication.Commit())
            {
                return(Json(new
                {
                    code = 0,
                    model = model
                }));
            }
            return(Json(new { code = 2, msg = "插入到数据库失败" }));
        }