当前位置: 首页>>代码示例>>C#>>正文


C# Renderer.CreateImageFile方法代码示例

本文整理汇总了C#中Renderer.CreateImageFile方法的典型用法代码示例。如果您正苦于以下问题:C# Renderer.CreateImageFile方法的具体用法?C# Renderer.CreateImageFile怎么用?C# Renderer.CreateImageFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Renderer的用法示例。


在下文中一共展示了Renderer.CreateImageFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Generate

        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="content">内容</param>
        /// <param name="filePath">保存文件路径</param>
        /// <param name="errorMessage">错误异常消息</param>
        /// <returns></returns>
        public static bool Generate(string content, string filePath, out string errorMessage)
        {
            errorMessage = string.Empty;
            var qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
            try
            {
                QrCode qrCode;
                qrEncoder.TryEncode(content, out qrCode);
                var renderer = new Renderer(5, Brushes.Black, Brushes.White);

                if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                else
                {
                    FileInfo fileInfo = new FileInfo(filePath);
                    if (fileInfo.Exists)
                        fileInfo.Delete();
                }

                renderer.CreateImageFile(qrCode.Matrix, filePath, ImageFormat.Png);
                return true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return false;
            }
        }
开发者ID:iZhongCheng,项目名称:Common.Utility,代码行数:35,代码来源:Q2CodeHelper.cs

示例2: GenerateQR

        public static void GenerateQR(string encodeString, string venueName, string branding)
        {
            //Ask the user for the path where the QR pdf file will be stored.  If canceled, return and do nothing.
            string filePath = GetSaveFilePath();
            if (filePath.Equals(""))
                return;

            QrEncoder encoder = new QrEncoder(ErrorCorrectionLevel.H);
            QrCode code = encoder.Encode(encodeString);

            Renderer renderer = new Renderer(25, System.Drawing.Brushes.Black, System.Drawing.Brushes.White);
            renderer.CreateImageFile(code.Matrix, IMAGE_NAME, ImageFormat.Png);

            PrintToPDF(venueName, branding, filePath);
        }
开发者ID:rickthestick,项目名称:DJClient,代码行数:15,代码来源:QRGenerator.cs

示例3: Generate

        public ActionResult Generate(String longurl)
        {
            var jsonResp = new UrlShortenResponse{
            Success = true
            };

            /*
             *   +--------------------------------------------------------------------------------+
             *   | Step 1: Check if the URL is valid. We will issue a web request and see the     |
             *   |         status code.                                                           |
             *   | Step 2: Check if this URL is already in the system. If exists, return          |
             *   |         We will check for the current user, since we will generate a unique    |
             *   |         URL for each user for a given original URL                             |
             *   | Step 3: Generate short URL. (May be check again if we generated a duplicate?)  |
             *   | Step 4: Generate a QR code for the URL                                         |
             *   | Step 5: Save generated short url and also save the QR image.                   |
             *   | Step 6: Send Json response back to the user.                                   |
             *   +--------------------------------------------------------------------------------+
            */

            #region Step 1 - Check for a valid URL

            bool bValidUrl = true;
            try
            {
                HttpWebRequest request = WebRequest.Create(longurl) as HttpWebRequest;
                request.Method = "GET";
                request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                var response = request.GetResponse();
                bValidUrl = response.Headers.Count > 0;
            }
            catch
            {
                bValidUrl = false;
            }

            if (!bValidUrl)
            {
                return Json(new UrlShortenResponse
                {
                    Success = false,
                    Message = "Please check if the URL is correct and try again."
                }, "text/html");
            }

            String protoPrefix = "http://";
            String webUrl = longurl;
            if (longurl.Contains("://"))
            {
                int iIndex = longurl.IndexOf("://");
                protoPrefix = longurl.Substring(0, iIndex + 3);
                webUrl = longurl.Substring(iIndex + 3);
            }

            #endregion

            #region Step 2-5 - Generate URL and save

            UrlMap url = _UrlMapDataSource.FindSingleUrlByUserName(longurl, User.Identity.Name);
            if (url == null)
            {
                url = new UrlMap();
                url.OriginalUrl = longurl;
                url.DateCreated = DateTime.UtcNow;
                url.IsActive = true;

                //Step 3:
                //Now generate hash for the longUrl;
                uint hash = FNVHash.fnv_32a_str(webUrl + User.Identity.Name);

                //Convert hash to base36
                url.ShortUrlCode = Base36Converter.Encode(hash);

                url.ShortUrl = String.Format("{0}{1}", _URLShortenerHost, url.ShortUrlCode);

                //Step 4:
                QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
                QrCode qrCode = new QrCode();
                qrEncoder.TryEncode(url.ShortUrl, out qrCode);

                Renderer renderer = new Renderer(5, Brushes.Black, Brushes.White);

                String fileName = String.Format("{0}{1}.qr", AppDomain.CurrentDomain.BaseDirectory, url.ShortUrlCode);
                renderer.CreateImageFile(qrCode.Matrix, fileName, ImageFormat.Png);
                jsonResp.QRCodeUrl = String.Format("{0}Home/QRImage/{1}.qr", _URLShortenerHost, url.ShortUrlCode);

                //Save Url Map
                _UrlMapDataSource.AddUrlMap(url, User.Identity.Name);

                //Save method appends the .qr extension
                _UrlMapDataSource.SaveQRCode(fileName, url.ShortUrlCode);
            }
            #endregion

            // Step 6
            jsonResp.Url = url.ShortUrl;
            jsonResp.QRCodeUrl = String.Format("{0}Home/QRImage/{1}.qr", _URLShortenerHost, url.ShortUrlCode);

            return Json(jsonResp, "text/html");
        }
开发者ID:anilnakkala,项目名称:skewrl,代码行数:100,代码来源:HomeController.cs


注:本文中的Renderer.CreateImageFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。