public void calculateDistanceImage(object sender, RoutedEventArgs e) { if (Clipboard.ContainsImage()) { var btn = sender as Button; String code = btn.Tag.ToString(); System.Windows.Media.Imaging.BitmapSource imageClipboard = Clipboard.GetImage(); Bitmap image = getBitmapFromSource(imageClipboard); if (code.Equals("1")) { changeOreDistText(dist1, image, true); } if (code.Equals("2")) { changeOreDistText(dist2, image, true); } if (code.Equals("3")) { changeOreDistText(dist3, image, true); } if (code.Equals("4")) { changeOreDistText(dist4, image, true); } } else { MessageBox.Show("You need to have screenshot in clipboard!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static System.Windows.Media.Imaging.BitmapSource GetBitmapSource(System.Drawing.Color color1, System.Drawing.Color color2) { string sColorKey = color1.ToArgb().ToString() + "_" + color2.ToArgb().ToString(); if (_cacheBitmapSource.ContainsKey(sColorKey)) { return(_cacheBitmapSource[sColorKey]); } int width = 32; int height = 32; int stride = width * 4 + (width % 4); byte[] bits = new byte[height * stride]; for (int i = 0; i < width; i++) { for (int j = height - 1 - i; j > -1; j--) { if (i <= j) { setpixel(ref bits, i, j, stride, color1); } else { setpixel(ref bits, i, j, stride, color2); } } } System.Windows.Media.Imaging.BitmapSource bs = System.Windows.Media.Imaging.BitmapSource.Create(width, height, 300, 300, System.Windows.Media.PixelFormats.Pbgra32, null, bits, stride); _cacheBitmapSource.Add(sColorKey, bs); return(bs); }
public static System.Windows.Media.Imaging.BitmapSource OpenCVLibraryToBitmapSource(OpenCvSharp.Mat mat) { System.Windows.Media.Imaging.BitmapSource source = mat.ToWriteableBitmap(); source.Freeze(); DeleteObject(mat.CvPtr); return(source); //return OpenCvSharp.Extensions.BitmapSourceConverter.ToBitmapSource(mat); }
public static OpenCvSharp.Mat BitmapSourceToOpenCvSharpMat(System.Windows.Media.Imaging.BitmapSource source) { OpenCvSharp.Mat mat = source.ToMat(); source.Freeze(); source = null; return(mat); //return OpenCvSharp.Extensions.BitmapSourceConverter.ToMat(source); }
private System.Windows.Media.Imaging.BitmapSource GetImage(IntPtr bm) { System.Windows.Media.Imaging.BitmapSource bmSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bm, IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); return(bmSource); }
// Helper function to generate an Image from a BitmapSource private static System.Drawing.Image ImageSourceToGDI(System.Windows.Media.Imaging.BitmapSource src) { var ms = new MemoryStream(); var encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder(); encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(src)); encoder.Save(ms); ms.Flush(); return(System.Drawing.Image.FromStream(ms)); }
public static MemoryBitmap ToMemoryBitmap(WIC_READABLE src) { var binfo = src.GetBitmapInfo(); var dst = new MemoryBitmap(binfo); src.CopyPixels(dst.ToByteArray(), binfo.StepByteSize, 0); return(dst); }
public static System.Windows.Media.Imaging.BitmapSource GetBitmapSource(System.Drawing.Bitmap _image) { System.Drawing.Bitmap bitmap = _image; System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); return(bitmapSource); }
public static byte[] ToByteArray(this System.Windows.Media.Imaging.BitmapSource bitmapSource) { using (MemoryStream ms = new MemoryStream()) { var encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder(); encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapSource)); encoder.Save(ms); return(ms.ToArray()); } }
protected override void Execute(CodeActivityContext context) { string text = ""; System.Windows.Media.Imaging.BitmapSource image = null; int counter = 0; while (string.IsNullOrEmpty(text) && image == null) { counter++; try { System.Windows.IDataObject idat = null; Exception threadEx = null; System.Threading.Thread staThread = new System.Threading.Thread(() => { try { if (System.Windows.Clipboard.ContainsText()) { idat = System.Windows.Clipboard.GetDataObject(); text = (string)idat.GetData(typeof(string)); } if (System.Windows.Clipboard.ContainsImage()) { idat = System.Windows.Clipboard.GetDataObject(); image = System.Windows.Clipboard.GetImage(); // var tmp = System.Windows.Clipboard.GetImage(); // image = new ImageElement(tmp); //image = (System.Drawing.Image)idat.GetData(typeof(System.Drawing.Image)); } } catch (Exception ex) { threadEx = ex; } }); staThread.SetApartmentState(System.Threading.ApartmentState.STA); staThread.Start(); staThread.Join(); } catch (Exception ex) { Log.Debug(ex.Message); System.Threading.Thread.Sleep(250); } if (counter == 3) { break; } } context.SetValue(StringResult, text); context.SetValue(ImageResult, image); }
private System.Windows.Media.Imaging.BitmapSource GetBitmapSource(System.Drawing.Image image) { var bitmap = new Bitmap(image); System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); return(bitmapSource); }
public System.Windows.Media.Imaging.BitmapSource DoEffect(System.Windows.Media.Imaging.BitmapSource img, int?def) { ToonShaderEffect eff = new ToonShaderEffect(); if (!def.HasValue) { eff.Factor = contr.Factor; } return(img.UseEffect(eff)); }
public BillboardSingleImage3D(Media.Imaging.BitmapSource bitmapSource, Stream imageStream) : this(bitmapSource) { this.AlphaTexture = imageStream; using (Image image = Image.Load(imageStream)) { Width = Math.Max(this.Width, image.Description.Width); Height = Math.Max(this.Height, image.Description.Height); } AlphaTexture.Position = 0; }
//Hilfsmethode: transferiert ein Foto (Bitmap) in ein Byte-Array private static byte[] BitmapSourceToByte(System.Windows.Media.Imaging.BitmapSource source) { var encoder = new System.Windows.Media.Imaging.JpegBitmapEncoder(); var frame = System.Windows.Media.Imaging.BitmapFrame.Create(source); encoder.Frames.Add(frame); var stream = new MemoryStream(); encoder.Save(stream); return(stream.ToArray()); }
public TableWindow3D() { InitializeComponent(); //This serves as a transparent x,y Plane for Editor interaction //Geometry3D backDrop = new Geometry3D(); //Plane is just a tiny bit set off below the z=0 plane to avoid rendering and interaction overlapping problems m_BlackPlane.Content = HciLab.Utilities.Mash3D.Rectangle3DGeo.Rect(-1000.0, -1000.0, 2000.0, 2000.0, System.Windows.Media.Colors.Black, -0.05); double w = CalibrationManager.Instance.GetProjectionArea().Width; double h = CalibrationManager.Instance.GetProjectionArea().Height; m_Camera = new PerspectiveCamera( SettingsManager.Instance.Settings.SettingsTable.ProjCamPosition, SettingsManager.Instance.Settings.SettingsTable.ProjCamLookDirection, new Vector3D(0, 1, 0), SettingsManager.Instance.Settings.SettingsTable.ProjCamFOV); m_Viewport.Camera = m_Camera; m_Projection.Positions.Clear(); m_Projection.Positions.Add(new Point3D(0, 0, 0)); m_Projection.Positions.Add(new Point3D(w, 0, 0)); m_Projection.Positions.Add(new Point3D(w, h, 0)); m_Projection.Positions.Add(new Point3D(w, h, 0)); m_Projection.Positions.Add(new Point3D(0, h, 0)); m_Projection.Positions.Add(new Point3D(0, 0, 0)); if (ScreenManager.isSecondScreenConnected()) { System.Drawing.Rectangle projectorResolution = ScreenManager.getProjectorResolution(); Left = projectorResolution.Left; Top = projectorResolution.Top; Width = projectorResolution.Width; Height = projectorResolution.Height; } else { AllowsTransparency = false; Topmost = false; WindowStyle = System.Windows.WindowStyle.SingleBorderWindow; } AllowDrop = true; CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); m_CbImage = CalibrationManager.Instance.renderCheckerboard(32, 20, 1280, 800, 0, 0); m_CheckerBoardVisual = new ModelVisual3D(); m_CheckerBoardVisual.Content = HciLab.Utilities.Mash3D.Image3DGeo.Image(0.0, 0.0, 690.0, 430.0, m_CbImage, -0.01); CalibrationManager.Instance.changedCalibrationMode += new CalibrationManager.ChangedCalibrationModeHandler(Instance_changedCalibrationMode); this.InvalidateVisual(); }
//Need System.Windows DLL & PresentationCore DLL & PresentationFramework & System.xaml & System.windows.presentation private System.Drawing.Bitmap BitmapSourceToBitmap(System.Windows.Media.Imaging.BitmapSource bitmapsource) { System.Drawing.Bitmap bitmap; System.IO.MemoryStream outStream = new System.IO.MemoryStream(); System.Windows.Media.Imaging.BitmapEncoder enc = new System.Windows.Media.Imaging.BmpBitmapEncoder(); enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapsource)); enc.Save(outStream); bitmap = new System.Drawing.Bitmap(outStream); return(bitmap); }
/// <summary> /// BitmapSource(BitmapImage) 转换 System.Drawing.Bitmap /// </summary> /// <param name="bitmapSource">BitmapSource(BitmapImage) - WPF平台</param> /// <returns>System.Drawing.Bitmap</returns> public static Bitmap BitmapSource2Bitmap(System.Windows.Media.Imaging.BitmapSource bitmapSource) { using (System.IO.MemoryStream outStream = new System.IO.MemoryStream()) { var enc = new System.Windows.Media.Imaging.BmpBitmapEncoder(); enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapSource)); enc.Save(outStream); Bitmap bitmap = new Bitmap(outStream); return(new Bitmap(bitmap)); } }
/// <summary> /// 转换Bitmap到BitmapSource /// </summary> /// <param name="bmp"></param> /// <returns></returns> public static System.Windows.Media.Imaging.BitmapSource GetBitmapSource(System.Drawing.Bitmap bmp) { System.Windows.Media.Imaging.BitmapSource bmpf = null; using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); bmpf = System.Windows.Media.Imaging.BitmapFrame.Create(ms, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad); } return(bmpf); //return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); }
internal static Bitmap GetBitmap(System.Windows.Media.Imaging.BitmapSource source) { Bitmap bmp = new Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size); System.Drawing.Imaging.BitmapData data = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); source.CopyPixels(System.Windows.Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride); bmp.UnlockBits(data); return(bmp); }
public System.Windows.Media.Imaging.BitmapSource GetBitmapSource() { IntPtr ptr = show.Bitmap.GetHbitmap(); System.Windows.Media.Imaging.BitmapSource ret = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( ptr, IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); DeleteObject(ptr); return(ret); }
public static Bitmap ToBitmap(this Media.Imaging.BitmapSource source) { Bitmap bitmap; using (MemoryStream outStream = new MemoryStream()) { var enc = new Media.Imaging.PngBitmapEncoder(); enc.Frames.Add(Media.Imaging.BitmapFrame.Create(source)); enc.Save(outStream); bitmap = new Bitmap(outStream); } return(bitmap); }
public System.Windows.Media.Imaging.BitmapSource DoEffect(System.Windows.Media.Imaging.BitmapSource img, int?def) { ColorToneEffect eff = new ColorToneEffect(); if (!def.HasValue) { eff.DarkColor = contr.DarkColor; eff.LightColor = contr.LightColor; eff.Desaturation = contr.Desaturation; eff.Toned = contr.Tone; } return(img.UseEffect(eff)); }
private void WinCopy_Closed(object sender, EventArgs e) { try { System.Windows.Media.Imaging.BitmapSource bs = Clipboard.GetImage(); Image img = new Image(); img.Width = bs.Width; img.Height = bs.Height; img.Source = bs; new InlineUIContainer(img, rtb.Selection.End); //插入图片到选定位置 } catch (Exception ex) { } }
public System.Windows.Media.Imaging.BitmapSource CreateBarCodeBitmapSource(string txt, int scale) { string result = DoBarCode(txt, scale); IntPtr hBitmap = newBitmap.GetHbitmap(); System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); return(bitmapSource); }
void RealizeImageBrush(ImageBrush brush, ref XForm xform, ref XImage xImage) { //Debug.Assert(xform != null); //xform = new XForm(this.writer.Owner, new XRect(brush.Viewbox.X * 3 / 4, brush.Viewbox.Y * 3 / 4, brush.Viewbox.Width * 3 / 4, brush.Viewbox.Height * 3 / 4)); //string imageUri = brush.ImageSource; FixedPage fpage = brush.GetParent <FixedPage>(); if (fpage == null) { Debug.Assert(false); } FixedPayload payload = fpage.Document.Payload; // Get the font object. // Important: font.PdfFont is not yet defined here on the first call string uriString = brush.ImageSource; BitmapSource image = payload.GetImage(uriString); // int factor = 1; //int width = (int)(100 * factor); //int height = (int)(100 * factor); //DrawingVisual visual = new DrawingVisual(); //DrawingContext vdc = visual.RenderOpen(); //vdc.DrawRectangle(Brushes.GreenYellow, null, new Rect(0, 0, width, height)); //vdc.DrawLine(new Pen(Brushes.Red, 3), new Point(0, 0), new Point(100, 100)); //vdc.DrawLine(new Pen(Brushes.Red, 3), new Point(100, 0), new Point(0, 100)); //vdc.Close(); //RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 72 * factor, 72 * factor, PixelFormats.Default); //rtb.Render(visual); //BitmapImage bitmapImage = new BitmapImage( xImage = XImage.FromBitmapSource(image); //XGraphics gfx = XGraphics.FromForm(xform); //gfx.DrawRectangle(XBrushes.Firebrick, new XRect(0, 0, 100, 100)); //PdfContentWriter formWriter = new PdfContentWriter(xform, RenderMode.Default); ////formWriter.Size = brush.Viewport.Size; //formWriter.BeginContent(false); ////formWriter.WriteElement(visual); //formWriter.EndContent(); }
static byte[] GetBytesFromBitmapSource(System.Windows.Media.Imaging.BitmapSource bmp) { System.Windows.Media.Imaging.PngBitmapEncoder encoder = new System.Windows.Media.Imaging.PngBitmapEncoder(); //encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); // byte[] bit = new byte[0]; using (MemoryStream stream = new MemoryStream()) { encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bmp)); encoder.Save(stream); byte[] bit = stream.ToArray(); stream.Close(); return(bit); } }
/// <summary> /// Converts a Gdi <see cref="System.Drawing.Image"/> into a Wpf <see cref="System.Windows.Media.Imaging.BitmapSource"/>. /// For this, the Gdi image is converted into a Gdi bitmap, and then converted to a Wpf BitmapSource. /// </summary> /// <param name="gdiImage">The Gdi image to convert.</param> /// <returns>A Wpf <see cref="System.Windows.Media.Imaging.BitmapSource"/>.</returns> public static System.Windows.Media.Imaging.BitmapSource ToBitmapSource(this System.Drawing.Image gdiImage) { if (null == gdiImage) { throw new ArgumentNullException(nameof(gdiImage)); } System.Windows.Media.Imaging.BitmapSource wpfBitmapSource = null; using (var gdiBitmap = new System.Drawing.Bitmap(gdiImage)) { wpfBitmapSource = gdiBitmap.ToBitmapSource(); } return(wpfBitmapSource); }
public MessageBox(string sTitle, string sMsg, bool bShowCancel = true) { InitializeComponent(); IntPtr pIcon = Properties.Resources.X.ToBitmap().GetHbitmap(); System.Windows.Media.Imaging.BitmapSource pBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(pIcon, IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); this.Icon = pBitmap; this.Title = sTitle; btnCancel.Visibility = bShowCancel ? Visibility.Visible : Visibility.Collapsed; tbMsg.Inlines.Clear(); tbMsg.Text = sMsg; }
/// <summary> /// Graba una imagen del clipBoard en un archivo /// </summary> private void SaveClipboardImageToFile(string fileName) { System.Windows.Media.Imaging.BitmapSource image = System.Windows.Clipboard.GetImage(); // Graba la imagen using (FileStream stmFile = new FileStream(fileName, FileMode.Create)) { System.Windows.Media.Imaging.BitmapEncoder encoder = new System.Windows.Media.Imaging.JpegBitmapEncoder(); // Codifica la imagen encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(image)); // Graba la imagen encoder.Save(stmFile); } }
void SaveAsPng(string exportFilename, System.Windows.Media.Imaging.BitmapSource exportImage) { if (exportFilename == string.Empty) { return; } using (System.IO.FileStream stream = new System.IO.FileStream(exportFilename, System.IO.FileMode.Create)) { System.Windows.Media.Imaging.PngBitmapEncoder encoder = new System.Windows.Media.Imaging.PngBitmapEncoder(); encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(exportImage)); encoder.Save(stream); stream.Close(); } }
public static Texture2D CreateTexture2DFromMediaBitamp(Device device,MediaBitmapSource bitmapSource) { int stride = bitmapSource.PixelWidth * 4; using (var buffer = new DataStream(bitmapSource.PixelHeight * stride, true, true)) { // Copy the content of the WIC to the buffer byte[] array = new byte[bitmapSource.PixelHeight * stride]; bitmapSource.CopyPixels(array, stride, 0); buffer.Write(array, 0, bitmapSource.PixelHeight * stride); return new Texture2D(device, new Texture2DDescription() { Width = bitmapSource.PixelWidth, Height = bitmapSource.PixelHeight, ArraySize = 1, BindFlags = BindFlags.ShaderResource, Usage = ResourceUsage.Immutable, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R8G8B8A8_UNorm, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), }, new DataRectangle(buffer.DataPointer, stride)); } }
public XPImage(BitmapSource bitmapSource) { this.xImage = XImage.FromBitmapSource(bitmapSource); }
/** * Constructor */ public ImageButton() { mStretchForeground = new System.Windows.Media.Stretch(); mStretchForeground = System.Windows.Media.Stretch.None; mStretchBackground = new System.Windows.Media.Stretch(); mStretchBackground = System.Windows.Media.Stretch.Fill; this.createBackgroundImage(); this.createTextBlock(); this.createForegroundImage(); /** * Grid object that holds the text and the foreground and background images * It has only one row and one column * It will display whe widgets one on top of each other */ mGrid = new System.Windows.Controls.Grid(); this.AddWidgetsToGrid(); mGrid.Margin = new Thickness(0.0); mBackgroundImage.Margin = new Thickness(0.0); mForegroundImage.Margin = new Thickness(0.0); mBackgroundImage.Width = mGrid.Width - DifferenceSpacer; mBackgroundImage.Height = mGrid.Height - DifferenceSpacer; mBackgroundImage.Stretch = mStretchBackground; mView = mGrid; // the MouseEnter handle for the ImageButton. Used for switching background image. mGrid.MouseEnter += new System.Windows.Input.MouseEventHandler(delegate(Object from, System.Windows.Input.MouseEventArgs evt) { if (mPressedBackgroundImageSource != null) { mNormalBackgroundImageSource = (System.Windows.Media.Imaging.BitmapSource)mBackgroundImage.Source; mBackgroundImage.Source = mPressedBackgroundImageSource; } }); // the MouseLeave handle for the ImageButton. Used for switching background image. mGrid.MouseLeave += new System.Windows.Input.MouseEventHandler(delegate(Object from, System.Windows.Input.MouseEventArgs evt) { if (mNormalBackgroundImageSource != null) { mBackgroundImage.Source = mNormalBackgroundImageSource; mNormalBackgroundImageSource = null; } //create a Memory object of 8 Bytes Memory eventData = new Memory(8); //starting with the 0 Byte we write the eventType const int MAWidgetEventData_eventType = 0; //starting with the 4th Byte we write the widgetHandle const int MAWidgetEventData_widgetHandle = 4; eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.MAW_EVENT_CLICKED); eventData.WriteInt32(MAWidgetEventData_widgetHandle, mHandle); //posting a CustomEvent mRuntime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_WIDGET, eventData); }); }