Пример #1
0
    /// <summary>
    /// 在图片上添加水印文字
    /// </summary>
    /// <param name="memoryStream">图片流</param>
    /// <param name="waterText">水印文字</param>
    /// <param name="position">水印位置</param>
    /// <param name="alpha">透明度(0.1-1.0数值越小透明度越高)</param>
    /// <returns></returns>
    public static bool AddImageText(ref MemoryStream memoryStream, string waterText, ImagePosition position, double alpha)
    {
        if (alpha < 0 || alpha > 1 || string.IsNullOrWhiteSpace(waterText))
        {
            return(false);
        }

        Image imgPhoto = null;

        try
        {
            imgPhoto     = Image.FromStream(memoryStream);
            imgPhoto     = AddImageTextDeal(waterText, position, alpha, imgPhoto);
            memoryStream = new MemoryStream();
            imgPhoto.Save(memoryStream, ImageFormat.Jpeg);
            imgPhoto.Dispose();

            return(true);
        }
        catch
        {
            imgPhoto?.Dispose();
            return(false);
        }
    }
Пример #2
0
    public static void Label(Rect area, GUIContent content, float padding, GUIStyle callingFrom)
    {
        //GUIStyle prevStyle = GUI.skin.label;
        //GUI.skin.label = callingFrom;
        TextAnchor    prevAlign    = GUI.skin.label.alignment;
        ImagePosition prevImagePos = GUI.skin.label.imagePosition;
        RectOffset    prevBorder   = GUI.skin.label.border;
        RectOffset    prevMargin   = GUI.skin.label.margin;
        RectOffset    prevPadding  = GUI.skin.label.padding;
        RectOffset    prevOverflow = GUI.skin.label.overflow;
        int           fontSize     = GUI.skin.label.fontSize;

        GUI.skin.label.alignment     = callingFrom.alignment;
        GUI.skin.label.imagePosition = callingFrom.imagePosition;
        GUI.skin.label.border        = callingFrom.border;
        GUI.skin.label.margin        = callingFrom.margin;
        GUI.skin.label.padding       = callingFrom.padding;
        GUI.skin.label.overflow      = callingFrom.overflow;
        GUI.skin.label.fontSize      = callingFrom.fontSize;

        Label(area, content, padding);

        GUI.skin.label.alignment     = prevAlign;
        GUI.skin.label.imagePosition = prevImagePos;
        GUI.skin.label.border        = prevBorder;
        GUI.skin.label.margin        = prevMargin;
        GUI.skin.label.padding       = prevPadding;
        GUI.skin.label.overflow      = prevOverflow;
        GUI.skin.label.fontSize      = fontSize;
        //GUI.skin.label = prevStyle;
    }
        //==============================================================================

        /**
         *	@brief	Set imagePosition to GUIStyle and return it.
         *
         *	@param	style	If null then create new GUIStyle. Otherwise return direct it.
         *	@param	imagePosition	ImagePosition.
         *
         *	@return	Builded GUIStyle
         */
        //==============================================================================
        public static GUIStyle ImagePos(this GUIStyle style, ImagePosition imagePosition = default(ImagePosition))
        {
            GUIStyle s = GetOrCreate(style);

            s.imagePosition = imagePosition;
            return(s);
        }
