Beispiel #1
0
        //browse and show image
        private void browseBtn_Click(object sender, EventArgs e)
        {
            //display OpenFileDialog to select gif
            OpenFileDialog openFile = new OpenFileDialog();

            //filter just GIF files
            openFile.Filter = "GIF Files|*.gif";
            //title of OpenFileDialog Window
            openFile.Title = "Select a GIF Image";
            //show dialog
            //if user press ok the open GIF file
            if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //show image on picture box
                sourcePath.Text = openFile.FileName.ToString();
                using (var fs = new System.IO.FileStream(openFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    var ms = new System.IO.MemoryStream();
                    fs.CopyTo(ms);
                    ms.Position = 0;
                    if (sourceGif.Image != null)
                    {
                        sourceGif.Image.Dispose();
                    }
                    sourceGif.Image = Image.FromStream(ms);
                }
            }
        }//end browse method here
Beispiel #2
0
        /// <summary>
        /// 输出静态资源
        /// </summary>
        /// <param name="request"></param>
        /// <param name="urlPath"></param>
        /// <param name="path"></param>
        protected virtual void WriteStaticFile(HttpRequest request, string urlPath, string path)
        {
            var filePath = System.IO.Path.Combine(path, urlPath);

            if (System.IO.Directory.Exists(filePath))
            {
                filePath = System.IO.Path.Combine(filePath, "index.html");
                if (System.IO.File.Exists(filePath))
                {
                    var url = $"{System.IO.Path.Combine(request.Url.AbsolutePath, "index.html")}{request.Url.Query}";
                    request.Context.Response.Redirect(url);
                    request.Context.Response.Close();
                    return;
                }
            }
            if (System.IO.File.Exists(filePath))
            {
                var mimeMapping = MimeMapping.GetMimeMapping(filePath);
                request.Context.Response.AddHeader("Content-type", $"{mimeMapping};charset=utf-8");
                using (System.IO.FileStream fileStream = System.IO.File.Open(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
                {
                    fileStream.CopyTo(request.Context.Response.OutputStream);
                }
                request.Context.Response.Close();
                return;
            }
            request.Context.Response.StatusCode = 404;
            request.Context.Response.Close();
            return;
        }
Beispiel #3
0
        /// <summary>
        /// 生成二维码(320*320)
        /// </summary>
        /// <param name="text">文本内容</param>
        /// <param name="savePath">保存路径</param>
        /// <param name="logoPath">Logo图片路径(缩放到真实二维码区域尺寸的1/6)</param>
        /// <param name="keepWhiteBorderPixelVal">白边处理(负值表示不做处理,最大值不超过真实二维码区域的1/10)</param>
        public static void QRCoder(string text, string savePath, string logoPath = "", int keepWhiteBorderPixelVal = -1)
        {
            var format = GetImageFormatByPath(savePath);

            byte[] bytesLogo = null;
            if (!string.IsNullOrEmpty(logoPath) && System.IO.File.Exists(logoPath))
            {
                var fsLogo = new System.IO.FileStream(logoPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                fsLogo.CopyTo(ms);
                fsLogo.Dispose();
                bytesLogo = ms.ToArray();
                ms.Dispose();
            }

            var bytes = QRCoder(text, format, bytesLogo, keepWhiteBorderPixelVal);

            if (bytes == null || bytes.Length < 1)
            {
                return;
            }

            var saveDirPath = System.IO.Path.GetDirectoryName(savePath);

            if (!System.IO.Directory.Exists(saveDirPath))
            {
                System.IO.Directory.CreateDirectory(saveDirPath);
            }
            var fs = new System.IO.FileStream(savePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.None);

            fs.Write(bytes, 0, bytes.Length);
            fs.Close();
        }
Beispiel #4
0
 public void Compress()
 {
     using (var streamUncompressed = new System.IO.FileStream(@"C:\Users\Adrian\Downloads\2008_civic_sedan.pdf", System.IO.FileMode.Open))
         using (var streamCompressed = new System.IO.FileStream(@"C:\Users\Adrian\Downloads\2008_civic_sedan.z", System.IO.FileMode.Create))
         {
             var deflateStream = new System.IO.Compression.DeflateStream(streamCompressed, System.IO.Compression.CompressionMode.Compress);
             streamUncompressed.CopyTo(deflateStream);
         }
 }
Beispiel #5
0
        /// <summary>
        /// Return a file stream with position set to 0 on a file on disk
        /// </summary>
        public static System.IO.MemoryStream GetFileStream(string fileLocation)
        {
            System.IO.MemoryStream returnStream = null;
            using (System.IO.FileStream stream = new System.IO.FileStream(fileLocation, System.IO.FileMode.Open))
            {
                returnStream = new System.IO.MemoryStream();
                stream.CopyTo(returnStream);
            }

            returnStream.Position = 0;
            return(returnStream);
        }
        } // End Static Constructor

        public byte[] GetFont(string faceName)
        {
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                string ttfFile = s_SupportedFonts[0];

                using (System.IO.FileStream ttf = System.IO.File.OpenRead(ttfFile))
                {
                    ttf.CopyTo(ms);
                    ms.Position = 0;
                    return(ms.ToArray());
                }
            }
        }
Beispiel #7
0
 /*
  * Открыть
  */
 private void MenuItem_ClickOpen(object sender, RoutedEventArgs e)
 {
     System.IO.MemoryStream memoStream = new System.IO.MemoryStream();
     System.Windows.Forms.OpenFileDialog open_dialog = new
                                                       System.Windows.Forms.OpenFileDialog();
     open_dialog.Filter = "bmp рисунок (*.bmp)|*.bmp|" +
                          "Jpg рисунок (*.jpg, *.jpeg)|*.jpg; *.jpeg|" +
                          "Png рисунок (*.png)|*.png";
     if (open_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string file_name = open_dialog.FileName;
         string path      = System.IO.Path.GetFullPath(file_name);
         using (System.IO.FileStream fs = System.IO.File.OpenRead(file_name))
         {
             fs.CopyTo(memoStream);
             BitmapImage bmi = new BitmapImage();
             bmi.BeginInit();
             bmi.StreamSource = memoStream;
             try
             {
                 bmi.EndInit();
                 ImageBrush brush = new ImageBrush(bmi);
                 canvas.Background = brush;
                 fs.Close();
             }
             catch (System.IO.FileFormatException eee)
             {
                 MessageBox.Show("Неизвестный формат изображения или " +
                                 "изображение повреждено");
             }
             catch (COMException ce)
             {
                 if (ce.ErrorCode == 0x88982F61)
                 {
                     MessageBox.Show("Неизвестный формат изображения или " +
                                     "изображение повреждено");
                 }
             }
         }
     }
 }
        public static System.IO.MemoryStream ConvertPdfFileToStream(string file_name)
        {
            if (!System.IO.File.Exists(file_name))
            {
                throw new Exception("File does not exist.");
            }

            System.IO.MemoryStream dest_stream = null;
            try
            {
                using (var fs = new System.IO.FileStream(file_name, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    dest_stream = new System.IO.MemoryStream();
                    fs.CopyTo(dest_stream);
                }
            }
            catch (Exception excpt)
            {
                System.Diagnostics.Debug.WriteLine(excpt);
            }
            return(dest_stream);
        }
Beispiel #9
0
        internal static System.IO.FileInfo CompressGZip(System.IO.FileInfo OriginFile)
        {
            string destiFullName = string.Format("{0}{1}.gz", System.IO.Path.GetTempPath(), OriginFile.Name);

            using (System.IO.FileStream inFile = OriginFile.OpenRead())
            {
                // Create the compressed file.
                using (System.IO.FileStream outFile =
                           System.IO.File.Create(destiFullName))
                {
                    using (System.IO.Compression.GZipStream Compress =
                               new System.IO.Compression.GZipStream(outFile,
                                                                    System.IO.Compression.CompressionMode.Compress))
                    {
                        // Copy the source file into
                        // the compression stream.
                        inFile.CopyTo(Compress);
                    }
                }
            }
            return(new System.IO.FileInfo(destiFullName));
        }
        public ImposeSingleTypesetPdf(CockleFilePdf imposeReadyCocklePdf, TypeOfBindEnum bind_type, bool hasCover)
        {
            // interrupt if file doesn't exist
            if (!System.IO.File.Exists(imposeReadyCocklePdf.FullName))
            {
                return;
            }

            // convert to stream
            System.IO.MemoryStream orig_mem_stream;
            using (var fs = new System.IO.FileStream(imposeReadyCocklePdf.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                orig_mem_stream = new System.IO.MemoryStream();
                fs.CopyTo(orig_mem_stream);
            }
            if (null == orig_mem_stream)
            {
                return;
            }

            // initialize properties
            OrigCockleReadyFile = imposeReadyCocklePdf;
            BindType            = bind_type;
            HasCover            = hasCover;
            if (HasCover)
            {
                if (null != OrigCockleReadyFile.CoverLength)
                {
                    LengthOfCover = OrigCockleReadyFile.CoverLength;
                }
                else
                {
                    LengthOfCover = PdfCropAndNUp.StaticUtils.GetCoverLength_FirstPageTypesetPdf(OrigCockleReadyFile.FullName);
                }
            }
            // run imposition
            carryOutImposition(orig_mem_stream);
        }
        private void GenerateReport(IList <SellerReportDTO> pLstSellerReports, string pStrSeller, string pStrAuction, string pStrSellerMail)
        {
            try
            {
                ReportDocument lObjReportDocument = null;

                lObjReportDocument = new SellerReportToSend();

                lObjReportDocument.SetDataSource(pLstSellerReports);
                lObjReportDocument.SetParameterValue("AuctionsFolio", pStrAuction);
                lObjReportDocument.SetParameterValue("SellerName", pStrSeller);

                //Crystal Report to MemoryStream Conversion
                using (System.IO.MemoryStream lObjMemoryStream = new System.IO.MemoryStream())
                {
                    using (
                        System.IO.FileStream lStreamPDF = (System.IO.FileStream)lObjReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat))
                    {
                        lStreamPDF.CopyTo(lObjMemoryStream);

                        System.IO.StreamWriter lObjWriter = new System.IO.StreamWriter(lStreamPDF);

                        lObjWriter.Write("x");
                        lObjWriter.Flush();
                        lObjWriter.Dispose();
                        lObjMemoryStream.Position = 0;

                        string lStrFileName = pStrSeller + pStrAuction + DateTime.Now.ToString("DDmmss") + ".PDF";

                        mObjMailSenderService.SendMail(lObjMemoryStream, pStrSellerMail, lStrFileName);
                    }
                }
            }
            catch (System.Exception lObjException)
            {
                //throw; ignore
            }
        }
Beispiel #12
0
        private void _CompressZIP(string pathFileZip, IDTSComponentEvents componentEvents)
        {
            System.IO.DirectoryInfo di   = new System.IO.DirectoryInfo(_folderSource);
            System.IO.FileInfo[]    fi_s = di.GetFiles("*.*", (_recurse ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly));
            bool b = false;

            try
            {
                using (ICSharpCode.SharpZipLib.Zip.ZipOutputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(System.IO.File.Create(pathFileZip)))
                {
                    fz.SetLevel(9);

                    if (!string.IsNullOrEmpty(_comment))
                    {
                        componentEvents.FireInformation(1, "UnZip SSIS", "Set Comment.", null, 0, ref b);
                        fz.SetComment(_comment);
                    }

                    if (!string.IsNullOrWhiteSpace(_password))
                    {
                        componentEvents.FireInformation(1, "UnZip SSIS", "Set Password.", null, 0, ref b);
                        fz.Password = _password;
                    }


                    foreach (System.IO.FileInfo fi in fi_s)
                    {
                        if (!System.Text.RegularExpressions.Regex.Match(fi.FullName, _fileFilter).Success)
                        {
                            componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": file " + fi.FullName + " doesn't match regex filter '" + _fileFilter + "'. File not processed.", null, 0, ref b);
                            continue;
                        }

                        componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": Compress (with '" + _storePaths.ToString() + "') file: " + fi.FullName, null, 0, ref b);

                        string file_name = "";
                        ICSharpCode.SharpZipLib.Zip.ZipEntry ze = null;

                        if (_storePaths == Store_Paths.Absolute_Paths)
                        {
                            //Absolute Path
                            file_name = ICSharpCode.SharpZipLib.Zip.ZipEntry.CleanName(fi.FullName);
                            ze        = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name);
                        }
                        else if (_storePaths == Store_Paths.Relative_Paths)
                        {
                            //Relative Path
                            ICSharpCode.SharpZipLib.Zip.ZipNameTransform zn = new ICSharpCode.SharpZipLib.Zip.ZipNameTransform(_folderSource);
                            file_name = zn.TransformFile(fi.FullName);
                            if (_addRootFolder)
                            {
                                file_name = (di.Name + "/" + file_name).Replace("//", "/");
                            }
                            ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name);
                        }
                        else if (_storePaths == Store_Paths.No_Paths)
                        {
                            //No Path
                            file_name = fi.Name;
                            ze        = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name);
                        }
                        else
                        {
                            throw new Exception("Please select type Store Paths (No_Paths / Relative_Paths / Absolute_Paths).");
                        }

                        using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                        {
                            ze.Size = fs.Length;
                            fz.PutNextEntry(ze);

                            fs.CopyTo(fz);

                            fs.Flush();
                            fz.Flush();

                            fz.CloseEntry();
                        }
                    }

                    fz.Flush();
                }

                _Check_ZIP(pathFileZip, componentEvents);
            }
            catch (Exception ex)
            {
                componentEvents.FireError(1000, "UnZip SSIS", ex.Message, null, 0);
                throw;
            }
            finally
            {
            }
        }
