Пример #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is byte[] arr))
            {
                return(null);
            }
            if (arr.Length == 0)
            {
                return(null);
            }

            try
            {
                var bmpSrc = (BitmapSource)converter.ConvertFrom(arr);
                return(bmpSrc);
            }
            catch { return(null); }
        }
Пример #2
0
        private void InitImg(System.Windows.Controls.Image img)
        {
            Stream stm = Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + ".fan.bmp");

            stm.Position = 0;
            BinaryReader br = new BinaryReader(stm);

            byte[] FacePicture = br.ReadBytes((int)stm.Length);
            br.Close();
            stm.Close();

            ImageSourceConverter imageSourceConverter = new ImageSourceConverter();

            stream = new MemoryStream(FacePicture);
            BitmapFrame source = imageSourceConverter.ConvertFrom(stream) as BitmapFrame;

            img.Source = source;
        }
        private void btnConvertToPainting_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog();

            if (!dlg.ShowDialog().Value)
            {
                return;
            }

            string path = dlg.FileName;

            // Process image

            ImageRecognitionAndProcessingClient client = new ImageRecognitionAndProcessingClient();

            System.Drawing.Image outcome = client.ConvertToPainting(File.ReadAllBytes(path));


            var imageSourceConverter = new ImageSourceConverter();

            byte[]      tempBitmap = BitmapToByte((System.Drawing.Bitmap)outcome);
            ImageSource image      = (ImageSource)imageSourceConverter.ConvertFrom(tempBitmap);


            imgOutput.Source = image;

            // Log success

            CloudmersiveAuditClient client2 = new CloudmersiveAuditClient();

            AuditLogWriteRequest req = new AuditLogWriteRequest();

            req.AuditLogMessage     = "Successfully processed image.";
            req.AuditLogReferenceIP = GetLocalIPAddress();
            req.AuditLogMeta        = dlg.FileName;

            CloudmersiveValidationApiClient valid = new CloudmersiveValidationApiClient();
            var geo = valid.GeolocateIP(req.AuditLogReferenceIP);

            req.AuditLogReferenceLocation = JsonConvert.SerializeObject(geo);

            client2.WriteLogMessageFull(req);
        }
Пример #4
0
 /// <summary>
 /// 双击列表会根据选中行显示该视频的详细信息,并且获取封面
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ReaderView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if (ReaderView.SelectedValue != null)
     {
         UpMessage vedio = (UpMessage)ReaderView.SelectedValue;
         VedioView vv    = new VedioView();
         vv.Title = $"{vedio.aid}详细信息";
         vv.TitleLabel.Content   = vedio.title;
         vv.descriptionBox.Text  = vedio.description;
         vv.aidLabel.Content     = $"av号:{vedio.aid}";
         vv.playLabel.Content    = $"播放数:{vedio.play}";
         vv.lengthLabel.Content  = $"视频长度:{vedio.length}";
         vv.createdLabel.Content = $"审核通过时间:{vedio.created}";
         ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
         vv.titlePic.Source = (ImageSource)imageSourceConverter.ConvertFrom(BiliBiliReader.getPic(vedio.pic));
         VedioView.Pic_Name = vedio.pic;
         vv.Show();
     }
 }
Пример #5
0
        private async Task <ImageSource> LoadImageSourceAsync(string address)
        {
            ImageSource imgSource = null;

            try
            {
                string               url = EncodeUrl(address);
                MemoryStream         ms  = new MemoryStream(await new WebClient().DownloadDataTaskAsync(new Uri(url)));
                ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                imgSource = (ImageSource)imageSourceConverter.ConvertFrom(ms);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }

            return(imgSource);
        }
Пример #6
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string path = (string)value;

            if (!File.Exists(path))
            {
                return(new ImageBrush());
            }
            Bitmap       bitmap = new Bitmap(path);
            MemoryStream stream = new MemoryStream();

            bitmap.Save(stream, ImageFormat.Png);
            bitmap.Dispose();
            ImageBrush           imageBrush           = new ImageBrush();
            ImageSourceConverter imageSourceConverter = new ImageSourceConverter();

            imageBrush.ImageSource = (ImageSource)imageSourceConverter.ConvertFrom(stream);
            return(imageBrush);
        }
Пример #7
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            if (value is VirtualFile file)
            {
                return(file.ToImageSource());
            }

            if (Converter.CanConvertFrom(value.GetType()))
            {
                return(Converter.ConvertFrom(value));
            }

            return(null);
        }
