Esempio n. 1
0
        public static ImageListOptions ReadImageData(byte[] imageData)
        {
            var imageList = new ImageList();
            var info      = new SerializationInfo(typeof(ImageListStreamer), new FormatterConverter());

            info.AddValue("Data", imageData);
            var ctor     = typeof(ImageListStreamer).GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(SerializationInfo), typeof(StreamingContext) }, null);
            var streamer = (ImageListStreamer)ctor.Invoke(new object[] { info, new StreamingContext(StreamingContextStates.All) });

            imageList.ImageStream = streamer;

            var opts = new ImageListOptions();

            opts.ColorDepth       = imageList.ColorDepth;
            opts.ImageSize        = imageList.ImageSize;
            opts.TransparentColor = imageList.TransparentColor;

            for (int i = 0; i < imageList.Images.Count; i++)
            {
                var bitmap = imageList.Images[i];
                var stream = new MemoryStream();
                bitmap.Save(stream, ImageFormat.Bmp);
                opts.ImageSources.Add(ImageResourceUtils.CreateImageSource(stream.ToArray()));
            }

            return(opts);
        }
Esempio n. 2
0
        public static ResourceElement Serialize(ImageListOptions opts)
        {
            var imgList = new ImageList();

            imgList.ColorDepth       = opts.ColorDepth;
            imgList.ImageSize        = opts.ImageSize;
            imgList.TransparentColor = opts.TransparentColor;

            foreach (var imageSource in opts.ImageSources)
            {
                var bitmapSource = imageSource as BitmapSource;
                if (bitmapSource == null)
                {
                    throw new InvalidOperationException("Only BitmapSources can be used");
                }
                var encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
                var outStream = new MemoryStream();
                encoder.Save(outStream);
                outStream.Position = 0;
                var wfBmp = new System.Drawing.Bitmap(outStream);
                imgList.Images.Add(wfBmp);
            }

            var obj = imgList.ImageStream;

            return(new ResourceElement {
                Name = opts.Name,
                ResourceData = new BinaryResourceData(new UserResourceType(obj.GetType().AssemblyQualifiedName, ResourceTypeCode.UserTypes), SerializationUtils.Serialize(obj)),
            });
        }
Esempio n. 3
0
		void InitializeFrom(ImageListOptions options) {
			Name = options.Name;
			HeightVM.Value = options.ImageSize.Height;
			WidthVM.Value = options.ImageSize.Width;
			TransparentColorVM.Value = options.TransparentColor;
			ColorDepthVM.SelectedItem = options.ColorDepth;
			ImageListStreamerVM.InitializeFrom(options.ImageSources);
		}
Esempio n. 4
0
		public ImageListVM(ImageListOptions options) {
			origOptions = options;

			ImageListStreamerVM = new ImageListStreamerVM();
			ImageListStreamerVM.Collection.CollectionChanged += (s, e) => HasErrorUpdated();
			WidthVM = new Int32VM(a => HasErrorUpdated(), true) {
				Min = 1,
				Max = 256,
			};
			HeightVM = new Int32VM(a => HasErrorUpdated(), true) {
				Min = 1,
				Max = 256,
			};
			TransparentColorVM = new DefaultConverterVM<Color>(a => HasErrorUpdated());

			Reinitialize();
		}
Esempio n. 5
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var imgNode = (ISerializedImageListStreamerResourceElementNode)nodes[0];
			var options = new ImageListOptions(imgNode.ImageListOptions);
			var data = new ImageListVM(options);
			var win = new ImageListDlg();
			win.Title = dnSpy_AsmEditor_Resources.EditResourceCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var listOpts = data.CreateImageListOptions();

			if (listOpts.ImageSources.Count == 0) {
				Shared.App.MsgBox.Instance.Show(dnSpy_AsmEditor_Resources.Error_EmptyImageList);
				return;
			}

			ResourceElementOptions opts = null;
			string error;
			try {
				opts = new ResourceElementOptions(SerializedImageListStreamerUtils.Serialize(listOpts));
				error = imgNode.CheckCanUpdateData(opts.Create());
			}
			catch (Exception ex) {
				error = string.Format(dnSpy_AsmEditor_Resources.Error_CouldNotSerializeImages, ex.Message);
			}
			if (!string.IsNullOrEmpty(error)) {
				Shared.App.MsgBox.Instance.Show(error);
				return;
			}

			undoCommandManager.Value.Add(new SerializedImageListStreamerResourceElementSettingsCommand(imgNode, opts));
		}
 /// <inheritdoc cref="ComputeService.ListImagesAsync" />
 public static IPage <Image> ListImages(this ComputeService service, ImageListOptions options = null)
 {
     return(service.ListImagesAsync(options).ForceSynchronous());
 }
Esempio n. 7
0
 void InitializeImageData(byte[] imageData)
 {
     this.imageListOptions = SerializedImageListStreamerUtils.ReadImageData(imageData);
     this.imageData        = imageData;
 }
Esempio n. 8
0
		ImageListOptions CopyTo(ImageListOptions options) {
			options.Name = Name;
			options.ImageSize = new Size(WidthVM.Value, HeightVM.Value);
			options.TransparentColor = TransparentColorVM.Value;
			options.ColorDepth = (ColorDepth)ColorDepthVM.SelectedItem;
			options.ImageSources.Clear();
			options.ImageSources.AddRange(ImageListStreamerVM.Collection.Select(a => a.ImageSource));
			return options;
		}
 void InitializeImageData(byte[] imageData)
 {
     this.imageListOptions = ReadImageData(imageData);
     this.imageData        = imageData;
 }
 /// <inheritdoc cref="ComputeService.ListImagesAsync" />
 public static IPage<Image> ListImages(this ComputeService service, ImageListOptions options = null)
 {
     return service.ListImagesAsync(options).ForceSynchronous();
 }