Beispiel #13
0
        private void _CompressTAR(string pathFileTAR, IDTSComponentEvents componentEvents, System.IO.Stream stream)
        {
            bool b = false;

            System.IO.DirectoryInfo di   = new System.IO.DirectoryInfo(_folderSource);
            System.IO.FileInfo[]    fi_s = di.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

            if (stream == null)
            {
                stream = System.IO.File.Create(pathFileTAR);
            }

            using (ICSharpCode.SharpZipLib.Tar.TarOutputStream tar = new ICSharpCode.SharpZipLib.Tar.TarOutputStream(stream))
            {
                foreach (System.IO.FileInfo fi in fi_s)
                {
                    if (!System.Text.RegularExpressions.Regex.Match(fi.FullName, _fileFilter).Success)
                    {
                        componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": file " + fi.FullName + " doesn't match regex filter '" + _fileFilter + "'. File not processed.", null, 0, ref b);
                        continue;
                    }

                    componentEvents.FireInformation(1, "UnZip SSIS", _typeCompression.ToString() + ": Compress (with '" + _storePaths.ToString() + "') file: " + fi.FullName, null, 0, ref b);
                    string fileName = fi.FullName;

                    if (_storePaths == Store_Paths.Absolute_Paths)
                    {
                        //Absolute Path
                        fileName = fi.FullName.Replace("\\", "/").Substring(3);
                    }
                    else if (_storePaths == Store_Paths.Relative_Paths)
                    {
                        //Relative Path
                        fileName = fileName.Replace(_folderSource, "").Replace("\\", "/");
                        if (_addRootFolder)
                        {
                            fileName = (di.Name + "/" + fileName).Replace("//", "/");
                        }
                    }
                    else if (_storePaths == Store_Paths.No_Paths)
                    {
                        //No Path
                        fileName = fi.Name;
                    }
                    else
                    {
                        throw new Exception("Please select type Store Paths (No_Paths / Relative_Paths / Absolute_Paths).");
                    }

                    using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        ICSharpCode.SharpZipLib.Tar.TarEntry te = ICSharpCode.SharpZipLib.Tar.TarEntry.CreateTarEntry(fileName);
                        te.Size = fs.Length;
                        tar.PutNextEntry(te);

                        fs.CopyTo(tar);

                        fs.Flush();
                        tar.Flush();

                        tar.CloseEntry();
                    }
                }

                tar.Flush();
                tar.Close();
            }
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            var xml = GenerateDataFromDataSource(GetData());

            using (System.IO.FileStream stream = new System.IO.FileStream(@"E:\currentdevelopment\cresa\Cresa\test.docx", System.IO.FileMode.Open))
            {
                using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
                {
                    stream.CopyTo(memStream);
                    WmlDocument wmlDoc = new WmlDocument("template1.doc", memStream);

                    bool templateError;
                    WmlDocument wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, xml, out templateError);

                    string imageid = "";
                   // using (System.IO.FileStream fs = System.IO.File.OpenRead(@"E:\currentdevelopment\cresa\Buildings_Curtis Block_.jpg"))
                  //  {

                  //      imageid= InsertPicture(wmlAssembledDoc, fs);
                  //  }

                    OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(wmlAssembledDoc);

                    using (WordprocessingDocument wordDoc = streamDoc.GetWordprocessingDocument())
                    {
                        for (int i=1; i<=2;i ++)
                        {
                            using (System.IO.FileStream fs = System.IO.File.OpenRead(@"E:\currentdevelopment\cresa\Buildings_Curtis Block_.jpg"))
                            {
                                MainDocumentPart mainPart = wordDoc.MainDocumentPart;
                                ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
                                imagePart.FeedData(fs);

                                imageid = mainPart.GetIdOfPart(imagePart);
                            }
                            var el = AddImageToBody(imageid);

                            foreach (var  txt  in wordDoc.MainDocumentPart.Document.Body.Descendants<Text>().Where(x=>x.Text.StartsWith("<BUILDING_IMAGE")))
                            {
                                try
                                {
                                    txt.Parent.AppendChild(el);
                                    txt.Text = "";
                                }
                                catch { }

                               // Console.WriteLine(txt);

                            }
                           // wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(el)));
                        }

                    }

                    streamDoc.GetModifiedDocument().SaveAs("testzz.doc");
                  //  wmlAssembledDoc.SaveAs("template2.doc");

                }
            }
        }