Пример #8
0
 public bool PreviewTex(FileNode texNode)
 {
     try
     {
         byte[] texdata = null;
         if (mergeChecked)
         {
             texdata = ((Chunk)chunkMap.First().Value).GetFileData(texNode);
         }
         else
         {
             texdata = mainChunk.GetFileData(texNode);
         }
         Bitmap pic = texPreviewer.GetPic(texdata);
         if (pic == null)
         {
             return(false);
         }
         texStream.Seek(0, SeekOrigin.Begin);
         texStream.SetLength(0);
         pic.Save(texStream, ImageFormat.Png);
         ImageBrush           imageBrush           = new ImageBrush();
         ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
         imageBrush.ImageSource = (ImageSource)imageSourceConverter.ConvertFrom(texStream);
         PreviewImage.Source    = imageBrush.ImageSource;
         return(true);
     }
     catch (Exception ex)
     {
         if (!CNMode)
         {
             PrintLog("Error occured while previewing.");
         }
         else
         {
             PrintLog("预览时发生错误");
         }
         Console.WriteLine(ex);
         texPreviewer = new TexPreviewer();
         return(false);
     }
 }
Пример #9
0
        /// <summary>
        /// 让图片框显示图片(按路径)
        /// </summary>
        /// <param name="path"></param>
        private void ShowPictrue(string path)
        {
            System.Drawing.Bitmap  bitmap = new System.Drawing.Bitmap(path);
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            ImageBrush           imageBrush           = new ImageBrush();
            ImageSourceConverter imageSourceConverter = new ImageSourceConverter();

            sourceComicImg.Source = (ImageSource)imageSourceConverter.ConvertFrom(stream);
            if (RealsizeTBtn.IsChecked == true)
            {
                sourceComicImg.Width  = bitmap.Width;
                sourceComicImg.Height = bitmap.Height;
            }
            else
            {
                sourceComicImg.Width  = this.Width * 0.7;
                sourceComicImg.Height = this.Height;
            }
        }
Пример #10
0
 public static void SetImage(int len, byte[] buffer)
 {
     if (buffer == null)
     {
         return;
     }
     try
     {
         ImageSourceConverter converter = new ImageSourceConverter();
         Stream ms     = new MemoryStream(buffer);
         var    bitmap = converter.ConvertFrom(ms) as BitmapFrame;
         MainWindow.Instance.Dispatcher.BeginInvoke(new Action(() =>
         {
             //imgGame.Source = bitmap;
         }), DispatcherPriority.Render);
     }
     catch (Exception ex)
     {
     }
 }
Пример #11
0
        public void Refresh()
        {
            if (ms != null)
            {
                ms.Close();
            }

            this.Name    = this.info.Name;
            this.Content = this.info.ToString();
            if (info.GetInfoType().Equals(BaseInfoType.InfoType.Picture))
            {
                ms = new MemoryStream(info.Data);

                ImageBrush           imageBrush           = new ImageBrush();
                ImageSourceConverter imageSourceConverter = new ImageSourceConverter();

                this.Source = (ImageSource)imageSourceConverter.ConvertFrom(ms);
                //ms.Close();
            }
        }
Пример #12
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            Size renderSize = this.RenderSize;

            drawingContext.DrawRectangle(new SolidColorBrush(Colors.White), null,
                                         new Rect(0, 0, renderSize.Width, renderSize.Height));

            if (manager != null)
            {
                TextView textView = this.TextView;
                if (textView != null && textView.VisualLinesValid)
                {
                    // create a dictionary line number => first bookmark
                    Dictionary <int, IBookmark> bookmarkDict = new Dictionary <int, IBookmark>();
                    foreach (IBookmark bm in manager.Bookmarks)
                    {
                        int       line = bm.LineNumber;
                        IBookmark existingBookmark;
                        if (!bookmarkDict.TryGetValue(line, out existingBookmark))
                        {
                            bookmarkDict.Add(line, bm);
                        }
                    }
                    Size pixelSize = PixelSnapHelpers.GetPixelSize(this);
                    foreach (VisualLine line in textView.VisualLines)
                    {
                        int       lineNumber = line.FirstDocumentLine.LineNumber;
                        IBookmark bm;
                        if (bookmarkDict.TryGetValue(lineNumber, out bm))
                        {
                            double lineMiddle = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextMiddle) - textView.VerticalOffset;
                            Rect   rect       = new Rect(0, PixelSnapHelpers.Round(lineMiddle - 8, pixelSize.Height), 16, 16);

                            ImageSourceConverter isc = new ImageSourceConverter();
                            var img = isc.ConvertFrom("pack://siteoforigin:,,,/" + (bm.Image ?? BookmarkBase.DefaultBookmarkImage)) as ImageSource;
                            drawingContext.DrawImage(img, rect);
                        }
                    }
                }
            }
        }
