Ejemplo n.º 1
0
        private TableImage CreateImage(IFormFile logoFile, EnumImageType imageType)
        {
            if (logoFile != null && (logoFile.ContentType == "image/png" || logoFile.ContentType == "image/jpeg"))
            {
                var image = new TableImage
                {
                    ImageType = imageType,
                    FileName  = logoFile.FileName,
                    SavedAt   = DateTime.Now,
                };

                byte[] imageData;

                using (var stream = logoFile.OpenReadStream())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        stream.CopyTo(ms);
                        imageData = ms.ToArray();
                    }
                }

                if (imageData.Length == 0)
                {
                    return(null);
                }

                image.File = ImageHelper.ReduceImage(imageData);

                return(image);
            }

            return(null);
        }
        public static Models.ImageSearchResult Search(string apikey,
                                                      string searchTerm               = "",
                                                      EnumLanguage language           = EnumLanguage.en,
                                                      string id                       = "",
                                                      EnumResponseGroup responseGroup = EnumResponseGroup.Image_Details,
                                                      EnumImageType imageType         = EnumImageType.All,
                                                      EnumOrientation orientation     = EnumOrientation.All,
                                                      EnumCategory category           = EnumCategory.All,
                                                      int minWidth                    = 0,
                                                      int minHeight                   = 0,
                                                      bool EditorsChoice              = false,
                                                      bool SafeSearch                 = false,
                                                      int Page    = 1,
                                                      int PerPage = 20
                                                      )
        {
            if (string.IsNullOrEmpty(apikey))
            {
                throw new System.ArgumentNullException("apiKey");
            }

            try
            {
                Models.ImageSearchOptions options = new Models.ImageSearchOptions()
                {
                    ApiKey        = apikey,
                    SearchTerm    = searchTerm,
                    Language      = language,
                    Id            = id,
                    ResponseGroup = responseGroup,
                    ImageType     = imageType,
                    Orientation   = orientation,
                    Category      = category,
                    MinWidth      = minWidth,
                    MinHeight     = minHeight,
                    EditorsChoice = EditorsChoice,
                    SafeSearch    = SafeSearch,
                    Page          = Page,
                    PerPage       = PerPage
                };
                return(SearchWithOptions(options));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据图片名称,返回图片文件
        /// </summary>
        /// <param name="folderName">文件夹名称</param>
        /// <param name="imageName">图片名称</param>
        /// <param name="enumImageType">图片后缀</param>
        /// <returns></returns>
        public Image GetResourcesImage(string folderName, string imageName, EnumImageType enumImageType)
        {
            string imageType = Enum.GetName(typeof(EnumImageType), (int)enumImageType);

            Image bgImage = null;

            try
            {
                string imageFile = "Cnas.wns.Resources." + SkinIconName + "." + folderName + "." + imageName + "." + imageType.ToLower();
                bgImage = Image.FromStream(this.AssemblyWinUI.GetManifestResourceStream(imageFile));
            }
            catch
            {
                return(bgImage = null);
            }

            return(bgImage);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  根据图片名称,返回图片文件流
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="imageName"></param>
        /// <param name="enumImageType"></param>
        /// <returns></returns>
        public Stream GetResourcesStream(string folderName, string imageName, EnumImageType enumImageType)
        {
            string imageType = Enum.GetName(typeof(EnumImageType), (int)enumImageType);

            Stream stream = null;

            try
            {
                string imageFile = "Cnas.wns.Resources." + SkinIconName + "." + folderName + "." + imageName + "." + imageType.ToLower();
                stream = AssemblyWinUI.GetManifestResourceStream(imageFile);
            }
            catch
            {
                return(stream = null);
            }

            return(stream);
        }
Ejemplo n.º 5
0
        public bool SaveImage(int nCamID, EnumImageType type, string filePath, HTuple hWindow, string fileName = "")
        {
            if (nCamID < 0)
            {
                return(false);
            }
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            if (!Directory.Exists(filePath))
            {
                return(false);
            }
            if (ho_image_Copy == null || ho_image_Copy.Key == IntPtr.Zero)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(fileName))
            {
                var DT = DateTime.Now;
                fileName = $"{DT.Year}年{DT.Month}月{DT.Day}日 {DT.Hour}_{DT.Minute}_{DT.Second}_{DT.Millisecond}";
            }

            switch (type)
            {
            case EnumImageType.image:
                HOperatorSet.WriteImage(ho_image_Copy, "jpeg", 0, $"{filePath}\\{fileName}.jpg");
                break;

            case EnumImageType.window:
                HOperatorSet.DumpWindow(hWindow, "jpeg", $"{filePath}\\{fileName}.jpg");
                break;
            }
            ho_image_Copy.Dispose();
            return(true);
        }
Ejemplo n.º 6
0
        private static void DrawSmallText(Graphics g, ImageText smallText, EnumImageStyle style, EnumImageType type, ImageFont imageFont)
        {
            FontFamily font = null;

            if (!imageFont.ifSystem)
            {
                //读取字体文件
                string path = AppDomain.CurrentDomain.BaseDirectory + imageFont.url;
                PrivateFontCollection pfc = new PrivateFontCollection();
                pfc.AddFontFile(path);
                font = pfc.Families[0];
            }
            else
            {
                font = new FontFamily(imageFont.name);
            }
            string drawString = "";

            if (smallText.Order)
            {
                drawString = smallText.Text; // Create font and brush.
            }
            else //反向打印
            {
                drawString = WebApplication.Common.Utils.ReverseCharArray(smallText.Text);
            }
            Font       drawFont = new Font(font, smallText.FontSize); //实例化字体
            SolidBrush drawBrush;
            float      x = smallText.PositionX; float y = smallText.PositionY;

            if (type == EnumImageType.儿童印章)
            {
                drawBrush = new SolidBrush(Color.Black);
            }
            else
            {
                if (style == EnumImageStyle.阳文)
                {
                    drawBrush = new SolidBrush(Color.Red);
                }
                else
                {
                    drawBrush = new SolidBrush(Color.White);
                }
            }
            g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.AntiAlias;
            g.DrawString(drawString, drawFont, drawBrush, x, y);
        }
Ejemplo n.º 7
0
        //private static void DrawMainText(Graphics g, ImageText mainText, EnumImageStyle style, EnumImageType type)
        //{
        //    FontFamily font = null;
        //    if (!mainText.imageFont.ifSystem)
        //    {
        //        //读取字体文件
        //        string path = AppDomain.CurrentDomain.BaseDirectory + mainText.imageFont.url;
        //        PrivateFontCollection pfc = new PrivateFontCollection();
        //        pfc.AddFontFile(path);
        //        font = pfc.Families[0];
        //    }
        //    else
        //    {
        //        font = new FontFamily(mainText.imageFont.name);
        //    }

        //    String drawString = mainText.Text; // Create font and brush.

        //    Font drawFont = new Font(font, mainText.FontSize);    //实例化字体
        //    SolidBrush drawBrush;
        //    float x = mainText.PositionX, y = mainText.PositionY;
        //    if (type == EnumImageType.儿童印章)
        //    {
        //        drawBrush = new SolidBrush(Color.Black); //儿童印章不区分阴文和阳文,统一用黑色文字。
        //    }
        //    else
        //    {
        //        if (style == EnumImageStyle.阳文)
        //        {
        //            drawBrush = new SolidBrush(Color.Red);
        //        }
        //        else
        //        {
        //            drawBrush = new SolidBrush(Color.White);
        //        }
        //    }
        //    ////减缓锯齿
        //    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        //    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        //    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        //    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        //    g.DrawString(drawString, drawFont, drawBrush, x, y);
        //}

        //private static void DrawSmallText(Graphics g, ImageText smallText, EnumImageStyle style, EnumImageType type)
        //{
        //    FontFamily font = null;
        //    if (!smallText.imageFont.ifSystem)
        //    {
        //        //读取字体文件
        //        string path = AppDomain.CurrentDomain.BaseDirectory + smallText.imageFont.url;
        //        PrivateFontCollection pfc = new PrivateFontCollection();
        //        pfc.AddFontFile(path);
        //        font = pfc.Families[0];
        //    }
        //    else
        //    {
        //        font = new FontFamily(smallText.imageFont.name);
        //    }
        //    string drawString = "";
        //    if (smallText.Order)
        //    {
        //        drawString = smallText.Text; // Create font and brush.
        //    }
        //    else //反向打印
        //    {
        //        drawString = WebApplication.Common.Utils.ReverseCharArray(smallText.Text);
        //    }
        //    Font drawFont = new Font(font, smallText.FontSize); //实例化字体
        //    SolidBrush drawBrush;
        //    float x = smallText.PositionX; float y = smallText.PositionY;
        //    if (type == EnumImageType.儿童印章)
        //    {
        //        drawBrush = new SolidBrush(Color.Black);
        //    }
        //    else
        //    {
        //        if (style == EnumImageStyle.阳文)
        //        {
        //            drawBrush = new SolidBrush(Color.Red);
        //        }
        //        else
        //        {
        //            drawBrush = new SolidBrush(Color.White);
        //        }
        //    }
        //    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        //    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        //    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        //    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        //    g.DrawString(drawString, drawFont, drawBrush, x, y);
        //}
        #endregion

        //5-19需求修改,一个印章只有一个字体
        private static void DrawMainText(Graphics g, ImageText mainText, EnumImageStyle style, EnumImageType type, ImageFont imageFont)
        {
            FontFamily font = null;

            if (!imageFont.ifSystem)
            {
                //读取字体文件
                string path = AppDomain.CurrentDomain.BaseDirectory + imageFont.url;
                PrivateFontCollection pfc = new PrivateFontCollection();
                pfc.AddFontFile(path);
                font = pfc.Families[0];
            }
            else
            {
                font = new FontFamily(imageFont.name);
            }

            String drawString = mainText.Text;                       // Create font and brush.

            Font       drawFont = new Font(font, mainText.FontSize); //实例化字体
            SolidBrush drawBrush;
            float      x = mainText.PositionX, y = mainText.PositionY;

            if (type == EnumImageType.儿童印章 || type == EnumImageType.个性签名章)
            {
                drawBrush = new SolidBrush(Color.Black); //儿童印章和个性签名章 不区分阴文和阳文,统一用黑色文字。
            }
            else
            {
                if (style == EnumImageStyle.阳文)
                {
                    drawBrush = new SolidBrush(Color.Red);
                }
                else
                {
                    drawBrush = new SolidBrush(Color.White);
                }
            }
            ////减缓锯齿
            g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.AntiAlias;
            g.DrawString(drawString, drawFont, drawBrush, x, y);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 根据图片名称,返回图片文件,可对文件进行处理后返回
        /// </summary>
        /// <param name="folderName">文件夹名称</param>
        /// <param name="imageName">图片名称</param>
        /// <param name="rectangle">new Rectangle(0, 0, 16, 16)  需要处理的尺寸</param>
        /// <param name="pixelFormat">PixelFormat.Format64bppPArgb 图像像素格式</param>
        /// <param name="enumImageType">图片后缀</param>
        /// <returns></returns>
        public Image GetResourcesImage(string folderName, string imageName, Rectangle rectangle, PixelFormat pixelFormat, EnumImageType enumImageType)
        {
            string imageType = Enum.GetName(typeof(EnumImageType), (int)enumImageType);

            Image bgImage = null;

            try
            {
                string imageFile   = "Cnas.wns.Resources." + SkinIconName + "." + folderName + "." + imageName + "." + imageType.ToLower();
                Bitmap bitmapImage = new Bitmap(Bitmap.FromStream(AssemblyWinUI.GetManifestResourceStream(imageFile)));//帮助
                bgImage = bitmapImage.Clone(rectangle, pixelFormat);
            }
            catch
            {
                return(bgImage = null);
            }

            return(bgImage);
        }
Ejemplo n.º 9
0
 static JDFAutoImageCompression()
 {
     atrInfoTable[0]  = new AtrInfoTable(AttributeName.ANTIALIASIMAGES, 0x33333333, AttributeInfo.EnumAttributeType.boolean_, null, "false");
     atrInfoTable[1]  = new AtrInfoTable(AttributeName.AUTOFILTERIMAGES, 0x33333333, AttributeInfo.EnumAttributeType.boolean_, null, "true");
     atrInfoTable[2]  = new AtrInfoTable(AttributeName.CONVERTIMAGESTOINDEXED, 0x33333333, AttributeInfo.EnumAttributeType.boolean_, null, null);
     atrInfoTable[3]  = new AtrInfoTable(AttributeName.DCTQUALITY, 0x33333333, AttributeInfo.EnumAttributeType.double_, null, "0");
     atrInfoTable[4]  = new AtrInfoTable(AttributeName.DOWNSAMPLEIMAGES, 0x33333333, AttributeInfo.EnumAttributeType.boolean_, null, "false");
     atrInfoTable[5]  = new AtrInfoTable(AttributeName.ENCODECOLORIMAGES, 0x44444443, AttributeInfo.EnumAttributeType.boolean_, null, null);
     atrInfoTable[6]  = new AtrInfoTable(AttributeName.ENCODEIMAGES, 0x33333331, AttributeInfo.EnumAttributeType.boolean_, null, "false");
     atrInfoTable[7]  = new AtrInfoTable(AttributeName.IMAGEAUTOFILTERSTRATEGY, 0x33333311, AttributeInfo.EnumAttributeType.NMTOKEN, null, null);
     atrInfoTable[8]  = new AtrInfoTable(AttributeName.IMAGEDEPTH, 0x33333333, AttributeInfo.EnumAttributeType.integer, null, null);
     atrInfoTable[9]  = new AtrInfoTable(AttributeName.IMAGEDOWNSAMPLETHRESHOLD, 0x33333333, AttributeInfo.EnumAttributeType.double_, null, "2.0");
     atrInfoTable[10] = new AtrInfoTable(AttributeName.IMAGEDOWNSAMPLETYPE, 0x33333333, AttributeInfo.EnumAttributeType.enumeration, EnumImageDownsampleType.getEnum(0), null);
     atrInfoTable[11] = new AtrInfoTable(AttributeName.IMAGEFILTER, 0x33333333, AttributeInfo.EnumAttributeType.NMTOKEN, null, null);
     atrInfoTable[12] = new AtrInfoTable(AttributeName.IMAGERESOLUTION, 0x33333333, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[13] = new AtrInfoTable(AttributeName.IMAGETYPE, 0x22222222, AttributeInfo.EnumAttributeType.enumeration, EnumImageType.getEnum(0), null);
     atrInfoTable[14] = new AtrInfoTable(AttributeName.JPXQUALITY, 0x33333311, AttributeInfo.EnumAttributeType.integer, null, null);
     elemInfoTable[0] = new ElemInfoTable(ElementName.CCITTFAXPARAMS, 0x66666611);
     elemInfoTable[1] = new ElemInfoTable(ElementName.DCTPARAMS, 0x66666611);
     elemInfoTable[2] = new ElemInfoTable(ElementName.JBIG2PARAMS, 0x33333111);
     elemInfoTable[3] = new ElemInfoTable(ElementName.JPEG2000PARAMS, 0x33333111);
     elemInfoTable[4] = new ElemInfoTable(ElementName.LZWPARAMS, 0x66666611);
 }
Ejemplo n.º 10
0
 ///
 ///          <summary> * (9) get attribute ImageType </summary>
 ///          * <returns> the value of the attribute </returns>
 ///
 public virtual EnumImageType getImageType()
 {
     return(EnumImageType.getEnum(getAttribute(AttributeName.IMAGETYPE, null, null)));
 }
Ejemplo n.º 11
0
 //         ---------------------------------------------------------------------
 //        Methods for Attribute ImageType
 //        ---------------------------------------------------------------------
 ///
 ///          <summary> * (5) set attribute ImageType </summary>
 ///          * <param name="enumVar">: the enumVar to set the attribute to </param>
 ///
 public virtual void setImageType(EnumImageType enumVar)
 {
     setAttribute(AttributeName.IMAGETYPE, enumVar == null ? null : enumVar.getName(), null);
 }