Пример #4
0
    /// <summary>
    /// Display the GUI buttons for alignment features
    /// </summary>
    /// <param name="forceUseful">
    /// <see cref="true"/> to force the Fall button enabled if a selection is made : it can only align on Position
    /// </param>
    public static void AlignButtonGUI(Transform[] userSelection, bool forceUseful)
    {
        bool GuiWasEnabled = GUI.enabled;

        GUI.enabled = (userSelection.Length > 1);
        ImagePosition wasPosition = GUI.skin.button.imagePosition;

        GUI.skin.button.imagePosition = AlignEditor.ButtonStyle;

        GUIContent minValueGuiContent = new GUIContent("Min", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/alignMin.png", typeof(Texture)) as Texture, "Align on minimum " + AlignEditor.axis + " value");

        if (GUILayout.Button(minValueGuiContent))
        {
            // Align to the min value
            AlignEditor.landmark = AlignManager.Landmark.minimum;
            Align();
        }
        GUIContent meanValueGuiContent = new GUIContent("Medium", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/alignMean.png", typeof(Texture)) as Texture, "Align on medium " + AlignEditor.axis + " value");

        if (GUILayout.Button(meanValueGuiContent))
        {
            // Align to the center
            AlignEditor.landmark = AlignManager.Landmark.mean;
            Align();
        }
        GUIContent maxValueGuiContent = new GUIContent("Max", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/alignMax.png", typeof(Texture)) as Texture, "Align on maximum " + AlignEditor.axis + " value");

        if (GUILayout.Button(maxValueGuiContent))
        {
            // Align to the max value
            AlignEditor.landmark = AlignManager.Landmark.maximum;
            Align();
        }
        GUIContent lineDistributionGuiContent = new GUIContent("Distribute", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/lineDistribution.png", typeof(Texture)) as Texture, "Make a linear distribution on " + AlignEditor.axis + " axis");

        if (GUILayout.Button(lineDistributionGuiContent))
        {
            // Distribute objects
            AlignEditor.landmark = AlignManager.Landmark.distributed;
            Distribute();
        }
        GUIContent switchValuesGuiContent = new GUIContent("Switch", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/switch.png", typeof(Texture)) as Texture, "Switch " + Tools.current.ToString() + " values");

        if (GUILayout.Button(switchValuesGuiContent))
        {
            // Switch values on objects
            SwitchValues();
        }

        GUI.enabled = (userSelection.Length >= 1) && (AlignEditor.PositionTool || forceUseful);

        if (GUILayout.Button(new GUIContent("Fall", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/fall.png", typeof(Texture)) as Texture, "Fall on terrain or objects downside")))
        {
            // Distribute objects
            AlignEditor.landmark = AlignManager.Landmark.minimum;
            FallOnTerrain();
        }
        GUI.enabled = GuiWasEnabled;
        GUI.skin.button.imagePosition = wasPosition;
    }
Пример #5
0
        public static void SetListViewImage(XPListView lst, string ImagePath, ImagePosition Position)
        {
            int x = 0;
            int y = 0;

            GetImageLocation(Position, ref x, ref y);

            try
            {
                LVBKIMAGE apiItem = new LVBKIMAGE();
                apiItem.pszImage       = ImagePath + Convert.ToChar(0);
                apiItem.cchImageMax    = ImagePath.Length;
                apiItem.ulFlags        = LVBKIF_SOURCE_URL | LVBKIF_STYLE_NORMAL;
                apiItem.xOffsetPercent = x;
                apiItem.yOffsetPercent = y;

                // Set the background colour of the ListView to 0XFFFFFFFF (-1) so it will be transparent
                int clear = CLR_NONE;
                SendMessage(lst.Handle, LVM_SETTEXTBKCOLOR, 0, ref clear);

                SendMessage(lst.Handle, LVM_SETBKIMAGE, 0, ref apiItem);
            }
            catch (Exception ex)
            {
                throw new System.Exception("An exception in ListViewAPI.SetListViewImage occured: " + ex.Message);
            }
        }
Пример #6
0
        public static void Makewater(Image image, string waterImagePath, Point p, ImagePosition imagePosition)
        {
            using (Image image2 = Image.FromFile(waterImagePath))
            {
                using (Graphics graphics = Graphics.FromImage(image))
                {
                    graphics.CompositingQuality = CompositingQuality.HighQuality;
                    graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphics.SmoothingMode      = SmoothingMode.HighQuality;
                    switch (imagePosition)
                    {
                    case ImagePosition.BottomLeft:
                        p.Y = (image.Height - image2.Height) - p.Y;
                        break;

                    case ImagePosition.BottomRight:
                        p.Y = (image.Height - image2.Height) - p.Y;
                        p.X = (image.Width - image2.Width) - p.X;
                        break;

                    case ImagePosition.TopRigth:
                        p.X = (image.Width - image2.Width) - p.X;
                        break;
                    }
                    graphics.DrawImage(image2, new Rectangle(p, new Size(image2.Width, image2.Height)));
                }
            }
        }
Пример #7
0
            public static void SetListViewImage(IntPtr listHandle, string imagePath, ImagePosition position)
            {
                if (listHandle == IntPtr.Zero)
                {
                    return;
                }

                int x = 0, y = 0;

                GetImageLocation(position, out x, out y);

                try
                {
                    var apiItem = new LVBKIMAGE();
                    apiItem.pszImage       = Marshal.StringToCoTaskMemUni(imagePath);
                    apiItem.cchImageMax    = imagePath.Length;
                    apiItem.ulFlags        = LVBKIF_SOURCE_URL | LVBKIF_STYLE_NORMAL;
                    apiItem.xOffsetPercent = x;
                    apiItem.yOffsetPercent = y;

                    // Set the background color of the ListView to 0XFFFFFFFF (-1) so it will be transparent
                    var clear = new IntPtr(-1);
                    SendMessage(listHandle, W32_LVM.LVM_SETTEXTBKCOLOR, IntPtr.Zero, ref clear);

                    SendMessage(listHandle, W32_LVM.LVM_SETBKIMAGEW, 0, ref apiItem);
                }
                catch (Exception ex)
                {
                    throw new Exception("An exception in API.SetListViewImage occured: " + ex.Message);
                }
            }
Пример #8
0
        public static void Makewater(Image image, String waterImagePath, Point p, ImagePosition imagePosition)
        {
            using (Image warterImage = Image.FromFile(waterImagePath))
            {
                using (Graphics newGp = Graphics.FromImage(image))
                {
                    newGp.CompositingQuality = CompositingQuality.HighQuality;
                    //设置高质量插值法
                    newGp.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    //设置高质量,低速度呈现平滑程度
                    newGp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    switch (imagePosition)
                    {
                    case ImagePosition.BottomLeft:
                        p.Y = image.Height - warterImage.Height - p.Y;
                        break;

                    case ImagePosition.TopRigth:
                        p.X = image.Width - warterImage.Width - p.X;
                        break;

                    case ImagePosition.BottomRight:
                        p.Y = image.Height - warterImage.Height - p.Y;
                        p.X = image.Width - warterImage.Width - p.X;
                        break;
                    }
                    newGp.DrawImage(warterImage, new Rectangle(p, new Size(warterImage.Width, warterImage.Height)));
                }
            }
        }
Пример #9
0
 /// <summary>
 /// Add a custom image to the PDF document.
 /// </summary>
 /// <param name="image">The byte array of the image.</param>
 /// <param name="imageLocation">The image signature starting position as System.Drawing.Point.</param>
 /// <param name="pageNumber">The page where the image will be inserted. Use 0 to insert image on all pages.</param>
 /// <param name="imagePostition">The image position. This could be over the content or under the content (as background).</param>
 public void AddImage(byte[] image, Point imageLocation, int pageNumber, ImagePosition imagePostition)
 {
     try
     {
         if (image == null)
         {
             throw new ArgumentNullException(CustomExceptions.CustomImageIsNull);
         }
         if (pageNumber < 0 || pageNumber > this.DocumentProperties.NumberOfPages)
         {
             throw new ArgumentOutOfRangeException(CustomExceptions.InvalidPageNumber);
         }
         CustomImage customImage = new CustomImage()
         {
             Image = image,
             StartingPointPosition = imageLocation,
             PageNumber            = pageNumber,
             AddImageAsWatermark   = false,
             ImagePosition         = imagePostition
         };
         this.customImageList.Add(customImage);
     }
     catch
     {
         throw;
     }
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="callerType"></param>
 /// <param name="borderStyle"></param>
 /// <param name="dataSource"></param>
 /// <param name="dataMember"></param>
 /// <param name="valueMember"></param>
 /// <param name="imageMember"></param>
 /// <param name="imagePosition"></param>
 /// <param name="imageSize"></param>
 /// <param name="displayFormat"></param>
 internal MyFreeComboBox(Type callerType, EnhancedBorderStyle borderStyle, object dataSource, string dataMember,
                         string valueMember, string imageMember, ImagePosition imagePosition, Size imageSize,
                         string displayFormat)
     : base(callerType, borderStyle, dataSource, dataMember, valueMember, imageMember, imagePosition, imageSize,
         displayFormat)
 {
     base.ValidateText = false;
 }
Пример #11
0
    static int IntToEnum(IntPtr L)
    {
        int           arg0 = (int)LuaDLL.lua_tonumber(L, 1);
        ImagePosition o    = (ImagePosition)arg0;

        LuaScriptMgr.PushEnum(L, o);
        return(1);
    }
Пример #12
0
 /// シングルタッチした際のパラメータセット
 private void setSingleTapParam()
 {
     singleDTapBackPos      = singleTapParam.Pos;
     singleTapParam.Pos.X   = useTouch.GetScrPosX(0);
     singleTapParam.Pos.Y   = useTouch.GetScrPosY(0);
     singleTapParam.TouchId = useTouch.GetInputId(0);
     singleTouchFlg         = true;
     singleFlicFlg          = false;
 }
Пример #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="callerType"></param>
 /// <param name="borderStyle"></param>
 /// <param name="dataSource"></param>
 /// <param name="dataMember"></param>
 /// <param name="valueMember"></param>
 /// <param name="imageMember"></param>
 /// <param name="imagePosition"></param>
 /// <param name="imageSize"></param>
 /// <param name="displayFormat"></param>
 internal MyFreeComboBox(Type callerType, EnhancedBorderStyle borderStyle, object dataSource, string dataMember,
                         string valueMember, string imageMember, ImagePosition imagePosition, Size imageSize,
                         string displayFormat)
     : base(
         callerType, borderStyle, dataSource, dataMember, valueMember, imageMember, imagePosition, imageSize,
         displayFormat)
 {
     base.ValidateText = false;
 }
Пример #14
0
 public static GUIStyle ImagePosition(this GUIStyle current, ImagePosition imagePosition, bool asCopy = true)
 {
     if (asCopy)
     {
         current = new GUIStyle(current);
     }
     current.imagePosition = imagePosition;
     return(current);
 }
Пример #15
0
    public static void SettingsButtonGUI()
    {
        ImagePosition wasPosition = GUI.skin.button.imagePosition;

        GUI.skin.button.imagePosition = AlignEditor.ButtonStyle;
        if (GUILayout.Button(new GUIContent("Settings", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/settings.png", typeof(Texture)) as Texture, "Open the settings popup")))
        {
            DisplaySettingsWindow();
        }
        GUI.skin.button.imagePosition = wasPosition;
    }
Пример #16
0
        public static string ToUssString(ImagePosition imgPosition)
        {
            switch (imgPosition)
            {
            case ImagePosition.ImageAbove: return("image-above");

            case ImagePosition.ImageLeft: return("image-left");

            case ImagePosition.ImageOnly: return("image-only");

            case ImagePosition.TextOnly: return("text-only");
            }
            return("");
        }
Пример #17
0
 private void button_GenClipPos_Click(object sender, EventArgs e)
 {
     try
     {
         HTuple hv_iFlag = null;
         VisionMethon.get_mapping_coords_ext(showRegion, _station.hv_xSnapPosLT, _station.hv_ySnapPosLT, _station.List_UV2XYResult[_station.SelectedIndex], _station.jFDLAFProductRecipe.ScaleFactor,
                                             _station.RowNumber, _station.ColumnNumber * _station.BlockNumber,
                                             out _station.clipMapX, out _station.clipMapY, out _station.clipMapRow, out _station.clipMapCol,
                                             out _station.clipMapU, out _station.clipMapV, out _station.hv_dieWidth, out _station.hv_dieHeight, out hv_iFlag);
         if (hv_iFlag.S != "")
         {
             MessageBox.Show("生成芯片点位失败." + hv_iFlag.S);
             return;
         }
         HOperatorSet.WriteTuple(_station.clipMapX, _station.ProductDir + "\\" + _station.ActivePdt + "\\clipMapX.dat");
         HOperatorSet.WriteTuple(_station.clipMapY, _station.ProductDir + "\\" + _station.ActivePdt + "\\clipMapY.dat");
         HOperatorSet.WriteTuple(_station.clipMapRow, _station.ProductDir + "\\" + _station.ActivePdt + "\\clipMapRow.dat");
         HOperatorSet.WriteTuple(_station.clipMapCol, _station.ProductDir + "\\" + _station.ActivePdt + "\\clipMapCol.dat");
         //_station.scanIniConfig.Writedouble("ScanPoints", "dieWidth", _station.hv_dieWidth.D);
         //_station.scanIniConfig.Writedouble("ScanPoints", "dieHeight", _station.hv_dieHeight.D);
         //清除之前的点位
         if (_station.ClipMapPostions != null)
         {
             _station.ClipMapPostions.Clear();
         }
         else
         {
             _station.ClipMapPostions = new List <ImagePosition>();
         }
         ImagePosition imagePosition = new ImagePosition();
         imagePosition.z     = _station.ZFocus;
         imagePosition.b     = 0;
         _station.clipPosNum = _station.clipMapX.Length;
         for (int i = 0; i < _station.clipPosNum; i++)
         {
             imagePosition.x = _station.clipMapX.TupleSelect(i);
             imagePosition.y = _station.clipMapY.TupleSelect(i);
             imagePosition.r = _station.clipMapRow.TupleSelect(i);
             imagePosition.c = _station.clipMapCol.TupleSelect(i);
             _station.ClipMapPostions.Add(imagePosition);
         }
         MessageBox.Show("生成芯片点位完成.");
     }
     catch (Exception ex)
     {
         MessageBox.Show("保存芯片点位失败。\n" + ex.ToString());
     }
 }
Пример #18
0
            private static void GetImageLocation(ImagePosition Position, out int XOffset, out int YOffset)
            {
                switch (Position)
                {
                case ImagePosition.TopCenter:
                    XOffset = 50;
                    YOffset = 0;
                    break;

                case ImagePosition.TopRight:
                    XOffset = 100;
                    YOffset = 0;
                    break;

                case ImagePosition.CenterLeft:
                    XOffset = 0;
                    YOffset = 50;
                    break;

                case ImagePosition.CenterRight:
                    XOffset = 100;
                    YOffset = 50;
                    break;

                case ImagePosition.AbsoluteMiddle:
                    XOffset = YOffset = 50;
                    break;

                case ImagePosition.BottomLeft:
                    XOffset = 0;
                    YOffset = 100;
                    break;

                case ImagePosition.BottomCenter:
                    XOffset = 50;
                    YOffset = 100;
                    break;

                case ImagePosition.BottomRight:
                    XOffset = 100;
                    YOffset = 100;
                    break;

                default:     // ImagePosition.TopLeft:
                    XOffset = YOffset = 0;
                    break;
                }
            }
Пример #19
0
        void SetImagePosition()
        {
            var position = ImagePosition.ToNS();

            if (string.IsNullOrEmpty(Text) &&
                (
                    position == NSCellImagePosition.ImageAbove ||
                    position == NSCellImagePosition.ImageBelow ||
                    Image != null && Image.Width > MinimumSize.Width
                ))
            {
                position = NSCellImagePosition.ImageOnly;
            }
            Control.ImagePosition = position;
            SetBezel();
        }
Пример #20
0
 protected override void SetImagePosition()
 {
     if (UserPreferredSize.Width == -1)
     {
         var position = ImagePosition.ToNS();
         if (string.IsNullOrEmpty(Text))
         {
             position = NSCellImagePosition.ImageOnly;
         }
         Control.ImagePosition = position;
         InvalidateMeasure();
     }
     else
     {
         base.SetImagePosition();
     }
 }
Пример #21
0
        public string GetImageString(ImagePosition ImagePosition)
        {
            switch (ImagePosition)
            {
            case ImagePosition.Left:
                return("left");

            case ImagePosition.Middle:
                return("mid");

            case ImagePosition.Right:
                return("right");

            default:
                return("left");
            }
        }
Пример #22
0
        static private Bitmap ImageUnExtend(Bitmap Source, int OWidth, int OHeight, ImagePosition IP)
        {
            int        Width = Source.Width, Height = Source.Height;
            Bitmap     Result = new Bitmap(OWidth, OHeight);
            BitmapData SourceData = Source.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            BitmapData ResultData = Result.LockBits(new Rectangle(0, 0, OWidth, OHeight), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            int        X, Y, T;
            byte *     SourcePointer = (byte *)SourceData.Scan0.ToPointer();
            byte *     ResultPointer = (byte *)ResultData.Scan0.ToPointer();
            int        DW            = (Width - OWidth) * 4;
            int        DH            = Width * 4 * (Height - OHeight);

            switch (IP)
            {
            case ImagePosition.LeftTop:
                break;

            case ImagePosition.RightTop:
                SourcePointer += DW;
                break;

            case ImagePosition.RightDown:
                SourcePointer += DH + DW;
                break;

            case ImagePosition.LeftDown:
                SourcePointer += DH;
                break;
            }
            for (Y = 0; Y < OHeight; ++Y)
            {
                for (X = 0; X < OWidth; ++X)
                {
                    for (T = 0; T < 4; ++T)
                    {
                        ResultPointer[0] = SourcePointer[0];
                        ++ResultPointer;
                        ++SourcePointer;
                    }
                }
                SourcePointer += DW;
            }
            Source.UnlockBits(SourceData);
            Result.UnlockBits(ResultData);
            return(Result);
        }
Пример #23
0
    void OnGUI()
    {
        if (AlignEditor.editorPath == null)
        {
            AlignEditor.editorPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this)));
        }

        title = "AllIn v" + AlignEditor.VERSION;
        ImagePosition wasPosition = AlignEditor.ButtonStyle;

        // v2.0 : automatic layout from ratio width/height
        if (this.position.width > this.position.height)
        {
            EditorGUILayout.BeginHorizontal();
            this.minSize = new Vector2(292, 58);
        }
        else
        {
            // Force image above for vertical layout
            if (wasPosition == ImagePosition.ImageLeft)
            {
                AlignEditor.ButtonStyle = ImagePosition.ImageAbove;
            }
            this.minSize = new Vector2(52, 256);
        }
        ClassicWindow.DetectAlignAxis();
        ClassicWindow.AlignButtonGUI(Selection.transforms, true);
        GridWindow.GridButtonGUI(Selection.transforms);
        CameraWindow.CameraButtonGUI(Selection.transforms);

        AlignEditor.SettingsButtonGUI();
        if (this.position.width > this.position.height)
        {
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            AlignEditor.ButtonStyle = wasPosition;
        }
        // Restore the previous state of button style
    }
Пример #24
0
    public static void GridButtonGUI(Transform[] userSelection)
    {
        bool GuiWasEnabled = GUI.enabled;

        GUI.enabled = (userSelection.Length >= 1);
        ImagePosition wasPosition = GUI.skin.button.imagePosition;

        GUI.skin.button.imagePosition = AlignEditor.ButtonStyle;

        GUIContent buttonContent = new GUIContent("Grid", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/gridDistribution.png", typeof(Texture)) as Texture, "Grid distribution");

        if (Selection.transforms.Length > 1)
        {
            buttonContent.tooltip = "Distribute " + userSelection.Length + " objects in a grid";
        }
        else if (Selection.transforms.Length == 1)
        {
            buttonContent.tooltip = "Duplicate " + userSelection[0].name + " in a grid";
        }
        if (GUILayout.Button(buttonContent))
        {
            // Detect the duplicate mode from the selections :
            if (Selection.transforms.Length > 1)
            {
                // Many objects : duplicate object
                // Distribute objects in a grid
                AlignEditor.landmark = AlignManager.Landmark.distributed;
                DistributeInGrid(Selection.activeTransform, userSelection);
            }
            else if (userSelection.Length == 1)
            {
                // One prefab : duplicate prefab
                // Distribute objects in a grid and duplicate objects
                AlignEditor.landmark = AlignManager.Landmark.distributed;
                DuplicateInGrid(userSelection [0].gameObject);
            }
        }
        GUI.skin.button.imagePosition = wasPosition;
        GUI.enabled = GuiWasEnabled;
    }
Пример #25
0
        public void setImageWaterMake()
        {
            Setpath(_source);
            if (CobImgGroup.SelectedItem == null)
            {
                _source.IsImageWater = false;
                return;
            }
            WaterImageManage water = new WaterImageManage();


            image.Source = null;

            Image imageTarget = CobImgGroup.SelectedItem as Image;

            int    imageTargetthree = imageTarget.Source.ToString().IndexOf("///");
            string imageTargetpath  = imageTarget.Source.ToString().Substring(imageTargetthree + 3);

            ImagePosition position = GetImagePosition(CobPoint.SelectionBoxItem.ToString());

            _source.ImagepositionWordImg = position;
            _source.OptintyImg           = (float)SLIop.Value;
            string wordsName = water.DrawImage(fileName, imageTargetpath, (float)SLIop.Value, position, path);

            _source.ImgString      = imageTargetpath;
            toolboxItem.Thumbnails = path + wordsName;
            imagesource            = new BitmapImage(new Uri(path + wordsName, UriKind.RelativeOrAbsolute));



            image.BeginInit();


            image.Source = imagesource;


            image.EndInit();

            _source.IsImageWater = true;
        }
        public void setImageWaterMake()
        {
            Setpath(_source);
            if (txtName.Text.Trim() == "")
            {
                _source.IswordWater = false;
                return;
            }
            WaterImageManage water     = new WaterImageManage();
            object           floatsize = CobFontsize.SelectionBoxItem;

            image.Source = null;

            ImagePosition imageposition = GetImagePosition(poition);

            System.Drawing.FontStyle fontstylevalue = GetFontStyle(fontstyle);


            _source.ImagepositionWord = imageposition;
            _source.fontfailydraw     = fontfamily;
            _source.drawfontSize      = itemFloat;
            _source.Optintyword       = (float)(SLIop.Value);
            _source.WaterContent      = txtName.Text;
            _source.fontstyle         = fontstylevalue;
            string wordsName = water.DrawWords(fileName, txtName.Text, (float)(SLIop.Value), fontfamily, itemFloat, imageposition, path, fontstylevalue);

            toolboxItem.Thumbnails = path + wordsName;

            imagesource = new BitmapImage(new Uri(path + wordsName, UriKind.RelativeOrAbsolute));


            image.BeginInit();


            image.Source = imagesource;

            image.EndInit();
            _source.IswordWater = true;
        }
Пример #27
0
    public static void CameraButtonGUI(Transform[] userSelection)
    {
        ImagePosition wasPosition = GUI.skin.button.imagePosition;

        // We set the image position from the user settings only for this part of the GUI
        GUI.skin.button.imagePosition = AlignEditor.ButtonStyle;

        GUIContent faceCameraGuiContent = new GUIContent("LookAt", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/cameraFacing.png", typeof(Texture)) as Texture, "Make objects face camera");

        if (GUILayout.Button(faceCameraGuiContent))
        {
            OrientToCamera(userSelection);
        }
        GUIContent screenCenterGuiContent = new GUIContent("Center", AssetDatabase.LoadAssetAtPath(AlignEditor.editorPath + "/Icons/" + AlignEditor.Skin + "/screenCenter.png", typeof(Texture)) as Texture, "Center objects in screen");

        if (GUILayout.Button(screenCenterGuiContent))
        {
            ScreenCenter(userSelection);
        }

        GUI.skin.button.imagePosition = wasPosition;
    }
Пример #28
0
        private void ConvertImageToText(Rectangle rectangleCrop)
        {
            _TempPosition.Add(_rectCropArea);
            var imageFileSave = _ImagePath + $"\\{DateTime.Now.Ticks}.jpg";
            var imgCrop       = CropImage(rectangleCrop);

            imgCrop.Save(imageFileSave, ImageFormat.Jpeg);
            var imageFile = File.ReadAllBytes(imageFileSave);
            var text      = ParseText(_TesseractPath, imageFile, "eng");

            //add to grid
            var item = new ImagePosition
            {
                ImageCrop      = imageFileSave,
                ImageContent   = text,
                ImageRectangle = rectangleCrop
            };
            var gridRow = new GridRow {
                RowHeight = 0
            };
            var gridCell1 = new GridCell {
                Value = item.ImageCrop
            };
            var gridCell2 = new GridCell {
                Value = item.ImageContent
            };
            var gridCell3 = new GridCell {
                Value = item.ImagePos
            };
            var gridCell4 = new GridCell {
                Value = "Xóa"
            };

            gridRow.Cells.Add(gridCell1);
            gridRow.Cells.Add(gridCell2);
            gridRow.Cells.Add(gridCell3);
            gridRow.Cells.Add(gridCell4);
            this.superGridControl1.PrimaryGrid.Rows.Add(gridRow);
        }
Пример #29
0
        private ImagePosition GetImagePosition(string position)
        {
            ImagePosition imagePosition = ImagePosition.RigthBottom;

            switch (position)
            {
            case "右上角":
                imagePosition = ImagePosition.RightTop;
                break;

            case "左上角":
                imagePosition = ImagePosition.LeftTop;
                break;

            case "顶端":
                imagePosition = ImagePosition.TopMiddle;

                break;

            case "底端":
                imagePosition = ImagePosition.BottomMiddle;
                break;

            case "居中":
                imagePosition = ImagePosition.Center;
                break;

            case "右下角":
                imagePosition = ImagePosition.RigthBottom;
                break;

            case "左下角":
                imagePosition = ImagePosition.LeftBottom;
                break;
            }

            return(imagePosition);
        }
Пример #30
0
    public static ImagePosition imagePosition__toGUI(ImagePosition fs, string text = "")
    {
        int s = 0;

        switch (fs)
        {
        case ImagePosition.ImageAbove: s = 0;
            break;

        case ImagePosition.ImageLeft: s = 1;
            break;

        case ImagePosition.ImageOnly: s = 2;
            break;

        case ImagePosition.TextOnly: s = 3;
            break;
        }
        string[] str = new string[] { "ImageAbove", "ImageLeft", "ImageOnly", "TextOnly" };
        s = GUILayout.SelectionGrid(s, str, 4);
        ImagePosition ta = ImagePosition.ImageAbove;

        switch (s)
        {
        case 0: ta = ImagePosition.ImageAbove;
            break;

        case 1: ta = ImagePosition.ImageLeft;
            break;

        case 2: ta = ImagePosition.ImageOnly;
            break;

        case 3: ta = ImagePosition.TextOnly;
            break;
        }
        return(ta);
    }
Пример #31
0
        public static GUIStyle ImagePosition(this GUIStyle current, string value, bool asCopy = true)
        {
            value = value.ToLower();
            ImagePosition imagePosition = current.imagePosition;

            if (value.ContainsAny("imageleft", "left"))
            {
                imagePosition = UnityEngine.ImagePosition.ImageLeft;
            }
            if (value.ContainsAny("imageabove", "above"))
            {
                imagePosition = UnityEngine.ImagePosition.ImageAbove;
            }
            if (value.ContainsAny("imageonly"))
            {
                imagePosition = UnityEngine.ImagePosition.ImageOnly;
            }
            if (value.ContainsAny("textOnly"))
            {
                imagePosition = UnityEngine.ImagePosition.TextOnly;
            }
            return(current.ImagePosition(imagePosition, asCopy));
        }
Пример #32
0
        /// <summary>
        /// 在图片上添加水印文字
        /// </summary>
        /// <param name="sourcePicture">源图片文件</param>
        /// <param name="waterWords">需要添加到图片上的文字</param>
        /// <param name="alpha">透明度</param>
        /// <param name="position">位置</param>
        /// <param name="PicturePath">文件路径</param>
        /// <returns></returns>
        public string DrawWords( string sourcePicture,
                                          string waterWords,
                                          float alpha,
                                          ImagePosition position,
                                          string PicturePath )
        {
            //
            // 判断参数是否有效
            //
            if( sourcePicture == string.Empty || waterWords == string.Empty || alpha == 0.0 || PicturePath == string.Empty ) {
                return sourcePicture;
            }

            //
            // 源图片全路径
            //
            string sourcePictureName = PicturePath + sourcePicture;
            string fileExtension = System.IO.Path.GetExtension( sourcePictureName ).ToLower();

            //
            // 判断文件是否存在,以及文件名是否正确
            //
            if( System.IO.File.Exists( sourcePictureName ) == false || (
                fileExtension != ".gif" &&
                fileExtension != ".jpg" &&
                fileExtension != ".png") ) {
                return sourcePicture;
            }

            //
            // 目标图片名称及全路径
            //
            string targetImage = sourcePictureName.Replace( System.IO.Path.GetExtension( sourcePictureName ), "" ) + "_shuiyin.jpg";

            //创建一个图片对象用来装载要被添加水印的图片
            Image imgPhoto = Image.FromFile( sourcePictureName );

            //获取图片的宽和高
            int phWidth = imgPhoto.Width;
            int phHeight = imgPhoto.Height;

            //
            //建立一个bitmap,和我们需要加水印的图片一样大小
            Bitmap bmPhoto = new Bitmap( phWidth, phHeight, PixelFormat.Format24bppRgb );

            //SetResolution:设置此 Bitmap 的分辨率
            //这里直接将我们需要添加水印的图片的分辨率赋给了bitmap
            bmPhoto.SetResolution( imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution );

            //Graphics:封装一个 GDI+ 绘图图面。
            Graphics grPhoto = Graphics.FromImage( bmPhoto );

            //设置图形的品质
            grPhoto.SmoothingMode = SmoothingMode.AntiAlias;

            //将我们要添加水印的图片按照原始大小描绘(复制)到图形中
            grPhoto.DrawImage(
             imgPhoto,                                           //   要添加水印的图片
             new Rectangle( 0, 0, phWidth, phHeight ), //  根据要添加的水印图片的宽和高
             0,                                                     //  X方向从0点开始描绘
             0,                                                     // Y方向
             phWidth,                                            //  X方向描绘长度
             phHeight,                                           //  Y方向描绘长度
             GraphicsUnit.Pixel );                              // 描绘的单位,这里用的是像素

            //根据图片的大小我们来确定添加上去的文字的大小
            //在这里我们定义一个数组来确定
            int[] sizes = new int[] { 22, 20, 18, 16, 14, 13, 12 };

            //字体
            Font crFont = null;
            //矩形的宽度和高度,SizeF有三个属性,分别为Height高,width宽,IsEmpty是否为空
            SizeF crSize = new SizeF();

            //利用一个循环语句来选择我们要添加文字的型号
            //直到它的长度比图片的宽度小
            for( int i = 0; i < 7; i++ ) {
                crFont = new Font( "arial", sizes[i], FontStyle.Bold );

                //测量用指定的 Font 对象绘制并用指定的 StringFormat 对象格式化的指定字符串。
                crSize = grPhoto.MeasureString( waterWords, crFont );

                // ushort 关键字表示一种整数数据类型
                if( (ushort)crSize.Width < (ushort)phWidth )
                    break;
            }

            //截边5%的距离,定义文字显示(由于不同的图片显示的高和宽不同,所以按百分比截取)
            int yPixlesFromBottom = (int)(phHeight * .05);

            //定义在图片上文字的位置
            float wmHeight = crSize.Height;
            float wmWidth = crSize.Width;

            float xPosOfWm;
            float yPosOfWm;

            switch( position ) {
                case ImagePosition.BottomMiddle:
                    xPosOfWm = phWidth / 2;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.Center:
                    xPosOfWm = phWidth / 2;
                    yPosOfWm = phHeight / 2;
                    break;
                case ImagePosition.LeftBottom:
                    xPosOfWm = wmWidth;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.LeftTop:
                    xPosOfWm = wmWidth / 2;
                    yPosOfWm = wmHeight / 2;
                    break;
                case ImagePosition.RightTop:
                    xPosOfWm = phWidth - wmWidth - 10;
                    yPosOfWm = wmHeight;
                    break;
                case ImagePosition.RigthBottom:
                    xPosOfWm = phWidth - wmWidth + 30;
                    yPosOfWm = phHeight - wmHeight;
                    break;
                case ImagePosition.TopMiddle:
                    xPosOfWm = phWidth / 2;
                    yPosOfWm = wmWidth;
                    break;
                default:
                    xPosOfWm = wmWidth;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
            }

            //封装文本布局信息(如对齐、文字方向和 Tab 停靠位),显示操作(如省略号插入和国家标准 (National) 数字替换)和 OpenType 功能。
            StringFormat StrFormat = new StringFormat();

            //定义需要印的文字居中对齐
            StrFormat.Alignment = StringAlignment.Center;

            //SolidBrush:定义单色画笔。画笔用于填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径。
            //这个画笔为描绘阴影的画笔,呈灰色
            int m_alpha = Convert.ToInt32( 256 * alpha );
            SolidBrush semiTransBrush2 = new SolidBrush( Color.FromArgb( m_alpha, 0, 0, 0 ) );

            //描绘文字信息,这个图层向右和向下偏移一个像素,表示阴影效果
            //DrawString 在指定矩形并且用指定的 Brush 和 Font 对象绘制指定的文本字符串。
            grPhoto.DrawString( waterWords,                                    //string of text
                                       crFont,                                         //font
                                       semiTransBrush2,                            //Brush
                                       new PointF( xPosOfWm + 1, yPosOfWm + 1 ),  //Position
                                       StrFormat );

            //从四个 ARGB 分量(alpha、红色、绿色和蓝色)值创建 Color 结构,这里设置透明度为153
            //这个画笔为描绘正式文字的笔刷,呈白色
            SolidBrush semiTransBrush = new SolidBrush( Color.FromArgb( 153, 255, 255, 255 ) );

            //第二次绘制这个图形,建立在第一次描绘的基础上
            grPhoto.DrawString( waterWords,                 //string of text
                                       crFont,                                   //font
                                       semiTransBrush,                           //Brush
                                       new PointF( xPosOfWm, yPosOfWm ),  //Position
                                       StrFormat );

            //imgPhoto是我们建立的用来装载最终图形的Image对象
            //bmPhoto是我们用来制作图形的容器,为Bitmap对象
            imgPhoto = bmPhoto;
            //释放资源,将定义的Graphics实例grPhoto释放,grPhoto功德圆满
            grPhoto.Dispose();

            //将grPhoto保存
            imgPhoto.Save( targetImage, ImageFormat.Jpeg );
            imgPhoto.Dispose();

            return targetImage.Replace( PicturePath, "" );
        }
Пример #33
0
    public static void SetListViewImage(XPListView lst, string ImagePath, ImagePosition Position)
    {
      int x = 0;
      int y = 0;

      GetImageLocation(Position, ref x, ref y);

      try
      {
        LVBKIMAGE apiItem = new LVBKIMAGE();
        apiItem.pszImage = ImagePath + Convert.ToChar(0);
        apiItem.cchImageMax = ImagePath.Length;
        apiItem.ulFlags = LVBKIF_SOURCE_URL | LVBKIF_STYLE_NORMAL;
        apiItem.xOffsetPercent = x;
        apiItem.yOffsetPercent = y;

        // Set the background colour of the ListView to 0XFFFFFFFF (-1) so it will be transparent
        int clear = CLR_NONE;
        SendMessage(lst.Handle, LVM_SETTEXTBKCOLOR, 0, ref clear);

        SendMessage(lst.Handle, LVM_SETBKIMAGE, 0, ref apiItem);
      }
      catch (Exception ex)
      {
        throw new System.Exception("An exception in ListViewAPI.SetListViewImage occured: " + ex.Message);
      }
    }
Пример #34
0
        /// <summary>
        /// アプリ設定から横長タイルに表示する画像の位置情報を取得する
        /// </summary>
        /// <returns></returns>
        private static ImagePosition getSettingWideTilePosition()
        {
            ImagePosition pos = new ImagePosition()
            {
                HorizontalOffset = (int)ApplicationData.Current.RoamingSettings.Values["WideTileHorizontalOffset"],
                VerticalOffset = (int)ApplicationData.Current.RoamingSettings.Values["WideTileVerticalOffset"],
                ZoomFactor = (float)ApplicationData.Current.RoamingSettings.Values["WideTileZoomFactor"],
            };

            return pos;
        }
Пример #35
0
        /// <summary>
        /// 指定したサイズと位置情報に画像ファイルをリサイズする
        /// </summary>
        /// <param name="file"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        private static async Task<StorageFile> resizeBitmap(StorageFile file, int width, int height, ImagePosition pos)
        {
            WriteableBitmap wb;
            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                wb = await BitmapFactory.New(1, 1).FromStream(stream);
            }
            WriteableBitmap resizeWb = wb.Resize((int)(wb.PixelWidth * pos.ZoomFactor), (int)(wb .PixelHeight * pos.ZoomFactor), WriteableBitmapExtensions.Interpolation.Bilinear);
            WriteableBitmap croppedWb = resizeWb.Crop(pos.HorizontalOffset, pos.VerticalOffset, width, height);
            
            //ファイルに保存
            StorageFolder folder = getLocalFolder();
            string fileName = "radame_" + width.ToString() + "x" + height.ToString() + ".png";
            StorageFile saveFile = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
            Debug.WriteLine("resizeBitmap path=" + saveFile.Path);

            await saveToPngFile(croppedWb, saveFile);
            return saveFile;
        }
Пример #36
0
            public TextWatermarkParameters(string sourceImagePath, string watermarkText, float alpha,
                ImagePosition wmPosition, Font wmTextFont, int textShadowWidth = 5)
            {
                this.SourceImageStream = null;
                this._sourceImageFileExtensionName = string.Empty;

                this.SourceImagePath = sourceImagePath;
                this.WatermarkText = watermarkText;
                this.Alpha = alpha;
                this.WmPosition = wmPosition;
                this.WmTextFont = wmTextFont;
                this.TextShadowWidth = textShadowWidth;
            }
Пример #37
0
 private static void GetImageLocation(ImagePosition Position, ref int XOffset, ref int YOffset)
 {
   switch (Position)
   {
     case ImagePosition.TopLeft:
       XOffset = YOffset = 0;
       break;
     case ImagePosition.TopCenter:
       XOffset = 50;
       YOffset = 0;
       break;
     case ImagePosition.TopRight:
       XOffset = 100;
       YOffset = 0;
       break;
     case ImagePosition.CenterLeft:
       XOffset = 0;
       YOffset = 50;
       break;
     case ImagePosition.CenterRight:
       XOffset = 100;
       YOffset = 50;
       break;
     case ImagePosition.AbsoluteMiddle:
       XOffset = YOffset = 50;
       break;
     case ImagePosition.BottomLeft:
       XOffset = 0;
       YOffset = 100;
       break;
     case ImagePosition.BottomCenter:
       XOffset = 50;
       YOffset = 100;
       break;
     case ImagePosition.BottomRight:
       XOffset = 100;
       YOffset = 100;
       break;
   }
 }
Пример #38
0
        /// <summary>   
        /// 在图片上添加水印文字   
        /// </summary>   
        /// <param name="sourcePicture">源图片文件</param>   
        /// <param name="waterWords">需要添加到图片上的文字</param>   
        /// <param name="alpha">透明度</param>   
        /// <param name="position">位置</param>   
        /// <param name="PicturePath">文件路径</param>   
        /// <returns></returns>   
        public bool DrawWords(Stream sourcePicture,  
            string waterWords,
            float alpha,
            Font crFont,
            Color forColor,
            ImagePosition position,
            string PicturePath)
        {
            bool IsSuccess = true;
            try
            {

            //创建一个图片对象用来装载要被添加水印的图片
            Image imgPhoto = Image.FromStream(sourcePicture);

            //获取图片的宽和高
            int phWidth = imgPhoto.Width;
            int phHeight = imgPhoto.Height;

            //
            //建立一个bitmap,和我们需要加水印的图片一样大小
            Bitmap bmPhoto = new Bitmap(sourcePicture);
            bmPhoto.MakeTransparent();
            //SetResolution:设置此 Bitmap 的分辨率
            //这里直接将我们需要添加水印的图片的分辨率赋给了bitmap
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            //Graphics:封装一个 GDI+ 绘图图面。
            Graphics grPhoto = Graphics.FromImage(bmPhoto);

            //设置图形的品质
            grPhoto.SmoothingMode = SmoothingMode.AntiAlias;

            //将我们要添加水印的图片按照原始大小描绘(复制)到图形中
            grPhoto.DrawImage(
             imgPhoto,                                           //   要添加水印的图片
             new Rectangle(0, 0, phWidth, phHeight), //  根据要添加的水印图片的宽和高
             0,                                                     //  X方向从0点开始描绘
             0,                                                     // Y方向
             phWidth,                                            //  X方向描绘长度
             phHeight,                                           //  Y方向描绘长度
             GraphicsUnit.Pixel);                              // 描绘的单位,这里用的是像素

            //矩形的宽度和高度,SizeF有三个属性,分别为Height高,width宽,IsEmpty是否为空
            SizeF crSize = new SizeF();

            //测量用指定的 Font 对象绘制并用指定的 StringFormat 对象格式化的指定字符串。
            crSize = grPhoto.MeasureString(waterWords, crFont);

            //截边5%的距离,定义文字显示(由于不同的图片显示的高和宽不同,所以按百分比截取)
            int yPixlesFromBottom = (int)(phHeight * .05);

            //定义在图片上文字的位置
            float wmHeight = crSize.Height;
            float wmWidth = crSize.Width;

            float xPosOfWm;
            float yPosOfWm;

            switch (position)
            {
                case ImagePosition.BottomMiddle:
                    xPosOfWm = phWidth/ 2;
                    yPosOfWm = phHeight - wmHeight;
                    break;
                case ImagePosition.Center:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = (phHeight - wmHeight) / 2;
                    break;
                case ImagePosition.LeftBottom:
                    xPosOfWm = wmWidth/2;
                    yPosOfWm = phHeight - wmHeight;
                    break;
                case ImagePosition.LeftTop:
                    xPosOfWm = wmWidth / 2;
                    yPosOfWm = 0;
                    break;
                case ImagePosition.RightTop:
                    xPosOfWm = phWidth - wmWidth/2;
                    yPosOfWm =0;
                    break;
                case ImagePosition.RigthBottom:
                    xPosOfWm = phWidth - wmWidth/2;
                    yPosOfWm = phHeight - wmHeight;
                    break;
                case ImagePosition.TopMiddle:
                    xPosOfWm = phWidth / 2;
                    yPosOfWm = 0;
                    break;
                default:
                    xPosOfWm = wmWidth;
                    yPosOfWm = phHeight - wmHeight - 2;
                    break;
            }

            //封装文本布局信息(如对齐、文字方向和 Tab 停靠位),显示操作(如省略号插入和国家标准 (National) 数字替换)和 OpenType 功能。
            StringFormat StrFormat = new StringFormat();

            //定义需要印的文字居中对齐
            StrFormat.Alignment = StringAlignment.Center;

            //SolidBrush:定义单色画笔。画笔用于填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径。
            //这个画笔为描绘阴影的画笔,呈灰色
            int m_alpha = Convert.ToInt32(255 * alpha);
            SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(m_alpha, forColor.R, forColor.G, forColor.B));
            //SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(m_alpha,0, 0, 0));
            //描绘文字信息,这个图层向右和向下偏移一个像素,表示阴影效果
            //DrawString 在指定矩形并且用指定的 Brush 和 Font 对象绘制指定的文本字符串。
            grPhoto.DrawString(waterWords,                                    //string of text
                                       crFont,                                         //font
                                       semiTransBrush2,                            //Brush
                                       new PointF(xPosOfWm, yPosOfWm),  //Position
                                       StrFormat);

            //从四个 ARGB 分量(alpha、红色、绿色和蓝色)值创建 Color 结构,这里设置透明度为153
            //这个画笔为描绘正式文字的笔刷,呈白色
            //SolidBrush semiTransBrush = new SolidBrush(forColor);

            //SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, forColor.R, forColor.G, forColor.B));
            ////第二次绘制这个图形,建立在第一次描绘的基础上

            ////update by wp
            //grPhoto.DrawString(waterWords,                 //string of text
            //                           crFont,                                   //font
            //                           semiTransBrush,                           //Brush
            //                           new PointF(xPosOfWm, yPosOfWm),  //Position
            //                           StrFormat);

            //imgPhoto是我们建立的用来装载最终图形的Image对象
            //bmPhoto是我们用来制作图形的容器,为Bitmap对象
            imgPhoto = bmPhoto;
            //释放资源,将定义的Graphics实例grPhoto释放,grPhoto功德圆满
            grPhoto.Dispose();
            ImageFormat imgFormat = null;
            string extension = Path.GetExtension(PicturePath).ToLower();
            if (extension.Equals(".jpg"))
            {
                imgFormat = ImageFormat.Jpeg;
            }
            else if (extension.Equals(".gif"))
            {
                imgFormat = ImageFormat.Gif;
            }
            else if (extension.Equals(".png"))
            {
                imgFormat = ImageFormat.Png;
            }

            //将grPhoto保存
            imgPhoto.Save(PicturePath, imgFormat);
            imgPhoto.Dispose();
            }
            catch (Exception ex)
            {
            IsSuccess = false;
            }
            return IsSuccess;
        }
Пример #39
0
            /// <summary>
            /// 生成缩略图
            /// </summary>
            /// <param name="originalImagePath">源图路径(物理路径)</param>
            /// <param name="thumbnailPath">缩略图路径(物理路径)</param>
            /// <param name="width">缩略图宽度</param>
            /// <param name="height">缩略图高度</param>
            /// <param name="mode">生成缩略图的方式</param>	
            /// <param name="isaddwatermark">是否添加水印</param>	
            /// <param name="quality">图片品质</param>	
            /// <param name="imagePosition">水印位置</param>	
            /// <param name="waterImage">水印图片名称</param>	
            public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode, bool isaddwatermark, ImagePosition imagePosition, string waterImage = null, int quality = 75)
            {
                Image originalImage = Image.FromFile(originalImagePath);

                int towidth = width;
                int toheight = height;

                int x = 0;
                int y = 0;
                int ow = originalImage.Width;
                int oh = originalImage.Height;

                switch (mode)
                {
                    case "HW"://指定高宽缩放(可能变形)
                        break;
                    case "W"://指定宽,高按比例
                        toheight = originalImage.Height * width / originalImage.Width;
                        break;
                    case "H"://指定高,宽按比例
                        towidth = originalImage.Width * height / originalImage.Height;
                        break;
                    case "Cut"://指定高宽裁减(不变形)
                        if (originalImage.Width >= towidth && originalImage.Height >= toheight)
                        {
                            if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                            {
                                oh = originalImage.Height;
                                ow = originalImage.Height * towidth / toheight;
                                y = 0;
                                x = (originalImage.Width - ow) / 2;
                            }
                            else
                            {
                                ow = originalImage.Width;
                                oh = originalImage.Width * height / towidth;
                                x = 0;
                                y = (originalImage.Height - oh) / 2;
                            }
                        }
                        else
                        {
                            x = (originalImage.Width - towidth) / 2;
                            y = (originalImage.Height - toheight) / 2;
                            ow = towidth;
                            oh = toheight;
                        }
                        break;
                    case "Fit"://不超出尺寸,比它小就不截了,不留白,大就缩小到最佳尺寸,主要为手机用
                        if (originalImage.Width > towidth && originalImage.Height > toheight)
                        {
                            if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                                toheight = originalImage.Height * width / originalImage.Width;
                            else
                                towidth = originalImage.Width * height / originalImage.Height;
                        }
                        else if (originalImage.Width > towidth)
                        {
                            toheight = originalImage.Height * width / originalImage.Width;
                        }
                        else if (originalImage.Height > toheight)
                        {
                            towidth = originalImage.Width * height / originalImage.Height;
                        }
                        else
                        {
                            towidth = originalImage.Width;
                            toheight = originalImage.Height;
                            ow = towidth;
                            oh = toheight;
                        }
                        break;
                    default:
                        break;
                }

                //新建一个bmp图片
                Image bitmap = new System.Drawing.Bitmap(towidth, toheight);

                //新建一个画板
                Graphics g = System.Drawing.Graphics.FromImage(bitmap);

                //设置高质量插值法
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

                //设置高质量,低速度呈现平滑程度
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                //清空画布并以透明背景色填充
                g.Clear(Color.White);

                //在指定位置并且按指定大小绘制原图片的指定部分
                g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),
                    new Rectangle(x, y, ow, oh),
                    GraphicsUnit.Pixel);

                //加图片水印
                if (isaddwatermark)
                {
                    if (string.IsNullOrEmpty(waterImage))
                        waterImage = "watermarker.png";
                    Image copyImage = System.Drawing.Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, waterImage));
                    //g.DrawImage(copyImage, new Rectangle(bitmap.Width-copyImage.Width, bitmap.Height-copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
                    int xPosOfWm;
                    int yPosOfWm;
                    int wmHeight = copyImage.Height;
                    int wmWidth = copyImage.Width;
                    int phHeight = toheight;
                    int phWidth = towidth;
                    switch (imagePosition)
                    {
                        case ImagePosition.LeftBottom:
                            xPosOfWm = 70;
                            yPosOfWm = phHeight - wmHeight - 70;
                            break;
                        case ImagePosition.LeftTop:
                            xPosOfWm = 70;
                            yPosOfWm = 0 - 70;
                            break;
                        case ImagePosition.RightTop:
                            xPosOfWm = phWidth - wmWidth - 70;
                            yPosOfWm = 0 - 70;
                            break;
                        case ImagePosition.RigthBottom:
                            xPosOfWm = phWidth - wmWidth - 70;
                            yPosOfWm = phHeight - wmHeight - 70;
                            break;
                        default:
                            xPosOfWm = 10;
                            yPosOfWm = 0;
                            break;
                    }
                    g.DrawImage(copyImage, new Rectangle(xPosOfWm, yPosOfWm, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
                }

                // 以下代码为保存图片时,设置压缩质量
                EncoderParameters encoderParams = new EncoderParameters();
                long[] qualityArray = new long[1];
                qualityArray[0] = quality;
                EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityArray);
                encoderParams.Param[0] = encoderParam;
                //获得包含有关内置图像编码解码器的信息的ImageCodecInfo 对象.
                ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo jpegICI = null;
                for (int i = 0; i < arrayICI.Length; i++)
                {
                    if (arrayICI[i].FormatDescription.Equals("JPEG"))
                    {
                        jpegICI = arrayICI[i];
                        //设置JPEG编码
                        break;
                    }
                }

                try
                {
                    if (jpegICI != null)
                    {
                        bitmap.Save(thumbnailPath, jpegICI, encoderParams);
                    }
                    else
                    {
                        //以jpg格式保存缩略图
                        bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    originalImage.Dispose();
                    bitmap.Dispose();
                    g.Dispose();
                }
            }
Пример #40
0
        public override void validateBuffer()
        {
            if (texture != null){
                texture.Dispose();
                texture = null;
            }

            if (vertexBuffer != null){
                vertexBuffer.Dispose();
                vertexBuffer = null;
            }

            if (textfield.text == null || textfield.text.Length == 0){
                dirtyBuffer = false;
                return;
            }

            updateSize();

            float[] verts = new float[8];
            float[] uvs = new float[8];

            int maxWidth = (int) textWidth;
            if (textfield.defaultTextFormat.align == "right"){
                maxWidth = textfield.width;
            }

            verts[0] = (float) OFFSET_X;
            verts[1] = (float) OFFSET_Y;

            verts[2] = (float) OFFSET_X;
            verts[3] = (float) OFFSET_Y + textHeight;

            verts[6] = (float) OFFSET_X + maxWidth;
            verts[7] = (float) OFFSET_Y;

            verts[4] = (float) OFFSET_X + maxWidth;
            verts[5] = (float) OFFSET_Y + textHeight;

            uvs[0] = 0;
            uvs[1] = 0;

            uvs[2] = 0;
            uvs[3] = 1;

            uvs[6] = 1;
            uvs[7] = 0;

            uvs[4] = 1;
            uvs[5] = 1;

            vertexBuffer = new VertexBuffer(4, VertexFormat.Float2, VertexFormat.Float2);
            vertexBuffer.SetVertices(0, verts);
            vertexBuffer.SetVertices(1, uvs);

            int argb = textfield.defaultTextFormat.color;

            var image = new Image(	ImageMode.Rgba,
                                    new ImageSize((int)maxWidth, (int)textHeight),
                                    new ImageColor(0, 0, 0, 0));

            ImagePosition pos = new ImagePosition(0, 0);
            for (int i = 0; i < textLines.Length; i++){
                pos.X = 0;
                pos.Y = i * font.Metrics.Height;

                if (textfield.defaultTextFormat.align == "right"){
                    pos.X = (int) maxWidth - font.GetTextWidth(textLines[i]);
                }

                image.DrawText(
                    textLines[i],
                    new ImageColor((int)((argb >> 16) & 0xff),
                    (int)((argb >> 8) & 0xff),
                    (int)((argb >> 0) & 0xff),
                    255),
                    font,
                    pos
                );
            }

            texture = new Texture2D((int)maxWidth, (int)textHeight, false, PixelFormat.Rgba);
            texture.SetPixels(0, image.ToBuffer());
            texture.SetFilter(TextureFilterMode.Disabled);
            texture.SetWrap(TextureWrapMode.ClampToEdge);
            texture.SetMaxAnisotropy(0);
            image.Dispose();

            dirtyBuffer = false;

            //Console.WriteLine("buffer validated: " + renderable.commands.length);
        }
Пример #41
0
        /// <summary>
        /// 添加图片水印
        /// </summary>
        /// <param name="sourcePicture">源图片文件名</param>
        /// <param name="waterImage">水印图片全路径</param>
        /// <param name="alpha">透明度(0.1-1.0数值越小透明度越高)</param>
        /// <param name="position">位置</param>
        /// <param name="PicturePath" >图片的路径</param>
        /// <returns>返回生成于指定文件夹下的水印文件名</returns>
        public string DrawImage(string sourcePicture,
                                          string waterImage,
                                          float alpha,
                                          ImagePosition position,
                                          string PicturePath)
        {
            //
            // 判断参数是否有效
            //
            if (sourcePicture == string.Empty || waterImage == string.Empty || alpha == 0.0 || PicturePath == string.Empty)
            {
                return sourcePicture;
            }

            //
            // 源图片,水印图片全路径
            //
            string sourcePictureName = PicturePath + sourcePicture;
            string waterPictureName = waterImage;
            string fileSourceExtension = System.IO.Path.GetExtension(sourcePictureName).ToLower();
            string fileWaterExtension = System.IO.Path.GetExtension(waterPictureName).ToLower();
            //
            // 判断文件是否存在,以及类型是否正确
            //
            if (System.IO.File.Exists(sourcePictureName) == false ||
                System.IO.File.Exists(waterPictureName) == false || (
                fileSourceExtension != ".gif" &&
                fileSourceExtension != ".jpg" &&
                fileSourceExtension != ".png") || (
                fileWaterExtension != ".gif" &&
                fileWaterExtension != ".jpg" &&
                fileWaterExtension != ".png")
                )
            {
                return sourcePicture;
            }

            //
            // 目标图片名称及全路径
            //
            string targetImage = sourcePictureName.Replace(System.IO.Path.GetExtension(sourcePictureName), "") + "_water.jpg";

            //
            // 将需要加上水印的图片装载到Image对象中
            //
            Image imgPhoto = Image.FromFile(sourcePictureName);
            //
            // 确定其长宽
            //
            int phWidth = imgPhoto.Width;
            int phHeight = imgPhoto.Height;

            //
            // 封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。
            //
            Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);

            //
            // 设定分辨率
            //
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            //
            // 定义一个绘图画面用来装载位图
            //
            Graphics grPhoto = Graphics.FromImage(bmPhoto);

            //
            //同样,由于水印是图片,我们也需要定义一个Image来装载它
            //
            Image imgWatermark = new Bitmap(waterPictureName);

            //
            // 获取水印图片的高度和宽度
            //
            int wmWidth = imgWatermark.Width;
            int wmHeight = imgWatermark.Height;

            //SmoothingMode:指定是否将平滑处理(消除锯齿)应用于直线、曲线和已填充区域的边缘。
            // 成员名称   说明
            // AntiAlias      指定消除锯齿的呈现。
            // Default        指定不消除锯齿。
            // HighQuality  指定高质量、低速度呈现。
            // HighSpeed   指定高速度、低质量呈现。
            // Invalid        指定一个无效模式。
            // None          指定不消除锯齿。
            grPhoto.SmoothingMode = SmoothingMode.AntiAlias;

            //
            // 第一次描绘,将我们的底图描绘在绘图画面上
            //
            grPhoto.DrawImage(imgPhoto,
                                        new Rectangle(0, 0, phWidth, phHeight),
                                        0,
                                        0,
                                        phWidth,
                                        phHeight,
                                        GraphicsUnit.Pixel);

            //
            // 与底图一样,我们需要一个位图来装载水印图片。并设定其分辨率
            //
            Bitmap bmWatermark = new Bitmap(bmPhoto);
            bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            //
            // 继续,将水印图片装载到一个绘图画面grWatermark
            //
            Graphics grWatermark = Graphics.FromImage(bmWatermark);

            //
            //ImageAttributes 对象包含有关在呈现时如何操作位图和图元文件颜色的信息。
            //
            ImageAttributes imageAttributes = new ImageAttributes();

            //
            //Colormap: 定义转换颜色的映射
            //
            ColorMap colorMap = new ColorMap();

            //
            //我的水印图被定义成拥有绿色背景色的图片被替换成透明
            //
            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);

            ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            float[][] colorMatrixElements = {
               new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f}, // red红色
               new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f}, //green绿色
               new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f}, //blue蓝色
               new float[] {0.0f,  0.0f,  0.0f,  alpha, 0.0f}, //透明度
               new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}};//

            //  ColorMatrix:定义包含 RGBA 空间坐标的 5 x 5 矩阵。
            //  ImageAttributes 类的若干方法通过使用颜色矩阵调整图像颜色。
            ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
             ColorAdjustType.Bitmap);

            //
            //上面设置完颜色,下面开始设置位置
            //
            int xPosOfWm;
            int yPosOfWm;

            switch (position)
            {
                case ImagePosition.BottomMiddle:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.Center:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = (phHeight - wmHeight) / 2;
                    break;
                case ImagePosition.LeftBottom:
                    xPosOfWm = 10;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.LeftTop:
                    xPosOfWm = 10;
                    yPosOfWm = 10;
                    break;
                case ImagePosition.RightTop:
                    xPosOfWm = phWidth - wmWidth - 10;
                    yPosOfWm = 10;
                    break;
                case ImagePosition.RigthBottom:
                    xPosOfWm = phWidth - wmWidth - 10;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.TopMiddle:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = 10;
                    break;
                default:
                    xPosOfWm = 10;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
            }

            //
            // 第二次绘图,把水印印上去
            //
            grWatermark.DrawImage(imgWatermark,
             new Rectangle(xPosOfWm,
                                 yPosOfWm,
                                 wmWidth,
                                 wmHeight),
                                 0,
                                 0,
                                 wmWidth,
                                 wmHeight,
                                 GraphicsUnit.Pixel,
                                 imageAttributes);

            imgPhoto = bmWatermark;
            grPhoto.Dispose();
            grWatermark.Dispose();

            //
            // 保存文件到服务器的文件夹里面
            //
            imgPhoto.Save(targetImage, ImageFormat.Jpeg);
            imgPhoto.Dispose();
            imgWatermark.Dispose();
            return targetImage.Replace(PicturePath, "");
        }