Пример #13
0
        // Listing 2.6 Event register with lambda expression capturing local variable
        void UpdateImage(string url)
        {
            System.Windows.Controls.Image image = img; //#A

            var client = new WebClient();

            client.DownloadDataCompleted += (o, e) => //#B
            {
                if (image != null)
                {
                    using (var ms = new MemoryStream(e.Result))
                    {
                        var imageConverter = new ImageSourceConverter();
                        image.Source = (ImageSource)imageConverter.ConvertFrom(ms);
                    }
                }
            };
            client.DownloadDataAsync(new Uri(url)); //#C

            // image = null; //#A from Listing 2.7
        }
Пример #14
0
        public object Convert(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            var str            = value.ToString();
            var converterBoxed = _converter.ConvertFrom(str);

            if (converterBoxed is ImageSource imageSource)
            {
                return(imageSource);
            }

            return(null);
        }
Пример #15
0
        private void CreateQRCode(object sender, RoutedEventArgs e)
        {
            // 生成二维码的内容
            MainWindow mainwin = (MainWindow)Application.Current.MainWindow;
            string     strCode = Setting.BASE_URL + "pdf/";

            if (Type == 1)
            {
                Boolean isSuccess = false;
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("uid", mainwin.User.id.ToString());
                string url   = Setting.BASE_URL + "test/getOverallReport";
                string rtext = HttpRequestHelper.HttpGet(url, parameters, ref isSuccess);
                strCode += No + "overall.pdf";
            }
            else
            {
                Boolean isSuccess = false;
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("uid", mainwin.User.id.ToString());
                parameters.Add("tid", No);
                string url   = Setting.BASE_URL + "test/getSingleReport";
                string rtext = HttpRequestHelper.HttpGet(url, parameters, ref isSuccess);
                strCode += mainwin.User.id + No + "test.pdf";
            }
            url = strCode;

            QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q);
            QRCode          qrcode      = new QRCode(qrCodeData);

            MemoryStream stream      = new MemoryStream();
            Bitmap       qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, false);

            qrCodeImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            ImageBrush           imageBrush           = new ImageBrush();
            ImageSourceConverter imageSourceConverter = new ImageSourceConverter();

            QRCode.Source = (ImageSource)imageSourceConverter.ConvertFrom(stream);
        }
Пример #16
0
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            isnew = true;
            if (lstFields.SelectedItems.Count == 0)
            {
                MessageBox.Show("请选择要生成二维码的字段");
            }
            else
            {
                SelectFields = new List <string>();
                StringBuilder qrcontent = new StringBuilder();
                foreach (object item in lstFields.SelectedItems)
                {
                    string filed = item.ToString().Replace(" ", "");
                    qrcontent.AppendLine(filed);
                    SelectFields.Add(filed);
                }

                QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
                QrCode    qrCode    = new QrCode();
                qrEncoder.TryEncode(qrcontent.ToString(), out qrCode);

                GraphicsRenderer render       = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), System.Drawing.Brushes.Black, System.Drawing.Brushes.White);
                MemoryStream     memoryStream = new MemoryStream();
                render.WriteToStream(qrCode.Matrix, ImageFormat.Png, memoryStream);

                byte[] bytearray = null;
                memoryStream.Position = 0;
                using (BinaryReader br = new BinaryReader(memoryStream))
                {
                    bytearray = br.ReadBytes((int)memoryStream.Length);
                }

                ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                imgQRcode.Source = (ImageSource)imageSourceConverter.ConvertFrom(bytearray);

                QRImageSource = bytearray;
            }
        }
Пример #17
0
        /// <summary>
        /// 二维码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void hlinkQRCode_Click(object sender, RoutedEventArgs e)
        {
            QRCodeManageDialog qrcode = new QRCodeManageDialog(QRFields, QRCodeImageSource);

            qrcode.UpdateQRCodeSource += (fields, imagesource) =>
            {
                this.QRFields          = fields;
                this.QRCodeImageSource = imagesource;

                if (imagesource != null)
                {
                    ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                    imgQRcode.Source = (ImageSource)imageSourceConverter.ConvertFrom(QRCodeImageSource);
                }
                else
                {
                    imgQRcode.Source = null;
                    MessageBox.Show("请选择生成二维码字段");
                }
            };
            qrcode.ShowDialog();
        }
