Example #1
0
        public StorageGif insert(string origFilePath, string url, Int32 actualWidth, Int32 actualHeight, Int32 folderId)
        {
            //补充idx,createTime两个参数
            FileInfo fileInfo = new FileInfo(origFilePath);
            int      filesize = 0;

            if (fileInfo.Exists)
            {
                filesize = (int)fileInfo.Length;
            }
            String origFilename = FileUtil.getFilename(origFilePath);

            StorageGif storageGif = new StorageGif();

            storageGif.origFilename = origFilename;
            storageGif.url          = url;
            storageGif.ext          = fileInfo.Extension;
            storageGif.size         = filesize;
            storageGif.createTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            storageGif.actualWidth  = actualWidth;
            storageGif.actualHeight = actualHeight;
            storageGif.folderId     = folderId;


            return(storageGifDal.insert(storageGif));
        }
        /*
         * 12 Gif
         */
        public static Gif newGif(DControl ctl, StorageGif storageGif, Boolean isDesign)
        {
            string imgPath     = FileUtil.notExistsShowDefault(storageGif?.url, Params.GifNotExists);
            string imgFullPath = AppDomain.CurrentDomain.BaseDirectory + imgPath;

            DControlDto dto = DControlUtil.convert(ctl);

            dto.url = imgFullPath;
            Gif gif = new Gif(imgPath, isDesign);

            gif.HorizontalAlignment = HorizontalAlignment.Left;
            gif.VerticalAlignment   = VerticalAlignment.Top;
            gif.Margin     = new Thickness(ctl.left, ctl.top, 0, 0);
            gif.Width      = ctl.width;
            gif.Height     = ctl.height;
            gif.Background = Brushes.Transparent;

            gif.Opacity = ctl.opacity / 100.0;
            Panel.SetZIndex(gif, ctl.idx);
            gif.Focusable = false;
            gif.Tag       = dto;
            TransformGroup group = new TransformGroup();

            gif.RenderTransform       = group;
            gif.RenderTransformOrigin = new Point(0.5, 0.5);
            RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);

            rotateTransform.Angle = ctl.rotateAngle;
            gif.Visibility        = Visibility.Visible;
            return(gif);
        }
        //1、插入图片
        public StorageGif insert(StorageGif entity)
        {
            String sql = "insert into storageGif(origFilename,url,ext,size,createTime,actualWidth,actualHeight,folderId) values(@origFilename,@url,@ext,@size,@createTime,@actualWidth,@actualHeight,@folderId);select last_insert_rowid();";

            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@origFilename", DbType.String, 100),
                new SQLiteParameter("@url",          DbType.String, 255),
                new SQLiteParameter("@ext",          DbType.String,  10),
                new SQLiteParameter("@size",         DbType.Int32,    4),
                new SQLiteParameter("@createTime",   DbType.String,  30),
                new SQLiteParameter("@actualWidth",  DbType.String,   4),
                new SQLiteParameter("@actualHeight", DbType.Int32,    4),
                new SQLiteParameter("@folderId",     DbType.Int32, 4)
            };
            parameters[0].Value = entity.origFilename;
            parameters[1].Value = entity.url;
            parameters[2].Value = entity.ext;
            parameters[3].Value = entity.size;
            parameters[4].Value = entity.createTime;
            parameters[5].Value = entity.actualWidth;
            parameters[6].Value = entity.actualHeight;
            parameters[7].Value = entity.folderId;

            DataTable dt = Common.SQLiteHelper.ExecuteQuery(sql, parameters);
            int       id = DataType.ToInt32(dt.Rows[0]["last_insert_rowid()"].ToString());

            entity.id = id;
            return(entity);
        }
        /*
         * 更新
         */
        public int upate(StorageGif entity)
        {
            string sql = "update storageGif set origFilename=@origFilename,url=@url,size=@size"
                         + ",ext=@ext,createTime=@createTime,actualWidth=@actualWidth"
                         + ",actualHeight=@actualHeight,folderId=@folderId"
                         + "  where id=@id";

            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@origFilename", DbType.String, 100),
                new SQLiteParameter("@url",          DbType.String, 255),
                new SQLiteParameter("@size",         DbType.Int32,    4),
                new SQLiteParameter("@ext",          DbType.String,  10),
                new SQLiteParameter("@createTime",   DbType.String,  30),
                new SQLiteParameter("@actualWidth",  DbType.Int32,    4),
                new SQLiteParameter("@actualHeight", DbType.Int32,    4),
                new SQLiteParameter("@folderId",     DbType.Int32,    4),
                new SQLiteParameter("@id",           DbType.Int32, 4)
            };
            parameters[0].Value = entity.origFilename;
            parameters[1].Value = entity.url;
            parameters[2].Value = entity.size;
            parameters[3].Value = entity.ext;

            parameters[4].Value = entity.createTime;
            parameters[5].Value = entity.actualWidth;
            parameters[6].Value = entity.actualHeight;
            parameters[7].Value = entity.folderId;
            parameters[8].Value = entity.id;

            int result = Common.SQLiteHelper.ExecuteNonQuery(sql, parameters);

            return(result);
        }
        private void Open_Dialogue_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;

            System.Windows.Forms.OpenFileDialog ofld = new System.Windows.Forms.OpenFileDialog();
            ofld.Filter      = "GIF图片|*.gif;";
            ofld.Multiselect = false;
            if (ofld.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                String filename = ofld.FileName;
                if (filename != "" || filename != null)
                {
                    System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(filename);
                    String     url        = uploadImage(btn, filename);
                    StorageGif storageGif = storageGifBll.insert(filename, url, sourceImage.Width, sourceImage.Height, folderId);
                    //this.currDControl.url = url;
                    //this.currDControl.imgs = jpgPath;

                    //插入一个视频到列表
                    Canvas newImage = initOneImage(storageGif);
                    imageListWrap.Children.Insert(0, newImage);
                    selectButton(newImage);
                }
            }
        }
        /*
         * 3.2插入一行文字
         */
        public void insertGifToPage(DControl ctl)
        {
            StorageGif storageGif = storageGifBll.get(ctl.storageId);
            Gif        gif        = NewControlUtil.newGif(ctl, storageGif, false);

            loadAllAnimation(gif, ctl);
            gif.PreviewMouseUp += gif_PreviewMouseUp;
            gif.PreviewTouchUp += gif_PreviewTouchUp;
            mainContainer.Children.Add(gif);
        }
        /*
         * 7.1 单击gif跳转
         *
         * 1.单击图片跳转到页面
         *
         * 2.跳转到外部网站
         *
         * 3.单击图片全屏播放视频
         *
         * 4.单击图片放大
         *
         *
         */
        private void gifFun(object sender)
        {
            Gif         gif = (Gif)sender;
            DControlDto ctl = (DControlDto)gif.Tag;

            this.DifferentScreenDifferentLinkTo(ctl);
            if (!string.IsNullOrWhiteSpace(ctl.linkToWeb))
            {
                Int32  pagePercent = FrameUtil.getMaxPercent(App.localStorage.cfg.screenWidth, App.localStorage.cfg.screenHeight);
                double screenWidth = SystemParameters.PrimaryScreenWidth;//得到屏幕整体宽度
                int    winWidth    = (int)(App.localStorage.cfg.screenWidth * pagePercent / 100);
                int    winHeight   = (int)(App.localStorage.cfg.screenHeight * pagePercent / 100);

                App.localStorage.currForm1 = new Form1(winWidth, winHeight, ctl.linkToWeb, screenWidth);
                App.localStorage.currForm1.ShowDialog();
            }
            else if (ctl.linkToVideoId > 0)
            {
                insertFullVideoToPage(ctl);
            }
            else if (ctl.isClickShow)
            {
                int frameWidth  = App.localStorage.cfg.screenWidth;
                int frameHeight = App.localStorage.cfg.screenHeight;
                if (dPage.width > 0)
                {
                    frameWidth = dPage.width;
                }
                if (dPage.height > 0)
                {
                    frameHeight = dPage.height;
                }

                Cfg cfg = new Cfg();
                cfg.screenWidth  = frameWidth;
                cfg.screenHeight = frameHeight;

                StorageGif storageGif = storageGifBll.get(ctl.storageId);
                if (storageGif == null)
                {  //默认gif
                    storageGif              = new StorageGif();
                    storageGif.id           = 0;
                    storageGif.url          = Params.GifNotExists;
                    storageGif.actualWidth  = 550;
                    storageGif.actualHeight = 400;
                    storageGif.ext          = ".gif";
                    storageGif.origFilename = "gif.gif";
                    storageGif.size         = 304874;
                    storageGif.folderId     = 1;
                }

                ShowBigGifUtil.showBigImage(storageGif, ctl, mainContainer, cfg);
            }
        }