Пример #42
0
			public ButtonContentLayout(ImagePosition position, double spacing)
			{
				Position = position;
				Spacing = spacing;
			}
Пример #43
0
            public ImageWatermarkParameters(string sourceImagePath, string watermarkImagePath, float alpha, ImagePosition wmPosition)
            {
                this.SourceImageStream = null;
                this.WatermarkImageStream = null;
                this._sourceImageFileExtensionName = string.Empty;

                this.SourceImagePath = sourceImagePath;
                this.WatermarkImagePath = watermarkImagePath;
                this.Alpha = alpha;
                this.WmPosition = wmPosition;
            }
Пример #44
0
        public static Texture CreateTexture(string textureName, string displayName, Vector2 position, ImagePosition orientation, bool addToActiveList = true)
        {
            Texture active = textures.Where(a => a.Name == textureName).FirstOrDefault();

            if(active == null)
                active = textures.Where(a => a.Name == "Dummy").FirstOrDefault();
            
            Texture instance = new Texture(active.Name, displayName, active.Sprite, active.Image, position, orientation);

            if(addToActiveList)
                activeTextures.Add(instance);

            return instance;
        }
Пример #45
0
        /// <summary>   
        /// 添加图片水印   
        /// </summary>   
        /// <param name="sourcePicture">源图片文件名</param>   
        /// <param name="waterImage">水印图片文件名</param>   
        /// <param name="alpha">透明度(0.1-1.0数值越小透明度越高)</param>   
        /// <param name="position">位置</param>   
        /// <param name="PicturePath" >生产水印图片的路径</param>   
        /// <returns>返回生成于指定文件夹下的水印文件名</returns>   
        public bool DrawImage(Stream sourcePicture,
            string waterImage,
            float alpha,
            float waterImageSize,
            ImagePosition position,
            string PicturePath)
        {
            bool IsSuccess = true;
            try
            {

            // 将需要加上水印的图片装载到Image对象中
            //
            Image imgPhoto = Image.FromStream(sourcePicture);
            //
            // 确定其长宽
            //
            int phWidth = imgPhoto.Width;
            int phHeight = imgPhoto.Height;

            //
            // 封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。
            //
            Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
            bmPhoto.MakeTransparent();
            //
            // 设定分辨率
            //
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            //
            // 定义一个绘图画面用来装载位图
            //
            Graphics grPhoto = Graphics.FromImage(bmPhoto);

            //
            //同样,由于水印是图片,我们也需要定义一个Image来装载它
            //
            Image imgWatermark = new Bitmap(waterImage);

            //
            // 获取水印图片的高度和宽度
            //
            int wmWidth = (int)(imgWatermark.Width * waterImageSize);
            int wmHeight = (int)(imgWatermark.Height * waterImageSize);

            //SmoothingMode:指定是否将平滑处理(消除锯齿)应用于直线、曲线和已填充区域的边缘。
            // 成员名称   说明
            // AntiAlias      指定消除锯齿的呈现。
            // Default        指定不消除锯齿。
            // HighQuality  指定高质量、低速度呈现。
            // HighSpeed   指定高速度、低质量呈现。
            // Invalid        指定一个无效模式。
            // None          指定不消除锯齿。
            grPhoto.SmoothingMode = SmoothingMode.AntiAlias;

            //
            // 第一次描绘,将我们的底图描绘在绘图画面上
            //
            grPhoto.DrawImage(imgPhoto,
                                        new Rectangle(0, 0, phWidth, phHeight),
                                        0,
                                        0,
                                        phWidth,
                                        phHeight,
                                        GraphicsUnit.Pixel);

            //
            // 与底图一样,我们需要一个位图来装载水印图片。并设定其分辨率
            //
            Bitmap bmWatermark = new Bitmap(bmPhoto);
            bmWatermark.MakeTransparent();
            bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            //
            // 继续,将水印图片装载到一个绘图画面grWatermark
            //
            Graphics grWatermark = Graphics.FromImage(bmWatermark);

            //
            //ImageAttributes 对象包含有关在呈现时如何操作位图和图元文件颜色的信息。
            //
            ImageAttributes imageAttributes = new ImageAttributes();

            //
            //Colormap: 定义转换颜色的映射
            //
            ColorMap colorMap = new ColorMap();

            //
            //我的水印图被定义成拥有绿色背景色的图片被替换成透明
            //
            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);

            ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            float[][] colorMatrixElements = {
               new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f}, // red红色
               new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f}, //green绿色
               new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f}, //blue蓝色
               new float[] {0.0f,  0.0f,  0.0f,  alpha, 0.0f}, //透明度
               new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}};//

            //  ColorMatrix:定义包含 RGBA 空间坐标的 5 x 5 矩阵。
            //  ImageAttributes 类的若干方法通过使用颜色矩阵调整图像颜色。
            ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
             ColorAdjustType.Bitmap);

            //
            //上面设置完颜色,下面开始设置位置
            //
            int xPosOfWm;
            int yPosOfWm;

            switch (position)
            {
                case ImagePosition.BottomMiddle:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    //yPosOfWm = phHeight - wmHeight - 10;
                    yPosOfWm = phHeight - wmHeight-2;
                    break;
                case ImagePosition.Center:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = (phHeight - wmHeight) / 2;
                    break;
                case ImagePosition.LeftBottom:
                    xPosOfWm = 2;
                    //yPosOfWm = phHeight - wmHeight - 10;
                    yPosOfWm = phHeight - wmHeight-2;
                    break;
                case ImagePosition.LeftTop:
                    xPosOfWm = 2;
                    yPosOfWm = 2;
                    break;
                case ImagePosition.RightTop:
                    //xPosOfWm = phWidth - wmWidth - 10;
                    xPosOfWm = phWidth - wmWidth-2;
                    yPosOfWm = 2;
                    break;
                case ImagePosition.RigthBottom:
                    //xPosOfWm = phWidth - wmWidth - 10;
                    //yPosOfWm = phHeight - wmHeight - 10;
                    xPosOfWm = phWidth - wmWidth-2;
                    yPosOfWm = phHeight - wmHeight-2;
                    break;
                case ImagePosition.TopMiddle:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = 2;
                    break;
                default:
                    xPosOfWm = 2;
                    //yPosOfWm = phHeight - wmHeight - 10;
                    yPosOfWm = phHeight - wmHeight-2;
                    break;
            }

            //
            // 第二次绘图,把水印印上去
            //
            grWatermark.DrawImage(imgWatermark,
             new Rectangle(xPosOfWm,
                                 yPosOfWm,
                                 wmWidth,
                                 wmHeight),
                                 0,
                                 0,
                                 wmWidth,
                                 wmHeight,
                                 GraphicsUnit.Pixel,
                                 imageAttributes);

            imgPhoto = bmWatermark;
            grPhoto.Dispose();
            grWatermark.Dispose();

            //
            // 保存文件到服务器的文件夹里面
            //
            ImageFormat imgFormat = null;
            string extension = Path.GetExtension(PicturePath).ToLower();
            if (extension.Equals(".jpg"))
            {
                imgFormat = ImageFormat.Jpeg;
            }
            else if (extension.Equals(".gif"))
            {
                imgFormat = ImageFormat.Gif;
            }
            else if (extension.Equals(".png"))
            {
                imgFormat = ImageFormat.Png;
            }
            imgPhoto.Save(PicturePath, imgFormat);
            imgPhoto.Dispose();
            imgWatermark.Dispose();

            }
            catch(Exception ex)
            {
            IsSuccess = false;
            }
            return IsSuccess;
        }