Пример #18
0
        /// <summary>
        /// new Uri("pack://application:,,,/Images/home-icon-bluecamera.png")
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datasource"></param>
        /// <param name="uri"></param>
        /// <returns></returns>
        public static ObservableCollection <PointLatLngImg> SetMapAnchor <T>(IEnumerable datasource, Uri uri)
            where T : class, new()
        {
            T t = new T();
            ObservableCollection <PointLatLngImg> Points = new ObservableCollection <PointLatLngImg>();

            if (t is TargetedAnalysis)
            {
                try
                {
                    foreach (TargetedAnalysis item in datasource)
                    {
                        PointLatLngImg point = new PointLatLngImg();
                        point.Point = new GMap.NET.PointLatLng(Convert.ToDouble(item.Latitude),
                                                               Convert.ToDouble(item.Longitude));

                        ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                        StreamResourceInfo   streamResourceInfo   = Application.GetResourceStream(uri);
                        point.Img           = (ImageSource)imageSourceConverter.ConvertFrom(streamResourceInfo.Stream);
                        point.ImgVisibility = Visibility.Visible;

                        point.ChannelName               = item.Name;
                        point.Location                  = item.Channel_address;
                        point.SnapPersonCount           = item.Count;
                        point.ChannelNameVisibility     = Visibility.Visible;
                        point.LocationVisibility        = Visibility.Visible;
                        point.SnapPersonCountVisibility = Visibility.Visible;

                        Points.Add(point);
                    }
                }
                catch (Exception ex)
                {
                    Logger <GMapForWpf> .Log.Error("SetMapAnchor<T>", ex);
                }
            }
            return(Points);
        }
Пример #19
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            //Reference this code
            var cm = new ColorMatrix(new float[][]
            {
                new float[] { byteToFloat((byte)sldRed.Value), 0, 0, 0, 0 },
                new float[] { 0, byteToFloat((byte)sldGreen.Value), 0, 0, 0 },
                new float[] { 0, 0, byteToFloat((byte)sldBlue.Value), 0, 0 },
                new float[] { 0, 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 0, 1 }
            });



            var img = System.Drawing.Image.FromFile(@"C:\\img.png");


            var ia = new ImageAttributes();

            ia.SetColorMatrix(cm);

            bmp = new Bitmap(img.Width, img.Height);
            var gfx  = Graphics.FromImage(bmp);
            var rect = new System.Drawing.Rectangle(0, 0, img.Width, img.Height);

            gfx.DrawImage(img, rect, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);

            ImageSourceConverter c      = new ImageSourceConverter();
            MemoryStream         stream = new MemoryStream();

            bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);

            ImageSource newImage = (ImageSource)c.ConvertFrom(stream);



            imgRecol.Source = newImage;
        }
Пример #20
0
        //回调函数
        private void SaveImageCallBack(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO pFrameInfo, IntPtr pUser)
        {
            DateTime dataTime1 = DateTime.Now;

            if ((3 * pFrameInfo.nFrameLen + 2048) > m_nBufSizeForSaveImage)
            {
                m_nBufSizeForSaveImage = 3 * pFrameInfo.nFrameLen + 2048;
                m_pBufForSaveImage     = new byte[m_nBufSizeForSaveImage];
            }

            IntPtr pImage = Marshal.UnsafeAddrOfPinnedArrayElement(m_pBufForSaveImage, 0);

            MyCamera.MV_SAVE_IMAGE_PARAM stSaveParam = new MyCamera.MV_SAVE_IMAGE_PARAM();
            stSaveParam.enImageType  = MyCamera.MV_SAVE_IAMGE_TYPE.MV_Image_Bmp;
            stSaveParam.enPixelType  = pFrameInfo.enPixelType;
            stSaveParam.pData        = pData;
            stSaveParam.nDataLen     = pFrameInfo.nFrameLen;
            stSaveParam.nHeight      = pFrameInfo.nHeight;
            stSaveParam.nWidth       = pFrameInfo.nWidth;
            stSaveParam.pImageBuffer = pImage;
            stSaveParam.nBufferSize  = m_nBufSizeForSaveImage;
            stSaveParam.nImageLen    = 0;
            int nRet = m_pOperator.SaveImage(ref stSaveParam);

            MemoryStream ms = new MemoryStream();                        //新建内存流

            ms.Write(m_pBufForSaveImage, 0, (int)stSaveParam.nImageLen); //附值

            this.Dispatcher.Invoke(DispatcherPriority.Normal,
                                   (ThreadStart) delegate()
            {
                image_Camera.Source = imageSourceConverter.ConvertFrom(ms) as BitmapFrame;
                GC.Collect(); //强制回收资源
            }
                                   );

            Thread.Sleep(500);   //这个延时可以让UI的响应更为流畅,但是图片的刷新较慢,打印的事件lTime在40ms内
        }