Example #8
0
 /*
  * 删除
  */
 public Int32 delete(StorageGif storageGif)
 {
     if (storageGif == null)
     {
         return(0);
     }
     if (string.IsNullOrWhiteSpace(storageGif.url))
     {
         return(0);
     }
     //string fullFilePath = AppDomain.CurrentDomain.BaseDirectory + storageGif.url;
     //Boolean b = File.Exists(fullFilePath);
     //if (b)
     //{
     //    File.Delete(fullFilePath);
     //}
     return(storageGifDal.delete(storageGif.id));
 }
Example #9
0
        /*
         * 3.3插入Gif
         */
        public void insertGifToPage(DControl ctl)
        {
            StorageGif storageGif  = storageGifBll.get(ctl.storageId);
            string     imgFullPath = FileUtil.notExistsShowDefault(storageGif?.url, Params.GifNotExists);

            imgFullPath = AppDomain.CurrentDomain.BaseDirectory + imgFullPath;

            Gif gifImage = NewControlUtil.newGif(ctl, storageGif, true);

            gifImage.Style = pageTemplate.container.TryFindResource("GifImageStyle") as System.Windows.Style;

            //控件拖动
            gifImage.PreviewMouseLeftButtonDown += control_MouseDown;
            gifImage.PreviewMouseMove           += control_MouseMove;
            gifImage.PreviewMouseLeftButtonUp   += control_MouseUp;

            //控件上右击显示菜单
            gifImage.MouseRightButtonUp += control_MouseRightButtonUp;
            pageTemplate.container.Children.Add(gifImage);
        }
        //获取图片
        public StorageGif get(Int32 id)
        {
            String sql = "select * from storageGif where id=@id";

            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@id", DbType.Int32, 4)
            };
            parameters[0].Value = id;

            DataTable dt = Common.SQLiteHelper.ExecuteQuery(sql, parameters);

            if (dt == null || dt.Rows.Count == 0)
            {
                return(null);
            }
            StorageGif storageGif = DataToEntity <StorageGif> .FillModel(dt.Rows[0]);

            return(storageGif);
        }
        private void init(DControl ctl)
        {
            StorageGif storageGif  = storageGifBll.get(ctl.storageId);
            string     imgFullPath = FileUtil.notExistsShowDefault(storageGif?.url, Params.GifNotExists);
            string     filename    = FileUtil.getFilename(imgFullPath);
            string     fullFolder  = FileUtil.getDirectory(AppDomain.CurrentDomain.BaseDirectory + imgFullPath);

            url.Content           = filename;
            url.Tag               = fullFolder;
            width.Text            = ctl.width.ToString();
            height.Text           = ctl.height.ToString();
            left.Text             = ctl.left.ToString();
            top.Text              = ctl.top.ToString();
            isClickShow.IsChecked = ctl.isClickShow;
            opacity.Text          = ctl.opacity.ToString();
            idx.Content           = ctl.idx.ToString();
            isTab.IsChecked       = ctl.isTab;
            rotateAngle.Text      = ctl.rotateAngle.ToString();

            actualWidthHeight.Content     = storageGif?.actualWidth + "*" + storageGif?.actualHeight;
            url.PreviewMouseLeftButtonUp += url_PreviewMouseLeftButtonUp;
        }
        /*
         * 保存视频
         */
        private void Submit_Button_Click(object sender, RoutedEventArgs e)
        {
            DControl currDControl = (DControl)currElement.Tag;
            //更新到数据库
            DControl dControl = dControlBll.get(currDControl.id);

            dControl.storageId = this.currDControl.storageId;
            dControlBll.update(dControl);

            //更新页面控件信息
            StorageGif storageGif  = storageGifBll.get(dControl.storageId);
            string     imgFullPath = FileUtil.notExistsShowDefault(storageGif?.url, Params.ImageNotExists);

            imgFullPath = AppDomain.CurrentDomain.BaseDirectory + imgFullPath;

            Gif gif = (Gif)currElement;

            gif.updateElement(imgFullPath, true);
            currElement.Tag = dControl;

            Close();
        }
