private void FromClipboardButton_Click(object sender, EventArgs e) { try { IDataObject id = Clipboard.GetDataObject(); string[] formats; if (id != null) { formats = id.GetFormats(); } System.Drawing.Image clipboardImage = null; if (Clipboard.ContainsImage()) { clipboardImage = Clipboard.GetImage(); MaskItem item = new MaskItem(); item.mMask = Masking.CreateMask(clipboardImage); MaskCheckList.Items.Add(item, false); Masking.setCurrSelectionMaskWeights(item.mMask.Clone()); } } catch { MessageBox.Show("Error importing image from clipboard. Image must be 24bpp RGB"); } }
private void ImportMaskButton_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "Image (*.bmp)|*.bmp|Raw32 (*.r32)|*.r32"; if (d.ShowDialog() == DialogResult.OK) { string tName = Path.GetFileNameWithoutExtension(d.FileName); bool okToLoad = true; for (int i = 0; i < MaskCheckList.Items.Count; i++) { MaskItem mi = MaskCheckList.Items[i] as MaskItem; if (Path.GetFileNameWithoutExtension(mi.Name) == tName) { if (MessageBox.Show("There exists a similar mask name already loaded. Would you still like to import this mask?", "Warning!", MessageBoxButtons.YesNo) != DialogResult.Yes) { okToLoad = false; } break; } } if (!okToLoad) { return; } if (Path.GetExtension(d.FileName.ToLower()) == ".bmp") { Image loadedImage = Masking.GetScaledImageFromFile(d.FileName, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts()); MaskItem item = new MaskItem(); item.Name = Path.GetFileName(d.FileName); item.mMask = Masking.CreateMask(loadedImage); MaskCheckList.Items.Add(item, false); Masking.setCurrSelectionMaskWeights(item.mMask.Clone()); } else if (Path.GetExtension(d.FileName.ToLower()) == ".r32") { MaskItem item = new MaskItem(); item.Name = Path.GetFileName(d.FileName); item.mMask = MaskFactory.GetNewMask(); BinaryReader r = new BinaryReader(File.OpenRead(d.FileName)); long index = 0; try { while (true) { item.mMask.SetMaskWeight(index, r.ReadSingle()); index++; } } catch (System.IO.EndOfStreamException ex) { ex.ToString(); } if (scaleToFitCheckbox.Checked) { //rescale this mask to fit current terrain int numX = (int)Math.Sqrt(index); float[] img = new float[numX * numX]; long id; float value; item.mMask.ResetIterator(); while (item.mMask.MoveNext(out id, out value)) { if (value == 0) { continue; } img[id] = value; } int newWidth = TerrainGlobals.getTerrain().getNumXVerts(); float[] outImg = ImageManipulation.resizeF32Img(img, numX, numX, newWidth, newWidth, ImageManipulation.eFilterType.cFilter_Linear); item.mMask.Clear(); for (index = 0; index < newWidth * newWidth; index++) { item.mMask.SetMaskWeight(index, outImg[index]); } } MaskCheckList.Items.Add(item, false); Masking.setCurrSelectionMaskWeights(item.mMask.Clone()); r.Close(); } } //ImageSourcePicker picker = new ImageSourcePicker(); //picker.ImageSelected += new EventHandler(picker_ImageSelected); //PopupEditor editor = new PopupEditor(); //editor.ShowPopup(this, picker); }