Пример #21
0
        // 이미지 받아서 처리
        private void imageReceive(string id, byte[] image)
        {
            using (MemoryStream inStream = new MemoryStream(image, 14, image.Length - 14))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    Image tempImage = Image.FromStream(inStream);
                    tempImage.Save(outStream, ImageFormat.Jpeg);
                    tempImage.Dispose();

                    string userId     = id.Replace("&", string.Empty).Trim();
                    string collection = imageList.Find(e => e.Contains(userId)).Split('/')[1];

                    ImageSourceConverter c = new ImageSourceConverter();

                    if (collection == CollectionName.UserImage.ToString())
                    {
                        UserImage = (ImageSource)c.ConvertFrom(outStream.ToArray());
                        changed("userImage");
                    }

                    else if (collection == CollectionName.friendsList.ToString())
                    {
                        friendsList.FirstOrDefault(e => e.friendsName == userId).friendsImage = (ImageSource)c.ConvertFrom(outStream.ToArray());
                        changed("friendsList");
                    }

                    else if (collection == CollectionName.chatRoomList.ToString())
                    {
                        chatRoomsList.FirstOrDefault(e => e.roomName == userId).roomImage = (ImageSource)c.ConvertFrom(outStream.ToArray());
                        changed("chatRoomsList");
                    }

                    imageList.Remove(userId + "/" + collection);
                }
            }
        }
Пример #22
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            BitmapSource bitmapSource = null;

            var uri = value as Uri;

            if (uri != null)
            {
                var imageSourceConverter = new ImageSourceConverter();
                var imageSource          = imageSourceConverter.ConvertFrom(uri);
                bitmapSource = imageSource as BitmapSource;
            }

            if (bitmapSource == null)
            {
                bitmapSource = value as BitmapSource;
            }
            if (bitmapSource != null)
            {
                var converter = GetConverter(bitmapSource.Format);
                return(converter.Convert(bitmapSource));
            }
            return(value);
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value != null)
     {
         Bitmap bi = null;
         var    imageSourceConverter = new ImageSourceConverter();
         using (var memoryStream = new MemoryStream())
         {
             bi.Save(memoryStream, ImageFormat.Png);
             var snapshotBytes = memoryStream.ToArray();
             return((ImageSource)imageSourceConverter.ConvertFrom(snapshotBytes));
         }
     }
     //BitmapImage bi = new BitmapImage();
     //bi.BeginInit();
     //MemoryStream ms = new MemoryStream();
     //Bitmap bitmap = value as Bitmap;
     //bitmap.Save(ms, ImageFormat.Bmp);
     //ms.Seek(0, SeekOrigin.Begin);
     //bi.StreamSource = ms;
     //bi.EndInit();
     //return bi;
     return(null);
 }
        private void RefreshImage(int index)
        {
            if (index < 0 || index >= m_scenario.ImageN)
            {
                return;
            }
            m_index = index;
            Logging.Assert(m_index >= 0 && m_index < m_scenario.ImageN);
            int key = -1;

            if (Config.Parameter.SaveMemory)
            {
                var image = m_scenario.ImageBytes(m_index);
                ctlImage.Source = imageSourceConverter.ConvertFrom(new MemoryStream(image.Value)) as ImageSource;
                key             = image.Key;
            }
            else
            {
                var image = m_scenario.Image(m_index);
                ctlImage.Source = image.Value;
                key             = image.Key;
            }
            ctlIndexLabel.Content = "T/C " + key + "/" + m_index;
        }