Example #13
0
        /*
         * 显示大图
         */
        public static void showBigImage(StorageGif storageGif, DControlDto ctl, Grid mainContainer, Cfg cfg)
        {
            FrameworkElement bigImageElement = FrameworkElementUtil.getByName(mainContainer, "bigImageCanvas");

            if (bigImageElement == null)
            {
                Canvas bigImageCanvas = new Canvas();
                bigImageCanvas.Name       = "bigImageCanvas";
                bigImageCanvas.Width      = cfg.screenWidth;
                bigImageCanvas.Height     = cfg.screenHeight;
                bigImageCanvas.Background = Brushes.Transparent;
                Panel.SetZIndex(bigImageCanvas, 10002);



                //图片背景,点击隐藏
                Border borderBg = new Border();
                borderBg.Width               = cfg.screenWidth;
                borderBg.Height              = cfg.screenHeight;
                borderBg.Background          = Brushes.Black;
                borderBg.Opacity             = 0.6;
                borderBg.HorizontalAlignment = HorizontalAlignment.Left;
                borderBg.VerticalAlignment   = VerticalAlignment.Top;
                borderBg.SetValue(Canvas.LeftProperty, 0.0);
                borderBg.SetValue(Canvas.TopProperty, 0.0);
                Panel.SetZIndex(borderBg, 1);
                bigImageCanvas.Children.Add(borderBg);



                //显示大图
                double maxWidth  = cfg.screenWidth * 0.9;
                double maxHeight = cfg.screenHeight * 0.9;
                //   BitmapImage bitmapImage = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + storageGif.url);
                double showWidth  = storageGif.actualWidth;
                double showHeight = storageGif.actualHeight;
                double w          = storageGif.actualWidth / maxWidth;
                double h          = storageGif.actualHeight / maxHeight;
                if (w > 1 && h > 1)
                {
                    if (w > h)
                    {
                        showWidth  = maxWidth;
                        showHeight = storageGif.actualHeight / w;
                    }
                    else
                    {
                        showHeight = maxHeight;
                        showWidth  = storageGif.actualWidth / h;
                    }
                }
                else if (w > 1)
                {
                    showWidth  = maxWidth;
                    showHeight = storageGif.actualHeight / w;
                }
                else if (h > 1)
                {
                    showHeight = maxHeight;
                    showWidth  = storageGif.actualWidth / h;
                }

                Canvas innerCanvas = new Canvas();
                innerCanvas.Width  = showWidth;
                innerCanvas.Height = showHeight;
                double left = ctl.left;
                double top  = ctl.top;
                innerCanvas.SetValue(Canvas.LeftProperty, left);
                innerCanvas.SetValue(Canvas.TopProperty, top);
                Panel.SetZIndex(innerCanvas, 2);


                Gif image = new Gif(storageGif.url, false);
                image.Width  = showWidth;
                image.Height = showHeight;
                Panel.SetZIndex(image, 1);
                innerCanvas.Children.Add(image);

                Button closebtn = new Button();
                closebtn.Background = new ImageBrush
                {
                    ImageSource = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + "/myfile/sysimg/ico-image-close.png")
                    ,
                    Stretch = Stretch.Fill
                };

                closebtn.Width               = 50;
                closebtn.Height              = 50;
                closebtn.BorderThickness     = new Thickness(0);
                closebtn.HorizontalAlignment = HorizontalAlignment.Right;
                closebtn.VerticalAlignment   = VerticalAlignment.Top;
                closebtn.SetValue(Canvas.RightProperty, -25.0);
                closebtn.SetValue(Canvas.TopProperty, -25.0);
                Panel.SetZIndex(closebtn, 2);

                closebtn.Click            += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer);
                closebtn.PreviewTouchDown += imageCloseBtnTouchDown;
                closebtn.PreviewTouchMove += imageCloseBtnTouchMove;
                closebtn.PreviewTouchUp   += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer);
                innerCanvas.Children.Add(closebtn);


                bigImageCanvas.Children.Add(innerCanvas);
                borderBg.PreviewMouseUp += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer);
                borderBg.PreviewTouchUp += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer);

                //手指缩放 移动 旋转
                BehaviorCollection          behaviors = Interaction.GetBehaviors(innerCanvas);
                TranslateZoomRotateBehavior tz        = new TranslateZoomRotateBehavior();
                tz.TranslateFriction       = 0.3;
                tz.RotationalFriction      = 0.4;
                tz.ConstrainToParentBounds = true;
                tz.SupportedGestures       = ManipulationModes.All;
                behaviors.Add(tz);

                TransformGroup group          = new TransformGroup();
                double         scaleX         = ctl.width / innerCanvas.Width;
                double         scaleY         = ctl.height / innerCanvas.Height;
                ScaleTransform scaleTransform = new ScaleTransform();
                scaleTransform.ScaleX = scaleX;
                scaleTransform.ScaleY = scaleY;
                group.Children.Add(scaleTransform);
                innerCanvas.RenderTransform = group;

                //动画,平移到指定位置
                double toLeft = (cfg.screenWidth - innerCanvas.Width) / 2;
                double toTop  = (cfg.screenHeight - innerCanvas.Height) / 2;
                double toTranslateTransformX = toLeft - ctl.left;
                double toTranslateTransformY = toTop - ctl.top;

                ShowBigGifUtil.showAnimation(borderBg, innerCanvas, ctl, toTranslateTransformX, toTranslateTransformY);

                mainContainer.Children.Add(bigImageCanvas);
            }
        }
