예제 #1
0
        private string SaveImage()
        {
            if (!DoesImageNeedHandling)
            {
                return(_originalPath);
            }

            var image = new KalikoImage(Server.MapPath(_originalPath));

            // TODO: Temporary fix for selecting full image, try to do this without loading the image first..
            if (IsCropValueFullImage(image))
            {
                return(_originalPath);
            }

            if (_hasCropValues)
            {
                image.Crop(_cropX, _cropY, _cropW, _cropH);
            }

            if (_width > 0 || _height > 0)
            {
                image.Resize(_width, _height);
            }

            var imagePath  = GetNewImagePath();
            var serverPath = Server.MapPath(imagePath);

            if (File.Exists(serverPath))
            {
                var originalServerPath = Server.MapPath(_originalPath);

                if (File.GetLastWriteTime(originalServerPath) < File.GetLastWriteTime(serverPath))
                {
                    return(imagePath);
                }

                File.Delete(serverPath);
            }

            // TODO: Config quality
            image.SaveJpg(Server.MapPath(imagePath), 90);

            return(imagePath);
        }
예제 #2
0
        /// <summary>
        /// 切割图片
        /// </summary>
        /// <param name="pageCount">切成几张</param>
        /// <returns></returns>
        private List <string> kalikoImage(int pageCount)
        {
            List <string> imageList = new List <string>();

            for (var n = 0; n < pageCount; n++)
            {
                KalikoImage ki = new KalikoImage(SealPath);
                var         w  = ki.Width / pageCount; // 计算每张图片的宽度

                ki.Crop(w * n, 0, w, ki.Height);
                //string path = System.IO.Path.Combine(config.Value.Substring(0, config.Value.LastIndexOf(".")), string.Format("{0}{1}.png", count, n));
                //if (!System.IO.Directory.Exists(config.Value.Substring(0, config.Value.LastIndexOf("."))))
                //{
                //    System.IO.Directory.CreateDirectory(config.Value.Substring(0, config.Value.LastIndexOf(".")));//不存在就创建目录
                //}
                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp", string.Format("{0}{1}.png", pageCount, n));
                ki.SavePng(path);
                ki.Dispose();
                imageList.Add(path);
            }
            return(imageList);
        }
예제 #3
0
            public uint Def_ReadFile(string filename, IntPtr buffer, uint BufferSize, ref uint NumberByteReadSuccess, long Offset, IntPtr info)
            {
                StringBuilder data  = new StringBuilder();
                VNode         Node  = new VNode(filename);
                string        query = "";

                byte[] file = null;

                Console.WriteLine("reading {0} {1} {2}", Node.isValid, Node.fileName, Node.curDir);
                if (Node.isValid && Node.param.TryGetValue("q", out query))
                {
                    #region This Is google Service
                    if (Node.fileName.StartsWith("google", StringComparison.CurrentCultureIgnoreCase))
                    {
                        Task <Google.Apis.Customsearch.v1.Data.Search> ret;
                        if (Node.param.ContainsKey("n"))
                        {
                            int    n    = 1;
                            string temp = "";
                            Node.param.TryGetValue("n", out temp);
                            int.TryParse(temp, out n);
                            ret = ServiceProvider.SearchGoogle(query, n);
                        }
                        else
                        {
                            ret = ServiceProvider.SearchGoogle(query, 1);
                        }
                        ret.Wait();
                        if (ret.Result.Items != null)
                        {
                            foreach (Google.Apis.Customsearch.v1.Data.Result s in ret.Result.Items)
                            {
                                data.AppendLine(s.Title);
                                data.AppendLine("----------------------------------------------------------------");
                                data.AppendLine(s.Snippet);
                                data.AppendLine(s.Link);
                                data.Append("\n");
                            }
                        }
                        Console.WriteLine(data.ToString());
                        file = System.Text.Encoding.ASCII.GetBytes(data.ToString());
                    }
                    #endregion
                }
                else if (Node.curDir == "ImagePass")
                {
                    if (!Node.fileExtention.EndsWith("inf", StringComparison.CurrentCultureIgnoreCase) && !Node.fileExtention.EndsWith("ini", StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (imageFiles.Any(name => name.StartsWith(Node.fileName)))
                        {
                            Console.WriteLine("Direct Read");
                            KalikoImage image = new KalikoImage(filepath + @"\" + imageFiles.Where(d => d.StartsWith(Node.fileName)).ToList()[0]);
                            Console.WriteLine("HEHFKHLDSKHFLSDHLKFHKD *()&*&(&**&(" + image.ByteArray.Length);
                            string width = "", height = "", OP = "", x = "", y = "";
                            System.IO.MemoryStream ms = new System.IO.MemoryStream();

                            Node.param.TryGetValue("op", out OP);
                            if (OP == "s" && Node.param.TryGetValue("w", out width) && Node.param.TryGetValue("h", out width))
                            {
                                int w = 0, h = 0;
                                if (int.TryParse(width, out w) && int.TryParse(width, out h))
                                {
                                    image.Scale(new FitScaling(w, h)).SavePng(ms);
                                }
                            }
                            if (OP == "c" && Node.param.TryGetValue("w", out width) && Node.param.TryGetValue("h", out width) && Node.param.TryGetValue("x", out x) && Node.param.TryGetValue("y", out y))
                            {
                                int w = 0, h = 0, X, Y;

                                if (int.TryParse(width, out w) && int.TryParse(width, out h) && int.TryParse(x, out X) && int.TryParse(y, out Y))
                                {
                                    image.Crop(X, Y, w, h);
                                }
                                image.SavePng(ms);
                            }

                            string ext = Node.fileExtention.ToLowerInvariant();


                            switch (ext)
                            {
                            case "png":
                                image.LoadImage(ms);
                                image.SavePng(ms);

                                break;

                            case "gif":
                                image.LoadImage(ms);
                                image.SaveGif(ms);
                                break;

                            case "bmp":
                                image.LoadImage(ms);
                                image.SaveBmp(ms);
                                break;

                            default:
                                image.LoadImage(ms);
                                image.SaveJpg(ms, 100);
                                break;
                            }
                            file = ms.ToArray();
                        }
                    }
                }


                if (file != null && file.Length != 0 && Offset < file.Length)
                {
                    if (BufferSize > file.Length - Offset)
                    {
                        NumberByteReadSuccess = (uint)(file.Length - Offset);
                        System.Runtime.InteropServices.Marshal.Copy(file, (int)Offset, buffer, (int)NumberByteReadSuccess);
                    }
                    else
                    {
                        NumberByteReadSuccess = BufferSize;
                        System.Runtime.InteropServices.Marshal.Copy(file, (int)Offset, buffer, (int)BufferSize);
                    }
                    return(0);
                }
                else
                {
                    Console.WriteLine("Error param {0}", Node.fileName);
                    return(0xC000000F);
                }
            }