Пример #25
0
        public MainWindow()
        {
            InitializeComponent();


            bool isFirst;

            mtx = new System.Threading.Mutex
                      (true, "zjdd ", out isFirst);

            #region Background color
            this.Background              = new SolidColorBrush(Color.FromRgb(188, 99, 163));
            this.mainPanel.Background    = this.Background;
            this.fileListView.Background = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            this.about.Background        = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            this.lrcBox.Background       = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            this.lrcList.Background      = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            this.directoryTreeView.TreeViewBackground = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            #endregion

            #region Initialize directory treeview contexmenu
            dirViewContextMenu = new ContextMenu();
            MenuItem menu = new MenuItem();
            menu.Header = "Add This Folder";
            menu.Click += new RoutedEventHandler(menu_Click);
            dirViewContextMenu.Items.Add(menu);
            MenuItem open = new MenuItem();
            open.Header = "Open Folder in Windows Explorer";
            open.Click += new RoutedEventHandler(open_Click);
            dirViewContextMenu.Items.Add(open);
            MenuItem properties = new MenuItem();
            properties.Header = "Properties";
            properties.Click += new RoutedEventHandler(properties_Click);
            dirViewContextMenu.Items.Add(properties);
            this.directoryTreeView.TreeViewContextMenu = dirViewContextMenu;
            #endregion

            #region Initialize mainwindow icon
            defaultPath = Settings.Settings.Default.lrcDirectory;//
            if ("" == defaultPath.Trim())
            {
                defaultPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ZDLRC\\";
                Settings.Settings.Default.lrcDirectory = defaultPath;
            }
            MemoryStream stream = new MemoryStream();
            Properties.Resources.lrc.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
            this.Icon = (ImageSource)imageSourceConverter.ConvertFrom(stream);



            Image image = new Image();
            image.Source = ImageHelper.ToBitmapSource(Properties.Resources.lrc);
            image.Height = image.Width = 64;


            #endregion

            #region delegate and thread
            fileList                             = new List <MusicFile>();
            lrcDownload                          = new LRCDownload();
            updateStatus                         = new UpdateStatus(UpdateSearchStatus);
            addLrcSelect                         = new AddLrcSelect(AddSearchLrc);
            addLrc                               = new AddLrc(AddDownloadLRC);
            failedList                           = new List <MusicFile>();
            searchLrcByZLP                       = new SearchLrcByZPL(SearchFromZLP);
            listViewFileList                     = new List <MusicFile>();
            fileList                             = new List <MusicFile>();
            lrcDownload                          = new LRCDownload();
            selectLRCBase                        = new LRCBase();
            scanComplete                         = new ScanComplete(ScanFinish);
            addFileToListView                    = new AddFileToListView(UpdateScanResult);
            backgroundWorker                     = new BackgroundWorker();
            backgroundWorker.DoWork             += new DoWorkEventHandler(backgroundWorker_DoWork);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
            #endregion

            #region Initialize aboutBox and load settings
            autoSelect.IsChecked = Settings.Settings.Default.autoSave;

            about.AppendText("LRC Download 1.0.0.1\n\n");
            about.AppendText("This is a free soft made by ZJ.\n");
            about.AppendText("If you have questions,please send me email:[email protected].\n");
            about.AppendText("Copyright© 2010-2012 of ZJSoft\n");
            new InlineUIContainer(image, about.Document.ContentEnd);
            #endregion

            #region Initialize lrcBox contexmenu
            InitLrcBoxContextMenu();
            #endregion

            #region Initialize fileListViewContextmenu
            fileListViewContextMenu = new ContextMenu();
            MenuItem clear = new MenuItem();
            clear.Header = "Remove All Files";
            clear.Click += new RoutedEventHandler(clear_Click);
            fileListViewContextMenu.Items.Add(clear);
            fileListViewContextMenu.Opened += new RoutedEventHandler(fileListViewContextMenu_Opened);
            fileListView.ContextMenu        = fileListViewContextMenu;
            #endregion

            ps    = new PipeServer(this);
            psSer = new Thread(new ThreadStart(ps.StartPipeServer));
            psSer.Start();
            //MessageBox.Show(App.args);
            if (!String.IsNullOrEmpty(App.args))
            {
                string[] pas = App.args.Split('|');
                if (pas.Length >= 3)
                {
                    if (pas[0].Trim() == "0xFFFF")
                    {
                        pas[0] = "";
                    }
                    if (pas[1].Trim() == "0xFFFF")
                    {
                        pas[1] = "";
                    }

                    SearchFromZLP(pas[0], pas[1], pas[2]);
                }
            }
        }
Пример #26
0
        public ImageSource imageSourceForImageControl(Bitmap yourBitmap)
        {
            ImageSourceConverter c = new ImageSourceConverter();

            return((ImageSource)c.ConvertFrom(yourBitmap));
        }