Example #14
0
        /*
         * 更新图片
         */
        public StorageGif update(StorageGif one)
        {
            int rows = storageGifDal.upate(one);

            return(one);
        }
        private void addItem(StorageGif storageGif)
        {
            Canvas imageCanvas = initOneImage(storageGif);

            imageListWrap.Children.Add(imageCanvas);
        }
        //public void DoEvents()
        //{
        //    DispatcherFrame frame = new DispatcherFrame();
        //    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
        //        new DispatcherOperationCallback(ExitFrames), frame);
        //    Dispatcher.PushFrame(frame);
        //}

        //public object ExitFrames(object f)
        //{
        //    ((DispatcherFrame)f).Continue = false;

        //    return null;
        //}

        /*
         * 初始化一个图片控件
         */
        private Canvas initOneImage(StorageGif storageGif)
        {
            GifListTag tag = new GifListTag();

            tag.isSelected = false;
            tag.storageGif = storageGif;
            Canvas imageCanvas = new Canvas();

            imageCanvas.Name   = "imageCanvas";
            imageCanvas.Width  = 100;
            imageCanvas.Height = 100;
            imageCanvas.Margin = new Thickness(10);
            imageCanvas.Tag    = tag;

            //1.按钮
            string imgFullPath = FileUtil.notExistsShowDefault(storageGif.url, Params.ImageNotExists);

            imgFullPath = AppDomain.CurrentDomain.BaseDirectory + imgFullPath;

            Image image = new Image();

            image.Name    = "image";
            image.Width   = 100;
            image.Height  = 75;
            image.Source  = FileUtil.readImage2(imgFullPath, 200);;
            image.Stretch = Stretch.Uniform;


            //2.按钮行
            Canvas bg = new Canvas();

            bg.Name       = "bg";
            bg.Background = Brushes.Black;
            bg.Width      = 100;
            bg.Height     = 24;
            bg.Opacity    = 0.6;
            bg.SetValue(Canvas.BottomProperty, 25.0);
            bg.SetValue(Canvas.LeftProperty, 0.0);

            //时长
            Label lLabel = new Label();

            lLabel.Width      = 100;
            lLabel.Height     = 24;
            lLabel.Content    = storageGif.actualWidth + "×" + storageGif.actualHeight;
            lLabel.Foreground = Brushes.White;
            lLabel.SetValue(Canvas.LeftProperty, 0.0);
            lLabel.SetValue(Canvas.TopProperty, 0.0);
            bg.Children.Add(lLabel);

            //删除按钮
            Button rbtn = new Button();

            rbtn.Width           = 16;
            rbtn.Height          = 16;
            rbtn.BorderThickness = new Thickness(0);
            rbtn.Background      = new ImageBrush
            {
                ImageSource = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + "/myfile/sysimg/ico-image-remove.png")
                ,
                Stretch = Stretch.UniformToFill
            };
            rbtn.SetValue(Canvas.RightProperty, -8.0);
            rbtn.SetValue(Canvas.TopProperty, -8.0);
            // bg.Children.Add(rbtn);
            // rbtn.Click += rbtnClick;


            //标题
            Label titleLabel = new Label();

            titleLabel.Width   = 100;
            titleLabel.Height  = 25;
            titleLabel.Content = storageGif.origFilename;
            titleLabel.SetValue(Canvas.LeftProperty, 0.0);
            titleLabel.SetValue(Canvas.BottomProperty, 0.0);
            titleLabel.ToolTip = titleLabel.Content;


            //勾选
            Button selectButton = new Button();

            selectButton.Name            = "selectButton";
            selectButton.Tag             = storageGif.id;
            selectButton.Width           = 24;
            selectButton.Height          = 24;
            selectButton.BorderThickness = new Thickness(0);
            selectButton.SetValue(Canvas.LeftProperty, 7.0);
            selectButton.SetValue(Canvas.TopProperty, 7.0);

            selectButton.Background = new ImageBrush
            {
                ImageSource = new BitmapImage(new Uri(@"Resources/ico_media_select.png", UriKind.Relative)),
                Stretch     = Stretch.UniformToFill
            };
            selectButton.Visibility = Visibility.Hidden;



            imageCanvas.MouseEnter          += imageCanvasMouseEnter;
            imageCanvas.MouseLeave          += imageCanvasMouseLeave;
            imageCanvas.MouseLeftButtonDown += selectButtonClick;
            selectButton.Click += selectButtonClick;



            imageCanvas.Children.Add(image);
            imageCanvas.Children.Add(bg);
            imageCanvas.Children.Add(titleLabel);
            imageCanvas.Children.Add(selectButton);
            // videoCanvas.Children.Add(rbtn);

            return(imageCanvas);
        }