void onLoadTextureFromFile(Image source, SlootEnum sloot, int index, string file) { byte[] _bytes = TMImageHelper.FromFile(file, true); switch (sloot) { case SlootEnum.Texture: { creature.dirs[DirIndex].sprites[SpriteIndex].textures[index] = _bytes; if (creature.dirs[DirIndex].sprites[SpriteIndex].textures[index] != null) { source.Source = creature.dirs[DirIndex].sprites[SpriteIndex].textures[index].ToImage(); } } break; case SlootEnum.Mask: { creature.dirs[DirIndex].sprites[SpriteIndex].masks[index] = _bytes; if (creature.dirs[DirIndex].sprites[SpriteIndex].masks[index] != null) { source.Source = creature.dirs[DirIndex].sprites[SpriteIndex].masks[index].ToImage(); } } break; } }
private void InsertPictureFromClipboard(object param) { try { if (Clipboard.ContainsImage()) { var imageTags = new StringBuilder(); var bmp = Clipboard.GetImage(); using (var img = TMImageHelper.ToBitmap(bmp)) { using (var newImg = TMImageHelper.ResizeImage(img, 512)) { using (var temp = new MemoryStream()) { newImg.Save(temp, ImageFormat.Jpeg); imageTags.AppendFormat("{{bild}}data:image/jpeg;base64,{0}{{/bild}}", Convert.ToBase64String(temp.ToArray())); } } } this.OnInsertText(imageTags.ToString()); } else { //TODO } } catch { //TODO } }
private void InsertPictures(object param) { try { var dialog = new OpenFileDialog(); dialog.Filter = "Alle Bilder|*.png;*.gif;*.bmp;*.jpg;*.jpeg;*.psd|Alle Dateien (*.*)|*.*"; dialog.Multiselect = true; if (dialog.ShowDialog() != true) { return; } var imageTags = new StringBuilder(); foreach (var file in dialog.FileNames .Select(p => new FileInfo(p)) .Where(f => f.Exists)) { try { using (var stream = file.OpenRead()) { using (var img = TMImageHelper.LoadBitmap(stream)) { using (var newImg = TMImageHelper.ResizeImage(img, 512)) { using (var temp = new MemoryStream()) { newImg.Save(temp, ImageFormat.Jpeg); imageTags.AppendFormat("{{bild}}data:image/jpeg;base64,{0}{{/bild}}", Convert.ToBase64String(temp.ToArray())); } } } } } catch { //TODO } } this.OnInsertText(imageTags.ToString()); } catch { //TODO } }