Пример #27
0
        private void doMessage(typedata income)
        {
            //Util.logTime();
            if (income.command == "usrdata")
            {
                for (int i = 0; i < income.data.Length; i++)
                {
                    OnePeople onee = new OnePeople(this);
                    onee         = (OnePeople)primeJSON.DeserializeObject(income.data[i], typeof(OnePeople));
                    map[onee.id] = onee;
                    if (onee.id == this.login)
                    {
                        this.win.Dispatcher.Invoke(new Action(() => {
                            ImageSourceConverter conv   = new ImageSourceConverter();
                            this.win.imgInfoPict.Source = (ImageSource)conv.ConvertFrom(onee.Pict);
                            this.win.lbInfoId.Content   = onee.id;
                        }));
                    }
                }
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    foreach (oneChat item in this.win.chates)
                    {
                        item.updateIcon(this);
                    }
                    foreach (OneUser item in this.win.users)
                    {
                        item.updateIcons(this);
                    }
                    foreach (oneMsg item in this.win.msges)
                    {
                        item.updateIcons(this);
                    }
                    foreach (OnePeople item in this.win.friends)
                    {
                        item.updateIcons(this);
                    }
                }));
            }
            else
            if (income.command == "answ")
            {
                if (income.data[0] == "no")
                {
                    Console.Write("\tWhoops! ");
                    if (income.data.Length > 1)
                    {
                        Console.WriteLine(income.data[1]);
                    }
                }
                else if (income.data[0] == "yes")
                {
                    Console.WriteLine("\tAccept!");
                    if (income.msg == "authuser")
                    {
                        this.authorized   = true;
                        this.currentGroup = "none";
                        authComplete();
                    }
                    else if (income.msg == "enduser")
                    {
                        this.authorized   = false;
                        this.currentGroup = "none";
                    }
                    else if (income.msg == "leavegr")
                    {
                        //this.currentGroup = "none";
                        this.win.Dispatcher.Invoke(new Action(() => {
                            oneChat pos = null;
                            foreach (oneChat item in this.win.chatsList.Items)
                            {
                                if (item.id == this.currentGroup)
                                {
                                    pos = item;
                                    break;
                                }
                            }
                            //this.win.chatsList.Items.Remove(pos);
                            this.win.chates.Remove(pos);
                            authComplete();
                            this.win.msges.Clear();
                        }));
                    }
                    else if (income.msg == "makegr")
                    {
                    }
                }
            }
            else
            if (income.command == "switch")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.win.tabcontroll.SelectedIndex = 1;
                    foreach (oneChat item in this.win.chates)
                    {
                        if (item.id == income.target)
                        {
                            this.win.chatsList.SelectedItem = item;
                            break;
                        }
                    }
                }));
            }

            else
            if (income.command == "upddata")
            {
                if (income.msg == "sendgru")
                {
                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        oneChat selectedd = (oneChat)this.win.chatsList.SelectedItem;

                        this.listOfChates.Clear();
                        for (int i = 0; i < income.data.Length; i++)
                        {
                            typegetdata getdata = new typegetdata();
                            getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                            oneChat newchat     = new oneChat(getdata.name, this.login, this);
                            getdata.display();

                            this.listOfChates.Add(newchat);
                        }
                        if (selectedd != null)
                        {
                            if (this.listOfChates.IndexOf(selectedd) == -1)
                            {
                                this.win.chatsList.SelectedIndex = -1;
                            }
                        }
                    }

                                                          ));
                }
                else if (income.msg == "sendugr")
                {
                    if (income.target == currentGroup)
                    {
                        this.win.Dispatcher.Invoke(new Action(() =>
                        {
                            this.win.users.Clear();
                            for (int i = 0; i < income.data.Length; i++)
                            {
                                typegetdata getdata = new typegetdata();
                                getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                                OneUser us          = new OneUser(getdata.name, this);
                                if ((i == 0 && us.id == this.login) || (i > 0 && this.win.users[0].id == this.login))
                                {
                                    this.win.btnLeaveChat.Content = "Delete chat";
                                    us.isMaker = true;
                                }
                                else
                                {
                                    us.isMaker = false;
                                    this.win.btnLeaveChat.Content = "Leave chat";
                                }
                                this.win.users.Add(us);
                            }
                        }));
                    }
                }
                else if (income.msg == "sendgruws")
                {
                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        this.listOfChates.Clear();
                        for (int i = 0; i < income.data.Length; i++)
                        {
                            typegetdata getdata = new typegetdata();
                            getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                            oneChat newchat     = new oneChat(getdata.name, this.login, this);
                            getdata.display();

                            this.listOfChates.Add(newchat);
                        }

                        this.win.tabcontroll.SelectedIndex = 1;
                        foreach (oneChat item in this.win.chates)
                        {
                            if (item.id == income.target)
                            {
                                this.win.chatsList.SelectedItem = item;
                                break;
                            }
                        }
                    }
                                                          ));
                }
            }
            else
            if (income.command == "updmsg")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.listOfMsg.Clear();
                    for (int i = 0; i < income.data.Length; i++)
                    {
                        typemsg tmsg  = new typemsg();
                        tmsg          = (typemsg)primeJSON.DeserializeObject(income.data[i], tmsg.GetType());
                        oneMsg newmsg = new oneMsg(tmsg.from, tmsg.msg, tmsg.time, this.login, this);

                        this.listOfMsg.Add(newmsg);

                        //win.msges.
                        //tmsg.display();
                    }
                    if (this.win.msgsList.Items.Count > 0)
                    {
                        this.win.msgsList.ScrollIntoView(this.win.msgsList.Items[this.win.msgsList.Items.Count - 1]);
                    }
                }));
            }
            else
            if (income.command == "notification")
            {
                if (income.data[0] == "newmsg")
                // Console.WriteLine($"\t\t{income.msg}");
                {
                    //MessageBox.Show(income.msg, "notification", MessageBoxButtons.OK);
                    if (income.msg == currentGroup)
                    {
                        _sendRefreshMsg(null);
                    }
                    else
                    {
                        this.win.Dispatcher.Invoke(new Action(() =>
                        {
                            int index = -1;
                            for (int i = 0; i < this.win.chates.Count; i++)
                            {
                                if (this.win.chates[i].id == income.msg)
                                {
                                    index = i;
                                }
                            }
                            if (index != -1)
                            {
                                this.win.chates[index].isNotRead = true;
                            }
                        }));
                    }

                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        int ind    = -1;
                        object sel = this.win.chatsList.SelectedItem;
                        for (int i = 0; i < this.win.chates.Count; i++)
                        {
                            if (this.win.chates[i].id == income.msg)
                            {
                                ind = i;
                            }
                        }
                        if (ind != -1)
                        {
                            oneChat forSwap = this.win.chates[ind];
                            this.win.chates.Remove(forSwap);
                            this.win.chates.Insert(0, forSwap);
                            this.win.chatsList.SelectedItem = sel;
                        }
                    }));
                }
                else if (income.data[0] == "updateusers")
                {
                    if (income.msg == currentGroup)
                    {
                        _updateUsersInCurrent();
                    }
                }
                //income.display();
            }
            else
            if (income.command == "friends")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.win.friends.Clear();

                    for (int i = 0; i < income.data.Length; i++)
                    {
                        OnePeople onee = new OnePeople(this);
                        onee           = (OnePeople)primeJSON.DeserializeObject(income.data[i], typeof(OnePeople));
                        this.win.friends.Add(onee);
                    }
                }));
            }
            //income.display();
            //Console.ReadKey();
        }