Пример #46
0
 public void SetBackgroundImage(string ImagePath, ImagePosition Position)
 {
   ListViewAPI.SetListViewImage(this, ImagePath, Position);
 }
Пример #47
0
 /// <summary>
 /// Calculate the watermark image position.
 /// </summary>
 /// <param name="position">position</param>
 /// <param name="srcWidth">source image width</param>
 /// <param name="srcHeight">source image height</param>
 /// <param name="wmWidth">watermark image width</param>
 /// <param name="wmHeight">watermark image height</param>
 /// <param name="xPosOfWm">final x position</param>
 /// <param name="yPosOfWm">final y position</param>
 private static void GetWatermarkTextPosition(ImagePosition position, int srcWidth, int srcHeight, float wmWidth, float wmHeight, out float xPosOfWm, out float yPosOfWm)
 {
     switch (position)
     {
         case ImagePosition.BottomMiddle:
             xPosOfWm = srcWidth / 2;
             yPosOfWm = srcHeight - wmHeight - 10;
             break;
         case ImagePosition.Center:
             xPosOfWm = srcWidth / 2;
             yPosOfWm = srcHeight / 2;
             break;
         case ImagePosition.LeftBottom:
             xPosOfWm = wmWidth;
             yPosOfWm = srcHeight - wmHeight - 10;
             break;
         case ImagePosition.LeftTop:
             xPosOfWm = wmWidth / 2;
             yPosOfWm = wmHeight / 2;
             break;
         case ImagePosition.RightTop:
             xPosOfWm = srcWidth - wmWidth - 10;
             yPosOfWm = wmHeight;
             break;
         case ImagePosition.RigthBottom:
             xPosOfWm = srcWidth - wmWidth - 10;
             yPosOfWm = srcHeight - wmHeight - 10;
             break;
         case ImagePosition.TopMiddle:
             xPosOfWm = srcWidth / 2;
             yPosOfWm = wmWidth;
             break;
         default:
             xPosOfWm = wmWidth;
             yPosOfWm = srcHeight - wmHeight - 10;
             break;
     }
 }