Beispiel #15
0
        private void OptimizeGif()
        {
            string filename   = outputFileName.Text;
            string outputPath = Outputpath.Text;

            if (string.IsNullOrWhiteSpace(filename.ToString()) || string.IsNullOrWhiteSpace(outputPath.ToString()))
            {
                MessageBox.Show("Please provide output filename and path");
            }
            else
            {
                string ExeToUse = string.Empty;

                if (Environment.Is64BitOperatingSystem == true)
                {
                    ExeToUse = "gifopt64.exe";
                }
                else
                {
                    ExeToUse = "gifopt32.exe";
                }

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.CreateNoWindow  = true;
                psi.UseShellExecute = false;
                psi.WindowStyle     = ProcessWindowStyle.Hidden;
                psi.FileName        = ExeToUse;

                string        CompressValue = compressLevel.Text;
                StringBuilder ArgsString    = new StringBuilder();

                ArgsString.Append(" -O=" + CompressValue + " ");
                if (lossy.Value > 0)
                {
                    ArgsString.Append(" --lossy=" + lossy.Value.ToString());
                }

                if (colorReduction.Value > 0)
                {
                    ArgsString.Append(" --colors=" + colorReduction.Value.ToString());
                }

                if (gifWidth.Text != "0" && gifHeight.Text != "0")
                {
                    ArgsString.Append(" --resize-fit " + gifWidth.Text + "x" + gifHeight.Text + " ");
                }

                ArgsString.Append("\"" + sourcePath.Text + "\"");
                ArgsString.Append(" -o " + "\"" + outputPath + "\\" + filename + ".gif" + "\"");

                //MessageBox.Show(ArgsString.ToString());

                psi.Arguments = ArgsString.ToString();

                Process.Start(psi).WaitForExit();

                using (var fs = new System.IO.FileStream(outputPath + "\\" + filename + ".gif", System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    var ms = new System.IO.MemoryStream();
                    fs.CopyTo(ms);
                    ms.Position = 0;
                    if (optimizedGif.Image != null)
                    {
                        optimizedGif.Image.Dispose();
                    }
                    optimizedGif.Image = Image.FromStream(ms);
                }
            } //end check else here
        }     //optimizegif ends here
Beispiel #16
-1
        // GET: Home/GZPost
        public FileResult GZPost(int id = 0)
        {
            if (id <= 0)
            { return null; }
            else
            {
                string fileName = GetFilePath(id);
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.MemoryStream postMemory = new System.IO.MemoryStream();
                    using (System.IO.FileStream postFile = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
                    {
                        postFile.CopyTo(postMemory);
                        postFile.Close();
                    }
                    postMemory.Position = 0;
                    FileStreamResult model = new FileStreamResult(postMemory, "application/json");
                    Response.AppendHeader("Content-Encoding", "gzip");

                    return model;
                }
                else
                { return null; }
            }
        }