Пример #28
0
 public FolderItem()
     : base()
 {
     ImageSourceConverter isc = new ImageSourceConverter();
     Image = isc.ConvertFrom("openfolderHS.png") as ImageSource;
 }
Пример #29
0
        public static void CreateSlideList(StackPanel sSlideList, string strFolderPath, ZYPSlice zypSlide, CancellationTokenSource ctsSource, ResourceDictionary rdDirectory, string strCurrentSlidePath)
        {
            ArrayList slideFileList = GetSlideFileList(strFolderPath, ".zyp");

            if (slideFileList.Count != 0)
            {
                foreach (string item in slideFileList)
                {
                    SlideListItem slideListItem = new SlideListItem();
                    slideListItem.strFileName = item;
                    MemoryStream thumbnail = zypSlide.GetThumbnail(item);
                    MemoryStream label     = zypSlide.GetLabel(item);
                    if (thumbnail != null && label != null)
                    {
                        ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                        slideListItem.imgSourceThumbnail = (ImageSource)imageSourceConverter.ConvertFrom(thumbnail);
                        slideListItem.imgSourceLabel     = (ImageSource)imageSourceConverter.ConvertFrom(label);
                        if (slideListItem != null)
                        {
                            int    count  = sSlideList.Children.Count;
                            Border border = new Border();
                            border.SetValue(FrameworkElement.StyleProperty, rdDirectory["SlideListItemBorder"]);
                            border.DataContext = slideListItem.strFileName;
                            Canvas canvas  = new Canvas();
                            Border border2 = new Border();
                            border2.SetValue(FrameworkElement.StyleProperty, rdDirectory["SlideListItemThumbnailBorder"]);
                            border2.RenderTransform = new RotateTransform(-90.0);
                            Image image = new Image();
                            image.SetValue(FrameworkElement.StyleProperty, rdDirectory["SlideListItemThumbnail"]);
                            image.Source = slideListItem.imgSourceThumbnail;
                            RotateTransform rotateTransform = new RotateTransform();
                            rotateTransform.Angle   = 180.0;
                            rotateTransform.CenterX = 47.5;
                            rotateTransform.CenterY = 100.0;
                            image.RenderTransform   = rotateTransform;
                            border2.Child           = image;
                            Image image2 = new Image();
                            image2.SetValue(FrameworkElement.StyleProperty, rdDirectory["SlideListItemLabel"]);
                            image2.Source = slideListItem.imgSourceLabel;
                            Label label2 = new Label();
                            label2.SetValue(FrameworkElement.StyleProperty, rdDirectory["SlideListItemSlideName"]);
                            label2.Content = Path.GetFileNameWithoutExtension(slideListItem.strFileName);
                            if (strCurrentSlidePath == slideListItem.strFileName)
                            {
                                border.BorderBrush = new SolidColorBrush(Color.FromRgb(57, 176, 181));
                                int num = (count - 1) * 130 + count * 10;
                                (sSlideList.Parent as ScrollViewer).ScrollToVerticalOffset(num - 10);
                            }
                            else
                            {
                                border.BorderBrush = Brushes.Gray;
                            }
                            canvas.Children.Add(border2);
                            canvas.Children.Add(image2);
                            canvas.Children.Add(label2);
                            border.Child = canvas;
                            if (ctsSource.IsCancellationRequested)
                            {
                                break;
                            }
                            sSlideList.Children.Add(border);
                        }
                    }
                }
            }
        }
        public void CreateQRCode(byte[] qrbytes)
        {
            ImageSourceConverter converter = new ImageSourceConverter();

            _qrCodeImage.Source = (ImageSource)converter.ConvertFrom(qrbytes);
        }