Пример #48
0
        /// <summary>   
        /// 在图片上添加水印文字   
        /// </summary>   
        /// <param name="sourcePicture">源图片文件</param>   
        /// <param name="waterWords">需要添加到图片上的文字</param>   
        /// <param name="alpha">透明度</param>   
        /// <param name="position">位置</param>   
        /// <param name="picturePath">文件路径</param>   
        /// <returns></returns>   
        public static string DrawWords(string sourcePicture, string waterWords, double alpha, ImagePosition position, string picturePath)
        {
            // 判断参数是否有效   
            if (sourcePicture == string.Empty || waterWords == string.Empty || Math.Abs(alpha * 10) - 1 < 0 || picturePath == string.Empty)
            {
                return sourcePicture;
            }
            //创建一个图片对象用来装载要被添加水印的图片   
            Image imgPhoto = Image.FromFile(sourcePicture);

            //获取图片的宽和高   
            int phWidth = imgPhoto.Width;
            int phHeight = imgPhoto.Height;

            //   
            //建立一个bitmap,和我们需要加水印的图片一样大小   
            var bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);

            //SetResolution:设置此 Bitmap 的分辨率   
            //这里直接将我们需要添加水印的图片的分辨率赋给了bitmap   
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            //Graphics:封装一个 GDI+ 绘图图面。   
            Graphics grPhoto = Graphics.FromImage(bmPhoto);

            //设置图形的品质   
            grPhoto.SmoothingMode = SmoothingMode.AntiAlias;

            //将我们要添加水印的图片按照原始大小描绘(复制)到图形中   
            grPhoto.DrawImage(
             imgPhoto,                                           //   要添加水印的图片   
             new Rectangle(0, 0, phWidth, phHeight), //  根据要添加的水印图片的宽和高   
             0,                                                     //  X方向从0点开始描绘   
             0,                                                     // Y方向    
             phWidth,                                            //  X方向描绘长度   
             phHeight,                                           //  Y方向描绘长度   
             GraphicsUnit.Pixel);                              // 描绘的单位,这里用的是像素   

            //根据图片的大小我们来确定添加上去的文字的大小   
            //在这里我们定义一个数组来确定   
            var sizes = new[] { 16, 14, 12, 10, 8, 6, 4 };

            //字体   
            Font crFont = null;
            //矩形的宽度和高度,SizeF有三个属性,分别为Height高,width宽,IsEmpty是否为空   
            var crSize = new SizeF();

            //利用一个循环语句来选择我们要添加文字的型号   
            //直到它的长度比图片的宽度小   
            for (int i = 0; i < 7; i++)
            {
                crFont = new Font("arial", sizes[i], FontStyle.Bold);

                //测量用指定的 Font 对象绘制并用指定的 StringFormat 对象格式化的指定字符串。   
                crSize = grPhoto.MeasureString(waterWords, crFont);

                // ushort 关键字表示一种整数数据类型   
                if ((ushort)crSize.Width < (ushort)phWidth)
                    break;
            }

            //截边5%的距离,定义文字显示(由于不同的图片显示的高和宽不同,所以按百分比截取)   

            //定义在图片上文字的位置   
            float wmHeight = crSize.Height;
            float wmWidth = crSize.Width;

            float xPosOfWm;
            float yPosOfWm;

            switch (position)
            {
                case ImagePosition.BottomMiddle:
                    xPosOfWm = phWidth / 2;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.Center:
                    xPosOfWm = phWidth / 2;
                    yPosOfWm = phHeight / 2;
                    break;
                case ImagePosition.LeftBottom:
                    xPosOfWm = wmWidth;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.LeftTop:
                    xPosOfWm = wmWidth / 2;
                    yPosOfWm = wmHeight / 2;
                    break;
                case ImagePosition.RightTop:
                    xPosOfWm = phWidth - wmWidth - 10;
                    yPosOfWm = wmHeight;
                    break;
                case ImagePosition.RigthBottom:
                    xPosOfWm = phWidth - wmWidth - 10;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.TopMiddle:
                    xPosOfWm = phWidth / 2;
                    yPosOfWm = wmWidth;
                    break;
                default:
                    xPosOfWm = wmWidth;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
            }

            //封装文本布局信息(如对齐、文字方向和 Tab 停靠位),显示操作(如省略号插入和国家标准 (National) 数字替换)和 OpenType 功能。   
            var strFormat = new StringFormat {Alignment = StringAlignment.Center};

            //定义需要印的文字居中对齐   

            //SolidBrush:定义单色画笔。画笔用于填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径。   
            //这个画笔为描绘阴影的画笔,呈灰色   
            var mAlpha = Convert.ToInt32(256 * alpha);
            var semiTransBrush2 = new SolidBrush(Color.FromArgb(mAlpha, 0, 0, 0));

            //描绘文字信息,这个图层向右和向下偏移一个像素,表示阴影效果   
            //DrawString 在指定矩形并且用指定的 Brush 和 Font 对象绘制指定的文本字符串。   
            grPhoto.DrawString(waterWords,                                    //string of text   
                                       crFont,                                         //font   
                                       semiTransBrush2,                            //Brush   
                                       new PointF(xPosOfWm + 1, yPosOfWm + 1),  //Position   
                                       strFormat);

            //从四个 ARGB 分量(alpha、红色、绿色和蓝色)值创建 Color 结构,这里设置透明度为153   
            //这个画笔为描绘正式文字的笔刷,呈白色   
            var semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));

            //第二次绘制这个图形,建立在第一次描绘的基础上   
            grPhoto.DrawString(waterWords,                 //string of text   
                                       crFont,                                   //font   
                                       semiTransBrush,                           //Brush   
                                       new PointF(xPosOfWm, yPosOfWm),  //Position   
                                       strFormat);

            //imgPhoto是我们建立的用来装载最终图形的Image对象   
            //bmPhoto是我们用来制作图形的容器,为Bitmap对象   
            imgPhoto = bmPhoto;
            //释放资源,将定义的Graphics实例grPhoto释放,grPhoto功德圆满   
            grPhoto.Dispose();

            //将grPhoto保存   
            imgPhoto.Save(picturePath, ImageFormat.Jpeg);
            imgPhoto.Dispose();

            return picturePath;
        }
