async void LoadImage(object sender, RoutedEventArgs e) { var picker = new FileOpenPicker(); picker.FileTypeFilter.Add(".ico"); picker.FileTypeFilter.Add(".bmp"); picker.FileTypeFilter.Add(".gif"); picker.FileTypeFilter.Add(".png"); picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".jxr"); picker.FileTypeFilter.Add(".tif"); picker.FileTypeFilter.Add(".tiff"); StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { try { await _bitmap.LoadAsync(file, new FormatConverter(PixelFormat.Format32bppPBGRA)); ClearSavedCopy(); _savedCopy = _bitmap.Transform(); CreateImageSource(); } catch (Exception ex) { LoadDefaultImage(); MessageDialog md = new MessageDialog(Strings.ImageFormatNotSupportedException + ex.Message, ""); await md.ShowAsync(); } } }
async void MainPage_Loaded(object sender, RoutedEventArgs e) { // locate the image var imageUri = new Uri("ms-appx:///Assets/GcLogo.png"); var storageFile = await StorageFile.GetFileFromApplicationUriAsync(imageUri); // load the image into C1Bitmap _bitmap = new C1Bitmap(); await _bitmap.LoadAsync(storageFile, new FormatConverter(PixelFormat.Format32bppPBGRA)); // create Direct2D and DirectWrite factories _d2dFactory = D2D.Factory2.Create(D2D.FactoryType.SingleThreaded); _dwFactory = DW.Factory.Create(DW.FactoryType.Shared); // create GPU resources CreateDeviceResources(); // create the image source _imageSource = new SurfaceImageSource(_marginLT + _bitmap.PixelWidth + _marginRB, _marginLT + _bitmap.PixelHeight + _marginRB, false); // obtain the native interface for the image source _sisNative = ComObject.QueryInterface <DXGI.ISurfaceImageSourceNative>(_imageSource); _sisNative.SetDevice(_dxgiDevice); // draw the image to SurfaceImageSource UpdateImageSource(ImageEffect.Original); // associate the image source with the Image image.Source = _imageSource; }
void Load_Clicked(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "Image Files|*.ico;*.bmp;*.gif;*.png;*.jpg;*.jpeg;*.jxr;*.tif;*.tiff"; ofd.Title = "Select the Image"; if (ofd.ShowDialog().Value) { try { _bitmap.Load(ofd.FileName, new FormatConverter(PixelFormat.Format32bppPBGRA)); ClearSavedCopy(); _savedCopy = _bitmap.Transform(); UpdateImage(); } catch (Exception ex) { LoadDefaultImage(); MessageBox.Show(ex.Message); } } }
/// <summary> /// Round up the image /// </summary> /// <param name="sourceBitmap"></param> /// <returns></returns> public static C1Bitmap RoundUpImage(C1Bitmap sourceBitmap) { var image = sourceBitmap.ToGdiBitmap(); var width = image.Width; var height = image.Height; using (var transformBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)) { using (var graphics = Graphics.FromImage(transformBitmap)) { graphics.Clear(Color.Transparent); var path = new GraphicsPath(FillMode.Alternate); int radius = 15; int diameter = radius * 2; path.StartFigure(); path.AddLine(radius, 0, width - radius, 0); path.AddArc(new RectangleF(width - diameter, 0, diameter, diameter), -90, 90); path.AddLine(width, radius, width, height - radius); path.AddArc(new RectangleF(width - diameter, height - diameter, diameter, diameter), 0, 90); path.AddLine(width - radius, height, radius, height); path.AddArc(new RectangleF(0, height - diameter, diameter, diameter), 90, 90); path.AddLine(0, height - radius, 0, radius); path.AddArc(new RectangleF(0, 0, diameter, diameter), 180, 90); path.CloseFigure(); graphics.SetClip(path); graphics.DrawImage(image, Point.Empty); } sourceBitmap.Import(transformBitmap); return(sourceBitmap); } }
void ApplyTransform(BaseTransform t) { var newBitmap = _bitmap.Transform(t); _bitmap.Dispose(); _bitmap = newBitmap; UpdateImage(); }
async Task ApplyTransform(BaseTransform t) { var newBitmap = _bitmap.Transform(t); _bitmap.Dispose(); _bitmap = newBitmap; await UpdateImageSource(); }
void ClearSavedCopy() { if (_savedCopy != null) { _savedCopy.Dispose(); _savedCopy = null; } }
public void Rotate(int delta) { var rotateOption = (TransformOptions)Enum.ToObject(typeof(TransformOptions), delta); var transform = new FlipRotator(rotateOption); Bitmap = Bitmap.Transform(transform); Image = Bitmap.ToGdiBitmap(); }
async void Restart_Clicked(object sender, RoutedEventArgs e) { if (_savedCopy != null) { _bitmap.Dispose(); _bitmap = _savedCopy.Transform(); await UpdateImageSource(); } }
//---------------------------------------------------------------------- #region ** event handlers void CropPage_Load(object sender, EventArgs e) { if (!_initialized) { _bitmap = new C1Bitmap(); LoadDefaultImage(); _initialized = true; } }
void btnRestart_Click(object sender, EventArgs e) { if (_savedCopy != null) { _bitmap.Dispose(); _bitmap = _savedCopy.Transform(); UpdateImage(); } }
void PrepareForNewImage() { if (_initialized) { DXUtil.Dispose(ref _imBmp); ClearSavedCopy(); _savedCopy = _bitmap.Transform(); UpdateTargetRect(); Invalidate(false); } }
void ApplyTransform(BaseTransform t) { var newBitmap = _bitmap.Transform(t); _bitmap.Dispose(); _bitmap = newBitmap; _selection = new RectF(1f, 1f); UpdateImage(); }
//---------------------------------------------------------------------- #region ** other methods public void LoadDefaultImage() { Assembly asm = typeof(CropPage).Assembly; using (Stream stream = asm.GetManifestResourceStream("BitmapSamples.Resources.HousePlan.jpg")) { _bitmap.Load(stream, new FormatConverter(PixelFormat.Format32bppPBGRA)); _savedCopy = _bitmap.Transform(); } UpdateImage(); }
void LoadDefaultImage() { Assembly asm = typeof(Crop).Assembly; using (Stream stream = asm.GetManifestResourceStream("BitmapSamples.Resources.Sheep.jpg")) { _bitmap.Load(stream, new FormatConverter(C1.WPF.Bitmap.PixelFormat.Format32bppPBGRA)); } ClearSavedCopy(); _savedCopy = _bitmap.Transform(); image.Source = _bitmap.ToWriteableBitmap(); }
async void Page_Loaded(object sender, RoutedEventArgs e) { _bitmap = new C1Bitmap(); await LoadDefaultImage(); _dragHelper = new C1DragHelper(imageGrid); _dragHelper.DragStarted += OnDragStarted; _dragHelper.DragDelta += OnDragDelta; imageGrid.Tapped += ImageGrid_Tapped; _initialized = true; }
private static C1Bitmap Base64ToImage(string base64String) { // Convert base 64 string to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); var bitmap = new C1Bitmap(); // Convert byte[] to Image using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { bitmap.Load(ms); } return(bitmap); }
void LoadDefaultImage() { Assembly asm = typeof(Crop).GetTypeInfo().Assembly; using (Stream stream = asm.GetManifestResourceStream("BitmapSamples.Assets.Sheep.jpg")) { _bitmap.Load(stream, new FormatConverter(PixelFormat.Format32bppPBGRA)); } ClearSavedCopy(); _savedCopy = _bitmap.Transform(); CreateImageSource(); }
// C1Bitmap holder. public Picture(Bitmap source) { Bitmap = new C1Bitmap(); if (source != null) { using (MemoryStream stream = new MemoryStream()) { source.Save(stream, System.Drawing.Imaging.ImageFormat.Png); Bitmap.Load(stream); } } SizeMode = PictureBoxSizeMode.StretchImage; Image = Bitmap.ToGdiBitmap(); Width = 120; Height = 120; }
void LoadImageStream(Stream stream) { bitmap.SetStream(stream); if (bitmap.Width * bitmap.Height > imageSize) { var scale = Math.Sqrt(imageSize * 1.0 / (bitmap.Width * bitmap.Height)); var resizedBitmap = new C1Bitmap((int)(bitmap.Width * scale), (int)(bitmap.Height * scale)); resizedBitmap.Copy(bitmap, true); bitmap = resizedBitmap; } originalBitmap.Copy(bitmap, false); screen.Copy(bitmap, false); imageGrid.Width = screen.Width; imageGrid.Height = screen.Height; }
public BitmapPanel(Size size, bool scalePicture) { this.Click += CustomClick; Cursor = Cursors.Hand; // Set size SetSizeControl(size, scalePicture); _innerPanel = new Panel() { Location = new Point(_delta, _delta), Size = new Size(Width - 2 * _delta, Height - 2 * _delta) }; _innerPanel.Click += CustomClick; Controls.Add(_innerPanel); _bitmap = new C1Bitmap(); }
void InitResources() { // load the image into C1Bitmap _bitmap = new C1Bitmap(); Assembly asm = typeof(MainWindow).Assembly; using (Stream stream = asm.GetManifestResourceStream("Direct2DEffects.Resources.GcLogo.png")) { _bitmap.Load(stream, new FormatConverter(C1.WPF.Bitmap.PixelFormat.Format32bppPBGRA)); } // create Direct2D and DirectWrite factories _d2dFactory = D2D.Factory2.Create(D2D.FactoryType.SingleThreaded); _dwFactory = DW.Factory.Create(DW.FactoryType.Shared); // create GPU resources CreateDeviceResources(); }
//---------------------------------------------------------------------- #region ** event handlers void FaceWarp_Load(object sender, EventArgs e) { if (!_initialized) { if (CreateDeviceIndependentResources()) { _bitmap = new C1Bitmap(_wicFactory); _initialized = true; LoadDefaultImage(); } else { btnLoad.Enabled = false; btnExport.Enabled = false; btnRestart.Enabled = false; } } }
void Page_Loaded(object sender, RoutedEventArgs e) { if (!_initialized) { _bitmap = new C1Bitmap(); LoadDefaultImage(); _dragHelper = new C1DragHelper(imageGrid); _dragHelper.DragDelta += OnDragDelta; _window = Window.GetWindow(this); if (_window != null) { _window.Closing += Window_Closing; } _initialized = true; } }
public FaceWarp() { InitializeComponent(); LoadDefaultImage(); image.Source = screen.ImageSource; var mouseHelper = new C1DragHelper(image, captureElementOnPointerPressed: true, initialThreshold: 0); var line = new Line(); mouseHelper.DragStarted += (s, e) => { _position = e.GetPosition(image); line = new Line { X1 = _position.X, Y1 = _position.Y, X2 = _position.X, Y2 = _position.Y, Stroke = new SolidColorBrush(Colors.Blue), StrokeThickness = 7, StrokeEndLineCap = PenLineCap.Triangle, StrokeStartLineCap = PenLineCap.Round }; imageGrid.Children.Add(line); }; mouseHelper.DragDelta += (s, e) => { var pos = e.GetPosition(image); line.X2 = pos.X; line.Y2 = pos.Y; }; mouseHelper.DragCompleted += (s, e) => { imageGrid.Children.Remove(line); var start = _position; var end = new Point(_position.X + e.CumulativeTranslation.X, _position.Y + e.CumulativeTranslation.Y); bitmap = new C1Bitmap(screen); Warp(bitmap, screen, start, end); }; }
void Page_Loaded(object sender, RoutedEventArgs e) { CreateDeviceIndependentResources(); _bitmap = new C1Bitmap(_wicFactory); CreateDeviceResources(); LoadDefaultImage(); _dragHelper = new C1DragHelper(image, captureElementOnPointerPressed: true, initialThreshold: 0); _dragHelper.DragStarted += OnDragStarted; _dragHelper.DragDelta += OnDragDelta; _dragHelper.DragCompleted += OnDragCompleted; _app = Application.Current; if (_app != null) { _app.Suspending += App_Suspending; } _initialized = true; }
public BitmapPanel(DataRow rowData, bool scalePicture, Size size) : this(size, scalePicture) { _innerPanel.Controls.Clear(); var checkColumns = new List <string>() { "Caption", "Picture", "Description" }; var sourceColumns = (from s in rowData.Table.Columns.Cast <DataColumn>() select s) .Select(x => x.ColumnName); if (!checkColumns.Where(x => sourceColumns.Contains(x)).Any()) { MessageBox.Show("The data source did not corrent!\nExpect columns: " + string.Join(",", checkColumns.ToArray())); } // Add label _caption = rowData["Caption"].ToString(); _description = rowData["Description"].ToString(); _label = new RichTextBox() { Text = _caption, Dock = DockStyle.Bottom, BackColor = System.Drawing.SystemColors.Window, BorderStyle = System.Windows.Forms.BorderStyle.None, ReadOnly = true, Cursor = Cursors.Hand }; _label.Height = _label.Font.Height + 2; _label.Click += CustomClick; _innerPanel.Controls.Add(_label); // Add bitmap _bitmap = LoadImage((byte[])rowData["Picture"]); SetImagePanel(); _defaultColor = _label.SelectionColor; _defaultBackColor = _label.SelectionBackColor; }
public MainForm() { InitializeComponent(); // load the image into C1Bitmap _bitmap = new C1Bitmap(); Assembly asm = typeof(MainForm).Assembly; using (Stream stream = asm.GetManifestResourceStream("Direct2DEffects.Resources.GcLogo.png")) { _bitmap.Load(stream, new FormatConverter(PixelFormat.Format32bppPBGRA)); } // create Direct2D and DirectWrite factories _d2dFactory = D2D.Factory2.Create(D2D.FactoryType.SingleThreaded); _dwFactory = DW.Factory.Create(DW.FactoryType.Shared); // create GPU resources CreateDeviceResources(); // fill the list of available effects var coll = effectsCombo.Items; coll.Add(new EffectItem(ImageEffect.Original, "Original Image")); coll.Add(new EffectItem(ImageEffect.GaussianBlur, "Gaussian Blur")); coll.Add(new EffectItem(ImageEffect.Sharpen, "Sharpen")); coll.Add(new EffectItem(ImageEffect.HorizontalSmear, "Horizontal Smear")); coll.Add(new EffectItem(ImageEffect.Shadow, "Shadow")); coll.Add(new EffectItem(ImageEffect.DisplacementMap, "Displacement Map")); coll.Add(new EffectItem(ImageEffect.Emboss, "Emboss")); coll.Add(new EffectItem(ImageEffect.EdgeDetect, "Edge Detect")); coll.Add(new EffectItem(ImageEffect.Sepia, "Sepia")); effectsCombo.SelectedIndex = 0; effectsCombo.SelectionChangeCommitted += effectsCombo_SelectionChangeCommitted; // display the original image UpdateImageSource(ImageEffect.Original); }
private async void ExportImage(object sender, RoutedEventArgs e) { if (selection.Width == 0 || selection.Height == 0) { MessageDialog md = new MessageDialog(Strings.EmptySelectionMessage); md.ShowAsync(); return; } var picker = new FileSavePicker(); picker.FileTypeChoices.Add("png", new List <string> { ".png" }); picker.DefaultFileExtension = ".png"; StorageFile file = await picker.PickSaveFileAsync(); if (file != null) { var saveStream = await file.OpenStreamForWriteAsync(); var crop = new C1Bitmap((int)selection.Width, (int)selection.Height); crop.BeginUpdate(); for (int x = 0; x < selection.Width; ++x) { for (int y = 0; y < selection.Height; ++y) { crop.SetPixel(x, y, bitmap.GetPixel(x + (int)selection.X, y + (int)selection.Y)); } } crop.EndUpdate(); var readStream = crop.GetStream(ImageFormat.Png, true); var data = new byte[readStream.Length]; readStream.Read(data, 0, (int)readStream.Length); saveStream.Write(data, 0, data.Length); saveStream.Dispose(); } }
void Page_Loaded(object sender, RoutedEventArgs e) { if (!_initialized) { CreateDeviceIndependentResources(); _bitmap = new C1Bitmap(_wicFactory); CreateDeviceResources(); LoadDefaultImage(); _dragHelper = new C1DragHelper(image, captureElementOnPointerPressed: true, initialThreshold: 0); _dragHelper.DragStarted += OnDragStarted; _dragHelper.DragDelta += OnDragDelta; _dragHelper.DragCompleted += OnDragCompleted; _window = Window.GetWindow(this); if (_window != null) { _window.Closing += Window_Closing; } _initialized = true; } }