private void Apply_rotate(object sender, RoutedEventArgs e) { try { string text = rotate_txt.Text; double number = Convert.ToDouble(text); if (text == "") { MessageBox.Show("The textbox is empty ,please enter a suitable degree"); } else { TransformedBitmap transformation = new TransformedBitmap(); transformation.BeginInit(); transformation.Source = bm; RotateTransform rotate = new RotateTransform(number); transformation.Transform = rotate; transformation.EndInit(); image_control.Source = transformation; } } catch (Exception) { MessageBox.Show("please enteronethe following degrees 0,90,180,270,360"); } }
void CaptureListener.OnBuffer(CaptureDevice oCaptureDevice, double i_sample_time, IntPtr i_buffer, int i_buffer_len) { Dispatcher.Invoke(new Action(delegate() { TransformedBitmap b = new TransformedBitmap(); b.BeginInit(); b.Source = BitmapSource.Create(oCaptureDevice.video_width, oCaptureDevice.video_height, 96.0, 96.0, PixelFormats.Bgr32, BitmapPalettes.WebPalette, i_buffer, i_buffer_len, oCaptureDevice.video_width * (oCaptureDevice.video_bit_count / 8)); b.SetValue(TransformedBitmap.TransformProperty, new ScaleTransform(-1, -1)); b.EndInit(); this.ImgCameraZm.SetValue(Image.SourceProperty, b); this.ARMarkerSystem.update(this.ARCameraSensor); this.CvMainZm.Children.Clear(); if (this.ARMarkerSystem.isExistMarker(this.MarkerID_VTT)) { this.DrawARDetectInfo(this.MarkerID_VTT, "VTT"); } if (this.ARMarkerSystem.isExistMarker(this.MarkerID_ABB)) { this.DrawARDetectInfo(this.MarkerID_ABB, "ABB"); } if (this.ARMarkerSystem.isExistMarker(this.Marker_Hello)) { this.DrawARDetectInfo(this.Marker_Hello, "Hello"); } })); }
private void PageLoaded(object sender, RoutedEventArgs args) { // Create Image element. Image rotated90 = new Image(); rotated90.Width = 150; // Create the TransformedBitmap to use as the Image source. TransformedBitmap tb = new TransformedBitmap(); // Create the source to use as the tb source. BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(@"sampleImages/watermelon.jpg", UriKind.RelativeOrAbsolute); bi.EndInit(); // Properties must be set between BeginInit and EndInit calls. tb.BeginInit(); tb.Source = bi; // Set image rotation. RotateTransform transform = new RotateTransform(90); tb.Transform = transform; tb.EndInit(); // Set the Image source. rotated90.Source = tb; //Add Image to the UI Grid.SetColumn(rotated90, 1); Grid.SetRow(rotated90, 1); transformedGrid.Children.Add(rotated90); }
/// <summary> /// Draws out the shooting enemies. /// </summary> /// <returns>a drawing.</returns> private Drawing GetShootingMonsters() { DrawingGroup g = new DrawingGroup(); foreach (var enemy in this.model.ShootingMonsters) { if (this.oldShootingMonsters == null || !this.oldShootingMonstersPosition.Contains(enemy.Cords)) { Point p = new Point((this.model.MyPlayer.Cords.X * GameModel.TileSize) - (enemy.Cords.X * GameModel.TileSize), (this.model.MyPlayer.Cords.Y * GameModel.TileSize) - (enemy.Cords.Y * GameModel.TileSize)); double rotation = Math.Atan2(p.Y, p.X) * 180 / Math.PI; BitmapImage bmp = GetImage("ct100big.png"); TransformedBitmap tb = new TransformedBitmap(); tb.BeginInit(); tb.Source = bmp; tb.Transform = new RotateTransform(90); tb.EndInit(); ImageDrawing drawing = new ImageDrawing(tb, new Rect(enemy.Cords.X * GameModel.TileSize, enemy.Cords.Y * GameModel.TileSize, GameModel.TileSize, GameModel.TileSize)); RotateTransform rotate = new RotateTransform(rotation, (enemy.Cords.X * GameModel.TileSize) + (GameModel.TileSize / 2), (enemy.Cords.Y * GameModel.TileSize) + (GameModel.TileSize / 2)); g.Children.Add(new DrawingGroup() { Children = { drawing }, Transform = rotate }); } } this.oldShootingMonsters = g; return(this.oldShootingMonsters); }
public BagSortNode(int top, int left) : base(top, left) { DelayTime = 10; TransformedBitmap tr = new TransformedBitmap(); RotateTransform right = new RotateTransform(90); BitmapImage bmp = new BitmapImage(); image = new Image { Width = 72, Height = 72, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, }; bmp = new BitmapImage(new Uri($"../../Resources/sorter.png", UriKind.Relative)); tr.BeginInit(); tr.Source = bmp; RotateTransform transform = new RotateTransform(90); tr.Transform = transform; tr.EndInit(); image.Source = tr; }
private static TransformedBitmap Transform(BblBitmapSource source, double scale, int angle) { // Set up the transformed thumbnail TransformedBitmap thumb = new TransformedBitmap(); thumb.BeginInit(); thumb.Source = source; TransformGroup transform = new TransformGroup(); // Rotation if (Math.Abs(angle) % 360 != 0) { transform.Children.Add(new RotateTransform(Math.Abs(angle))); } // Scale if ((float)scale < 1.0f) // Only downscale { double xScale = Math.Min(1.0, Math.Max(1.0 / (double)source.PixelWidth, scale)); double yScale = Math.Min(1.0, Math.Max(1.0 / (double)source.PixelHeight, scale)); if (angle < 0) { xScale = -xScale; } transform.Children.Add(new ScaleTransform(xScale, yScale)); } thumb.Transform = transform; thumb.EndInit(); return(thumb); }
// 静态委托 public void VideoDataCallbackDelegate(int userId, IntPtr buf, int len, AnyChatCoreSDK.BITMAPINFOHEADER bitMap, int userValue) { int stride = bitMap.biWidth * 3; BitmapSource bs = BitmapSource.Create(bitMap.biWidth, bitMap.biHeight, 96, 96, PixelFormats.Bgr24, null, buf, len, stride); // 将图像进行翻转 TransformedBitmap RotateBitmap = new TransformedBitmap(); RotateBitmap.BeginInit(); RotateBitmap.Source = bs; RotateBitmap.Transform = new RotateTransform(180); RotateBitmap.EndInit(); RotateBitmap.Freeze(); // 异步操作 Action action = new Action(delegate() { Dispatcher.BeginInvoke(new Action(delegate() { if (userId == g_selfUserId) { localVideoImage.Source = RotateBitmap; } else if (userId == g_otherUserId) { remoteVideoImage.Source = RotateBitmap; } }), null); }); action.BeginInvoke(null, null); }
private void Apply_rotate(object sender, RoutedEventArgs e) { string text = rotate_txt.Text; if (text == "") { MessageBox.Show("The textbox is empty ,please enter a suitable degree"); } else { double number = Convert.ToDouble(text); TransformedBitmap transformation = new TransformedBitmap(); transformation.BeginInit(); transformation.Source = bm; RotateTransform rotate = new RotateTransform(number); transformation.Transform = rotate; transformation.EndInit(); username_image.Source = transformation; //Image i = new Image(); //i.image_deal.Source = transformation; //i.image_deal.Visibility = Visibility.Visible; //i.Visibility = Visibility.Visible; } }
public static ImageSource Decode(TgaHeader tgaHeader, byte[] imageBuffer, int size) { const double DPI_X = 96d; const double DPI_Y = 96d; var stride = GetStride(tgaHeader); var pixelFormat = GetPixelFormat(tgaHeader); var bitmap = BitmapSource.Create( tgaHeader.Width, tgaHeader.Height, DPI_X, DPI_Y, pixelFormat, null, imageBuffer, stride); var transformedBmp = new TransformedBitmap(); transformedBmp.BeginInit(); transformedBmp.Source = bitmap; transformedBmp.Transform = CreateShrinkTransform(tgaHeader, size); transformedBmp.EndInit(); return(transformedBmp); }
public static void DrawProduct(Canvas canvas, ProductPlacement placement) { //Haal de bestandsnaam van de foto op of gebruik de default Product product = placement.Product; int x = placement.X; int y = placement.Y; string?photo = product.Photo ?? "placeholder.png"; int actualWidth = placement.Rotation % 180 == 0 ? product.Width : product.Length; int actualLength = placement.Rotation % 180 == 0 ? product.Length : product.Width; // Veranderd de rotatie van het product TransformedBitmap tempBitmap = new TransformedBitmap(); tempBitmap.BeginInit(); BitmapImage source = new BitmapImage(new Uri(Environment.CurrentDirectory + $"/Resources/Images/{photo}")); tempBitmap.Source = source; RotateTransform transform = new RotateTransform(placement.Rotation, source.Width / 2, source.Height / 2); tempBitmap.Transform = transform; tempBitmap.EndInit(); Image image = new Image { Source = tempBitmap, Height = actualLength, Width = actualWidth }; Canvas.SetTop(image, y); Canvas.SetLeft(image, x); // Voeg product toe aan canvas canvas.Children.Add(image); }
public static BitmapSource GetResized(BitmapSource src, int Size) { BitmapSource Source = src.Clone(); BitmapSource backup = Source.Clone(); try { TransformedBitmap scaled = new TransformedBitmap(); scaled.BeginInit(); scaled.Source = Source; double scX = (double)Size / (double)Source.PixelWidth; double scy = (double)Size / (double)Source.PixelHeight; ScaleTransform tr = new ScaleTransform(scX, scy, Source.Width / 2, Source.Height / 2); scaled.Transform = tr; scaled.EndInit(); Source = scaled; } catch { Source = backup; } int stride = ((((Source.Format.BitsPerPixel * Source.PixelWidth) + 31) / 32) * 4); byte[] sourceBuffer = new byte[stride * Source.PixelHeight]; Source.CopyPixels(sourceBuffer, stride, 0); BitmapSource bmp = BitmapSource.Create(Source.PixelWidth, Source.PixelHeight, 96, 96, Source.Format, Source.Palette, sourceBuffer, stride); return(bmp); }
public static BitmapSource RotateImage(string Image) { try { TransformedBitmap tBmp = new TransformedBitmap(); tBmp.BeginInit(); tBmp.Source = new BitmapImage(new Uri("pack://application:,,,./Images/FK/" + Image + ".png")); RotateTransform rt = new RotateTransform { Angle = 0 }; tBmp.Transform = rt; tBmp.EndInit(); //Create a new source after the transform BitmapSource s1 = tBmp; return(s1); } catch (Exception e) { MessageBox.Show(e.ToString()); } return(null); }
public static BitmapSource Resize(this BitmapSource image, int height) { BitmapSource bitmapSource; if (image.Height <= (double)height) { bitmapSource = image; } else { TransformedBitmap transformedBitmap = new TransformedBitmap(); transformedBitmap.BeginInit(); transformedBitmap.Source = image; int pixelHeight = transformedBitmap.Source.PixelHeight; int pixelWidth = transformedBitmap.Source.PixelWidth; double scaleX = (double)(transformedBitmap.Source.PixelWidth * height / pixelHeight) / (double)pixelWidth; double scaleY = (double)height / (double)pixelHeight; transformedBitmap.Transform = (Transform) new TransformGroup() { Children = { (Transform) new ScaleTransform(scaleX, scaleY) } }; transformedBitmap.EndInit(); WriteableBitmap writeableBitmap = new WriteableBitmap((BitmapSource)transformedBitmap); writeableBitmap.Freeze(); bitmapSource = (BitmapSource)writeableBitmap; } return(bitmapSource); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { CardBase card = value as CardBase; Image image = new Image(); if (card != null) { BitmapImage bitmap = card.CardImage; RotateTransform rotTrans = new RotateTransform(card.RotAngle()); TransformedBitmap bitmapTrans = new TransformedBitmap(); bitmapTrans.BeginInit(); bitmapTrans.Source = bitmap; bitmapTrans.Transform = rotTrans; bitmapTrans.EndInit(); image = new Image(); image.Source = bitmapTrans; image.Width = 100; image.Height = 100; } return(image); }
private void ImageCropper_Loaded(Object sender, RoutedEventArgs e) { SolidColorBrush brush = new SolidColorBrush(); brush.Color = Colors.White; SetDesignerItemColor(brush); BitmapSource src = imageSource as BitmapSource; if (src != null) { m_PixelWidth = src.PixelWidth; m_PixelHeight = src.PixelHeight; m_DpiX = src.DpiX; m_DpiY = src.DpiY; ReArrangeDesignerItem(src.PixelWidth, src.PixelHeight, src.DpiX, src.DpiY); //scale down image ScaleTransform scaleTransform = new ScaleTransform(); scaleTransform.ScaleX = imageWidth / PixelToUnit(src.PixelWidth, src.DpiX); scaleTransform.ScaleY = imageHeight / PixelToUnit(src.PixelHeight, src.DpiY); TransformedBitmap tb = new TransformedBitmap(); tb.BeginInit(); tb.Source = src; tb.Transform = scaleTransform; tb.EndInit(); this.backgroundImage.Source = tb; } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || !(value is string) || (value as string).Substring(0, 7) == @"Images\" || File.Exists(value as string) || (value as string).Substring(0, 4).ToLower() == "http" || (value as string).Substring(0, 3).ToLower() == "ftp" ) { return(value); } string [] sts = (value as string).Split(':'); if (sts.Length == 3) { sts [1] = sts [0] + ":" + sts [1]; sts = sts.Where(w => w != sts [0]).ToArray(); } BitmapImage bitmap = null; if (File.Exists(sts [0])) { FileStream zipStream = File.OpenRead(sts [0]); using (ZipArchive zip = new ZipArchive(zipStream)) { ZipArchiveEntry icon = zip.GetEntry(sts [1]); Stream imgStream = icon.Open(); Byte [] buffer = new Byte [icon.Length]; imgStream.Read(buffer, 0, buffer.Length); var byteStream = new System.IO.MemoryStream(buffer); bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.StreamSource = byteStream; bitmap.EndInit(); } } BitmapSource source = bitmap; if (bitmap.Format == PixelFormats.Bgra32 || bitmap.Format == PixelFormats.Prgba64 || bitmap.Format == PixelFormats.Rgba128Float || bitmap.Format == PixelFormats.Rgba64 ) { source = AutoCropBitmap(bitmap) as BitmapSource; } TransformedBitmap scaledBitmap = new TransformedBitmap(); scaledBitmap.BeginInit(); scaledBitmap.Source = source; double scale = 100 / source.Width; scaledBitmap.Transform = new ScaleTransform(scale, scale, source.Width / 2, source.Height / 2); scaledBitmap.EndInit(); return(scaledBitmap); }
public static ImageSource GetImageSource(WriteableBitmap writeableBitmap) { TransformedBitmap bitmap = new TransformedBitmap(); bitmap.BeginInit(); bitmap.Source = writeableBitmap; bitmap.EndInit(); return(bitmap); }
public void CreateImage( DxfRasterImage rasterImage, WW.Math.Point2D imageCorner1, WW.Math.Point2D imageCorner2, Vector4D transformedOrigin, Vector4D transformedXAxis, Vector4D transformedYAxis, DrawContext.Wireframe drawContext) { IBitmap bitmap = rasterImage.ImageDef.Bitmap; if (!bitmap.IsValid) { return; } imageCorner1 += DxfRasterImage.PixelOffset; imageCorner2 -= DxfRasterImage.PixelOffset; double width = (double)bitmap.Width; double height = (double)bitmap.Height; imageCorner1.X = IntervalD.GetRestrictedValue(imageCorner1.X, 0.0, width - 1.0); imageCorner1.Y = IntervalD.GetRestrictedValue(imageCorner1.Y, 0.0, height - 1.0); imageCorner2.X = IntervalD.GetRestrictedValue(imageCorner2.X, 0.0, width - 1.0); imageCorner2.Y = IntervalD.GetRestrictedValue(imageCorner2.Y, 0.0, height - 1.0); bool flag = imageCorner1.X != 0.0 || imageCorner1.Y != 0.0 || imageCorner2.X != width - 1.0 || imageCorner2.Y != height - 1.0; IntPtr hbitmap = bitmap.Image.GetHbitmap(); try { BitmapSource source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); if (flag) { source = (BitmapSource) new CroppedBitmap(source, new Int32Rect((int)imageCorner1.X, (int)imageCorner1.Y, (int)(imageCorner2.X - imageCorner1.X), (int)(imageCorner2.Y - imageCorner1.Y))); } WW.Math.Point2D point2D1 = this.matrix4D_0.TransformToPoint2D(transformedOrigin); WW.Math.Point2D point2D2 = this.matrix4D_0.TransformToPoint2D(transformedXAxis); WW.Math.Point2D point2D3 = this.matrix4D_0.TransformToPoint2D(transformedYAxis); Vector2D vector2D1 = point2D2 - point2D1; Vector2D vector2D2 = point2D3 - point2D1; TransformedBitmap transformedBitmap = new TransformedBitmap(); transformedBitmap.BeginInit(); transformedBitmap.Source = source; transformedBitmap.Transform = (Transform) new MatrixTransform(new Matrix(1.0, 0.0, 0.0, 1.0, 0.0, point2D1.Y) * new Matrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0) * new Matrix(1.0, 0.0, 0.0, 1.0, 0.0, -point2D1.Y) * new Matrix(vector2D1.X, vector2D2.X, vector2D1.Y, vector2D2.Y, 0.0, 0.0)); transformedBitmap.EndInit(); Image image = new Image(); image.BeginInit(); image.Source = (ImageSource)transformedBitmap; image.RenderTransform = (Transform) new TranslateTransform(point2D1.X, point2D1.Y); image.Stretch = Stretch.None; image.EndInit(); this.visualCollection_0.Add((Visual)image); } finally { Class975.DeleteObject(hbitmap); } }
private TransformedBitmap ScaleImage(ImageWidgetViewModel img) { var tb = new TransformedBitmap(); var scaleTransform = new ScaleTransform(); BitmapFrame OriginSource = img.ImgOriginSource as BitmapFrame; if (OriginSource == null) { tb.BeginInit(); tb.Source = null; tb.Transform = scaleTransform; tb.EndInit(); return(tb); } var scalex = img.ItemWidth / OriginSource.Width; var scaley = img.ItemHeight / OriginSource.Height; if (scaley <= scalex) { scaleTransform.ScaleX = 1; scaleTransform.ScaleY = (img.ItemHeight / OriginSource.Height) / scalex; } else { scaleTransform.ScaleY = 1; scaleTransform.ScaleX = (img.ItemWidth / OriginSource.Width) / scaley; } var checkWholeSize = (scaleTransform.ScaleX * OriginSource.Width) * (scaleTransform.ScaleY * OriginSource.Height); if (checkWholeSize > 3000 * 3000) { scaleTransform.ScaleX = Math.Sqrt(3000 * 3000 / checkWholeSize) * scaleTransform.ScaleX; scaleTransform.ScaleY = Math.Sqrt(3000 * 3000 / checkWholeSize) * scaleTransform.ScaleY; } tb.BeginInit(); tb.Source = OriginSource as BitmapFrame; tb.Transform = scaleTransform; tb.EndInit(); return(tb); }
public LibraryFilterControl() { InitializeComponent(); // Rotate the SORT icon 270 degrees TransformedBitmap sort_icon_rotated = new TransformedBitmap(); { BitmapImage sort_icon = Icons.GetAppIcon(Icons.Sort); sort_icon_rotated.BeginInit(); sort_icon_rotated.Transform = new RotateTransform(270); sort_icon_rotated.Source = sort_icon; sort_icon_rotated.EndInit(); } // Move the tabs into their correct places... DualTabTags.Children.Clear(); DualTabTags.AddContent("Sort", "Sort", sort_icon_rotated, false, false, TabSort); DualTabTags.AddContent("Tag", "Tag", null, false, false, TabTags); DualTabTags.AddContent("AutoTag", "AutoTag", null, false, false, TabAITags); DualTabTags.AddContent("Author", "Author", null, false, false, TabAuthors); DualTabTags.AddContent("Publ.", "Publ.", null, false, false, TabPublications); DualTabTags.AddContent("Year", "Year", null, false, false, TabYear); DualTabTags.AddContent("Stage", "Stage", null, false, false, TabReadingStages); DualTabTags.AddContent("Rating", "Rating", null, false, false, TabRatings); DualTabTags.AddContent("Theme", "Theme", null, false, false, TabThemes); DualTabTags.AddContent("Type", "Type", null, false, false, TabTypes); DualTabTags.MakeActive("Tag"); DualTabTags.TabPosition = DualTabbedLayout.TabPositions.Sides; SearchTag.OnSoftSearch += SearchTag_OnSoftSearch; ObjTagExplorerControl.OnTagSelectionChanged += ObjTagExplorerControl_OnTagSelectionChanged; ObjAITagExplorerControl.OnTagSelectionChanged += ObjAITagExplorerControl_OnTagSelectionChanged; ObjAuthorExplorerControl.OnTagSelectionChanged += ObjAuthorExplorerControl_OnTagSelectionChanged; ObjPublicationExplorerControl.OnTagSelectionChanged += ObjPublicationExplorerControl_OnTagSelectionChanged; ObjReadingStageExplorerControl.OnTagSelectionChanged += ObjReadingStageExplorerControl_OnTagSelectionChanged; ObjYearExplorerControl.OnTagSelectionChanged += ObjYearExplorerControl_OnTagSelectionChanged; ObjRatingExplorerControl.OnTagSelectionChanged += ObjRatingExplorerControl_OnTagSelectionChanged; ObjThemeExplorerControl.OnTagSelectionChanged += ObjThemeExplorerControl_OnTagSelectionChanged; ObjTypeExplorerControl.OnTagSelectionChanged += ObjTypeExplorerControl_OnTagSelectionChanged; ObjLibraryFilterControl_Sort.SortChanged += ObjLibraryFilterControl_Sort_SortChanged; ObjPanelSearchByTag.Visibility = ConfigurationManager.Instance.NoviceVisibility; // DispatcherTimer setup var dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += WeakEventHandler2.Wrap(dispatcherTimer_Tick, (eh) => { dispatcherTimer.Tick -= eh; }); dispatcherTimer.Interval = TimeSpan.FromMilliseconds(Constants.UI_REFRESH_POLLING_INTERVAL); dispatcherTimer.Start(); }
private static BitmapSource ScaleImage(BitmapSource pSourceImage, int pixelWidth, int pixelHeight) { var tb = new TransformedBitmap(); tb.BeginInit(); tb.Source = pSourceImage; tb.Transform = new ScaleTransform((double)pixelWidth / 100, (double)pixelHeight / 100); tb.EndInit(); return(tb); }
public static TransformedBitmap Rotate(BitmapSource image, double angle) { TransformedBitmap transformedBitmap = new TransformedBitmap(); transformedBitmap.BeginInit(); transformedBitmap.Source = image; transformedBitmap.Transform = new RotateTransform(angle); transformedBitmap.EndInit(); return(transformedBitmap); }
public BitmapSource SingleBitmapRotation(int angle, BitmapSource bitmap) { var transformedBitmap = new TransformedBitmap(); transformedBitmap.BeginInit(); transformedBitmap.Source = bitmap; transformedBitmap.Transform = new RotateTransform(angle); transformedBitmap.EndInit(); return(transformedBitmap); }
public SharpDX.Direct2D1.Bitmap GetD2DBitmap(SharpDX.Direct2D1.DeviceContext dc) { BitmapSource src = Frame; // PixelFormat settings/conversion if (src.Format != System.Windows.Media.PixelFormats.Bgra32) { // Convert BitmapSource FormatConvertedBitmap fcb = new FormatConvertedBitmap(); fcb.BeginInit(); fcb.Source = src; fcb.DestinationFormat = PixelFormats.Bgra32; fcb.EndInit(); src = fcb; } if (src.PixelHeight > _maxImageSize || src.PixelWidth > _maxImageSize) { double scale = (src.PixelWidth > src.PixelHeight) ? _maxImageSize / src.PixelWidth : _maxImageSize / src.PixelHeight; TransformedBitmap tb = new TransformedBitmap(); tb.BeginInit(); tb.Source = src; tb.Transform = new ScaleTransform(scale, scale); tb.EndInit(); src = tb; } SharpDX.Direct2D1.Bitmap retval = null; GCHandle pinnedArray = GCHandle.Alloc(null); try { int stride = src.PixelWidth * (src.Format.BitsPerPixel + 7) / 8; int bufferSize = stride * src.PixelHeight; byte[] buffer = new byte[bufferSize]; src.CopyPixels(System.Windows.Int32Rect.Empty, buffer, stride, 0); pinnedArray = GCHandle.Alloc(buffer, GCHandleType.Pinned); using (SharpDX.DataStream datastream = new SharpDX.DataStream(pinnedArray.AddrOfPinnedObject(), bufferSize, true, false)) { var bmpProps1 = new SharpDX.Direct2D1.BitmapProperties1(dc.PixelFormat, dc.Factory.DesktopDpi.Width, dc.Factory.DesktopDpi.Height); retval = new SharpDX.Direct2D1.Bitmap1(dc, new SharpDX.Size2(src.PixelWidth, src.PixelHeight), datastream, stride, bmpProps1); } } catch { } finally { if (pinnedArray.IsAllocated) { pinnedArray.Free(); } } return(retval); }
public static BitmapSource Resize(this BitmapSource source, double scalingX, double scalingY) { var transformedBitmap = new TransformedBitmap(); transformedBitmap.BeginInit(); transformedBitmap.Source = source; transformedBitmap.Transform = new ScaleTransform(scalingX, scalingY); transformedBitmap.EndInit(); return(transformedBitmap); //var targetBitmap = new TransformedBitmap((source as BitmapImage), new ScaleTransform(scalingX, scalingY)); }
/// <summary> /// Creates a thumbnail from an image file path. /// </summary> /// <param name="path"></param> void CreateThumbnail(string path) { FileStream stream = null; try { stream = new FileStream(path, FileMode.Open); var frame = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.None) .Frames[0]; BitmapSource thumbnail = frame.Thumbnail; if (thumbnail != null) { _thumb = thumbnail; return; } var transformedBitmap = new TransformedBitmap(); transformedBitmap.BeginInit(); transformedBitmap.Source = frame; int pixelH = frame.PixelHeight; int pixelW = frame.PixelWidth; int decodeH = 100; int decodeW = frame.PixelWidth * decodeH / pixelH; double scaleX = decodeW / (double)pixelW; double scaleY = decodeH / (double)pixelH; TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(new ScaleTransform(scaleX, scaleY)); transformedBitmap.Transform = transformGroup; transformedBitmap.EndInit(); WriteableBitmap writable = new WriteableBitmap(transformedBitmap); writable.Freeze(); _thumb = writable; } catch (IOException ex) { //TODO generate default image } finally { if (stream != null) { stream.Dispose(); } } }
private BitmapSource TransformBitmap(BitmapSource source, Transform transform) { var result = new TransformedBitmap(); result.BeginInit(); result.Source = source; result.Transform = transform; result.EndInit(); result.Freeze(); return(result); }
public static TransformedBitmap Scale(BitmapSource image, double scaleX, double scaleY) { TransformedBitmap transformedBitmap = new TransformedBitmap(); transformedBitmap.BeginInit(); transformedBitmap.Source = image; transformedBitmap.Transform = new ScaleTransform(scaleX, scaleY); transformedBitmap.EndInit(); return(transformedBitmap); }
/// <summary> /// Draws out the tracking enemies. /// </summary> /// <returns>a drawing.</returns> private Drawing GetTrackingMonsters() { DrawingGroup g = new DrawingGroup(); foreach (var enemy in this.model.TrackingMonsters) { if (this.oldTrackingMonsters == null || !this.oldTrackingMonstersPosition.Contains(enemy.Cords)) { BitmapImage bmp; if (enemy.BeingDamagedByLava) { bmp = GetImage("hoodtracker100100onfire.png"); } else { bmp = GetImage("hoodtracker100100.png"); } TransformedBitmap tb = new TransformedBitmap(); tb.BeginInit(); tb.Source = bmp; switch (this.model.BasicTrackingPath[enemy.Cords]) { case { } point when point == new Point(1, 0): tb.Transform = new RotateTransform(270); break; case { } point when point == new Point(0, 1): tb.Transform = new RotateTransform(0); break; case { } point when point == new Point(-1, 0): tb.Transform = new RotateTransform(90); break; case { } point when point == new Point(0, -1): tb.Transform = new RotateTransform(180); break; default: break; } tb.EndInit(); ImageDrawing drawing = new ImageDrawing(tb, new Rect(enemy.Cords.X * GameModel.TileSize, enemy.Cords.Y * GameModel.TileSize, GameModel.TileSize, GameModel.TileSize)); g.Children.Add(drawing); } } this.oldTrackingMonsters = g; return(this.oldTrackingMonsters); }
private void buttonRotate_Click(object sender, RoutedEventArgs e) { TransformedBitmap tb = new TransformedBitmap(); tb.BeginInit(); tb.Transform = new RotateTransform(90); tb.Source = this.imageViewModel.LoadedBitmap; tb.EndInit(); this.imageViewModel.LoadedBitmap = tb; this.imageViewModel.ClearPositions(); }