Пример #49
0
        /// <summary>   
        /// 添加图片水印   
        /// </summary>   
        /// <param name="sourcePicture">源图片文件名</param>   
        /// <param name="waterImage">水印图片文件名</param>   
        /// <param name="alpha">透明度(0.1-1.0数值越小透明度越高)</param>   
        /// <param name="position">位置</param>   
        /// <param name="picturePath" >图片的路径</param>   
        /// <returns>返回生成于指定文件夹下的水印文件名</returns>   
        public static string DrawImage(string sourcePicture, string waterImage, double alpha, ImagePosition position, string picturePath)
        {
            if (sourcePicture == string.Empty || waterImage == string.Empty || Math.Abs(alpha * 10) - 1 < 0 || picturePath == string.Empty)
            {
                return sourcePicture;
            }
            var imgPhoto = Image.FromFile(sourcePicture);
            //   
            // 确定其长宽   
            //   
            int phWidth = imgPhoto.Width;
            int phHeight = imgPhoto.Height;
            // 封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。   
            var bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
            // 设定分辨率   
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            // 定义一个绘图画面用来装载位图   
            var grPhoto = Graphics.FromImage(bmPhoto);

            //同样,由于水印是图片,我们也需要定义一个Image来装载它   
            Image imgWatermark = new Bitmap(waterImage);
            int wmWidth = imgWatermark.Width;
            int wmHeight = imgWatermark.Height;

            //SmoothingMode:指定是否将平滑处理(消除锯齿)应用于直线、曲线和已填充区域的边缘。   
            // 成员名称   说明    
            // AntiAlias      指定消除锯齿的呈现。     
            // Default        指定不消除锯齿。     
            // HighQuality  指定高质量、低速度呈现。     
            // HighSpeed   指定高速度、低质量呈现。     
            // Invalid        指定一个无效模式。     
            // None          指定不消除锯齿。    
            grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
            // 第一次描绘,将我们的底图描绘在绘图画面上   
            grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, phWidth, phHeight), 0, 0, phWidth, phHeight, GraphicsUnit.Pixel);

            var bmWatermark = new Bitmap(bmPhoto);
            bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            //   
            // 继续,将水印图片装载到一个绘图画面grWatermark   
            //   
            Graphics grWatermark = Graphics.FromImage(bmWatermark);

            //   
            //ImageAttributes 对象包含有关在呈现时如何操作位图和图元文件颜色的信息。   
            //          
            var imageAttributes = new ImageAttributes();

            //   
            //Colormap: 定义转换颜色的映射   
            //   
            var colorMap = new ColorMap
            {
                OldColor = Color.FromArgb(255, 0, 255, 0),
                NewColor = Color.FromArgb(0, 0, 0, 0)
            };

            //   
            //我的水印图被定义成拥有绿色背景色的图片被替换成透明   

            ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            float[][] colorMatrixElements = {    
           new[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f}, // red红色   
           new[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f}, //green绿色   
           new[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f}, //blue蓝色          
           new[] {0.0f,  0.0f,  0.0f,  (float)alpha, 0.0f}, //透明度        
           new[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}};//   

            //  ColorMatrix:定义包含 RGBA 空间坐标的 5 x 5 矩阵。   
            //  ImageAttributes 类的若干方法通过使用颜色矩阵调整图像颜色。   
            var wmColorMatrix = new ColorMatrix(colorMatrixElements);
            imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
             ColorAdjustType.Bitmap);
            //   
            //上面设置完颜色,下面开始设置位置   
            //   
            int xPosOfWm;
            int yPosOfWm;
            switch (position)
            {
                case ImagePosition.BottomMiddle:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.Center:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = (phHeight - wmHeight) / 2;
                    break;
                case ImagePosition.LeftBottom:
                    xPosOfWm = 10;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.LeftTop:
                    xPosOfWm = 10;
                    yPosOfWm = 10;
                    break;
                case ImagePosition.RightTop:
                    xPosOfWm = phWidth - wmWidth - 10;
                    yPosOfWm = 10;
                    break;
                case ImagePosition.RigthBottom:
                    xPosOfWm = phWidth - wmWidth - 10;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
                case ImagePosition.TopMiddle:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = 10;
                    break;
                default:
                    xPosOfWm = 10;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;
            }
            grWatermark.DrawImage(imgWatermark, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, wmWidth, wmHeight, GraphicsUnit.Pixel, imageAttributes);
            imgPhoto = bmWatermark;
            grPhoto.Dispose();
            grWatermark.Dispose();

            // 保存文件到服务器的文件夹里面   
            imgPhoto.Save(picturePath, ImageFormat.Jpeg);
            imgPhoto.Dispose();
            imgWatermark.Dispose();
            return picturePath;
        }
Пример #50
0
            public ImageWatermarkParameters(MemoryStream sourceImageStream, MemoryStream watermarkImageStream, 
                string sourceImageFileExtensionName, float alpha, ImagePosition wmPosition)
            {
                this.SourceImagePath = string.Empty;
                this.WatermarkImagePath = string.Empty; ;

                this.SourceImageStream = sourceImageStream;
                this.WatermarkImageStream = watermarkImageStream;
                this.Alpha = alpha;
                this.WmPosition = wmPosition;
                this._sourceImageFileExtensionName = sourceImageFileExtensionName;
            }
Пример #51
0
 /// シングルタッチした際のパラメータセット
 private void setSingleTapParam()
 {
     singleDTapBackPos    = singleTapParam.Pos;
     singleTapParam.Pos.X = useTouch.GetScrPosX( 0 );
     singleTapParam.Pos.Y = useTouch.GetScrPosY( 0 );
     singleTapParam.TouchId = useTouch.GetInputId( 0 );
     singleTouchFlg = true;
     singleFlicFlg  = false;
 }
Пример #52
0
        public static Button CreateButton(string textureName, string displayName, Vector2 position, ImagePosition orientation)
        {
            Texture texture = CreateTexture(textureName, displayName, position, orientation, false);
            Button button = new Button(texture);

            activeTextures.Add(button);

            return button;
        }