• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Imaging.TransformedBitmap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Windows.Media.Imaging.TransformedBitmap的典型用法代码示例。如果您正苦于以下问题:C# TransformedBitmap类的具体用法?C# TransformedBitmap怎么用?C# TransformedBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TransformedBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了TransformedBitmap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ApplyOrientation

        internal static BitmapSource ApplyOrientation(BitmapSource bitmap, BitmapMetadata metadata)
        {
            if (metadata == null || !metadata.ContainsQuery("System.Photo.Orientation"))
                return bitmap;

            ushort orientation = (ushort)metadata.GetQuery("System.Photo.Orientation");

            switch (orientation)
            {
                case 2: // flip horizontal
                    return new TransformedBitmap(bitmap, new ScaleTransform(-1, 1));

                case 3: // rotate 180
                    return new TransformedBitmap(bitmap, new RotateTransform(-180));

                case 4: // flip vertical
                    return new TransformedBitmap(bitmap, new ScaleTransform(1, -1));

                case 5: // transpose
                    bitmap = new TransformedBitmap(bitmap, new ScaleTransform(1, -1));
                    goto case 8;

                case 6: // rotate 270
                    return new TransformedBitmap(bitmap, new RotateTransform(-270));

                case 7: // transverse
                    bitmap = new TransformedBitmap(bitmap, new ScaleTransform(-1, 1));
                    goto case 8;

                case 8: // rotate 90
                    return new TransformedBitmap(bitmap, new RotateTransform(-90));

                default:
                    return bitmap;
            }
        }
开发者ID:digitalcivics,项目名称:happynotez,代码行数:36,代码来源:Helper.cs


示例2: DrawImage

        public static void DrawImage (this ConsoleBuffer @this, ImageSource imageSource, int x, int y, int width, int height)
        {
            var bmp = imageSource as BitmapSource;
            if (bmp == null)
                throw new ArgumentException("Only rendering of bitmap source is supported.");

            @this.OffsetX(ref x).OffsetY(ref y);
            int x1 = x, x2 = x + width, y1 = y, y2 = y + height;
            if ([email protected](ref x1, ref y1, ref x2, ref y2))
                return;

            if (width != bmp.PixelWidth || height != bmp.PixelHeight)
                bmp = new TransformedBitmap(bmp, new ScaleTransform((double)width / bmp.PixelWidth, (double)height / bmp.PixelHeight));
            if (bmp.Format != PixelFormats.Indexed4)
                bmp = new FormatConvertedBitmap(bmp, PixelFormats.Indexed4, BitmapPalettes.Halftone8Transparent, 0.5);

            const int bitsPerPixel = 4;
            int stride = 4 * (bmp.PixelWidth * bitsPerPixel + 31) / 32;
            byte[] bytes = new byte[stride * bmp.PixelHeight];
            bmp.CopyPixels(bytes, stride, 0);

            for (int iy = y1, py = 0; iy < y2; iy++, py++) {
                ConsoleChar[] charsLine = @this.GetLine(iy);
                for (int ix = x1, px = 0; ix < x2; ix++, px++) {
                    int byteIndex = stride * py + px / 2;
                    int bitOffset = px % 2 == 0 ? 4 : 0;
                    SetColor(ref charsLine[ix], bmp.Palette, (bytes[byteIndex] >> bitOffset) & 0xF);
                }
            }
        }
开发者ID:jhorv,项目名称:CsConsoleFormat,代码行数:30,代码来源:ConsoleBufferImageExts.cs


示例3: ResizeAsync

        /// <summary>
        ///     Resizes the image presented by the <paramref name="imageData"/> to a <paramref name="newSize"/>.
        /// </summary>
        /// <param name="imageData">
        ///     The binary data of the image to resize.
        /// </param>
        /// <param name="newSize">
        ///     The size to which to resize the image.
        /// </param>
        /// <param name="keepAspectRatio">
        ///     A flag indicating whether to save original aspect ratio.
        /// </param>
        /// <returns>
        ///     The structure which contains binary data of resized image and the actial size of resized image depending on <paramref name="keepAspectRatio"/> value.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        ///     An error occurred during resizing the image.
        /// </exception>
        public static Task<ImageInfo> ResizeAsync(this byte[] imageData, Size newSize, bool keepAspectRatio)
        {
            var result = new ImageInfo();
            var image = imageData.ToBitmap();
            var percentWidth = (double) newSize.Width/(double) image.PixelWidth;
            var percentHeight = (double) newSize.Height/(double) image.PixelHeight;

            ScaleTransform transform;
            if (keepAspectRatio)
            {
                transform = percentWidth < percentHeight
                                ? new ScaleTransform {ScaleX = percentWidth, ScaleY = percentWidth}
                                : new ScaleTransform {ScaleX = percentHeight, ScaleY = percentHeight};
            }
            else
            {
                transform = new ScaleTransform {ScaleX = percentWidth, ScaleY = percentHeight};
            }

            var resizedImage = new TransformedBitmap(image, transform);

            using (var memoryStream = new MemoryStream())
            {
                var jpegEncoder = new JpegBitmapEncoder();
                jpegEncoder.Frames.Add(BitmapFrame.Create(resizedImage));
                jpegEncoder.Save(memoryStream);

                result.Data = memoryStream.ToArray();
                result.Size = new Size(resizedImage.PixelWidth, resizedImage.PixelHeight);
            }

            return Task.FromResult(result);
        }
开发者ID:mdabbagh88,项目名称:UniversalImageLoader,代码行数:51,代码来源:ByteArrayExtension.cs


示例4: TryGetBitmapTransform

        public bool TryGetBitmapTransform(string optionValue, IEnumerable<KeyValuePair<string, string>> settings, out Func<BitmapSource, BitmapSource> bitmapTransformerFunc)
        {
            var cropOriginFunc = GetCropPointFunc(GetSetting(settings, "cropOrigin", "center,center"));
            var cropSize = GetCropSize(optionValue);

            bitmapTransformerFunc = bitmapSource =>
            {
                double widthScale = cropSize.Width / bitmapSource.PixelWidth;
                double heightScale = cropSize.Height / bitmapSource.PixelHeight;
                double scale = Math.Max(widthScale, heightScale);

                bitmapSource = new TransformedBitmap(bitmapSource, new ScaleTransform(scale, scale));

                var cropOrigin = cropOriginFunc(bitmapSource);
                var x = cropOrigin.X - (cropSize.Width / 2);
                x = Math.Max(0, x);
                x = Math.Min(x, bitmapSource.PixelWidth - cropSize.Width);

                var y = cropOrigin.Y - (cropSize.Height / 2);
                y = Math.Max(0, y);
                y = Math.Min(y, bitmapSource.PixelHeight - cropSize.Height);

                return new CroppedBitmap(bitmapSource, new Int32Rect((int)Math.Round(x), (int)Math.Round(y), (int)cropSize.Width, (int)cropSize.Height));
            };

            return true;
        }
开发者ID:bmbsqd,项目名称:dynamic-media,代码行数:27,代码来源:CropBitmapTransformerFactory.cs


示例5: Shrink

        public void Shrink(string sourcePath)
        {
            Debug.Assert(!String.IsNullOrWhiteSpace(sourcePath));

            BitmapDecoder decoder;
            BitmapEncoder encoder;
            GetBitmapDecoderEncoder(sourcePath, out decoder, out encoder);
            if (decoder == null || encoder == null)
                throw new ArgumentException("Image type is not supported.");

            // NOTE: grab its first (and usually only) frame. Only TIFF and GIF images support multiple frames
            var sourceFrame = decoder.Frames[0];

            // Apply the transform
            var transform = GetTransform(sourceFrame);

            if (transform == null)
                return;

            var transformedBitmap = new TransformedBitmap(sourceFrame, transform);

            // Create the destination frame
            var thumbnail = sourceFrame.Thumbnail;
            var metadata = sourceFrame.Metadata as BitmapMetadata;
            var colorContexts = sourceFrame.ColorContexts;
            var destinationFrame = BitmapFrame.Create(transformedBitmap, thumbnail, metadata, colorContexts);

            encoder.Frames.Add(destinationFrame);

            SaveResultToFile(sourcePath, encoder);
        }
开发者ID:remko-jansen,项目名称:pet-projects,代码行数:31,代码来源:ShrinkingService.cs


示例6: PageLoaded

      public 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);

      }
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:31,代码来源:TransformedImageExample.xaml.cs


示例7: GetTransformedBitmapFromUri

 private TransformedBitmap GetTransformedBitmapFromUri(string uri)
 {
     var bitmap = new Bitmap(uri);
     var requiredRotation = GetRotationFromImage(bitmap);
     var bitmapImage = new BitmapImage(new Uri(uri));
     var transform = new RotateTransform(requiredRotation);
     var tb = new TransformedBitmap(bitmapImage, transform);
     return tb;
 }
开发者ID:bkmr,项目名称:photoclassifier,代码行数:9,代码来源:MainWindowViewModel.cs


示例8: ResizeImage

        private static byte[] ResizeImage(ImageFormat format, BitmapSource photo, double? width, double? height)
        {
            var scaleX = (width.GetValueOrDefault(photo.Width) / photo.Width);
            var scaleY = (height.GetValueOrDefault(photo.Height) / photo.Height);

            var target = new TransformedBitmap(photo, new ScaleTransform(scaleX, scaleY, 0, 0));

            var targetFrame = BitmapFrame.Create(target);
            return targetFrame.ToByteArray(format);
        }
开发者ID:davidwhitney,项目名称:ImageProxyDotNet,代码行数:10,代码来源:ImageSourcingService.cs


示例9: buttonRotate_Click

        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();
        }
开发者ID:sunnyone,项目名称:kiritorimage,代码行数:11,代码来源:MainWindow.xaml.cs


示例10: TransformSave

 public static void TransformSave(BitmapSource bi, double scale, int quality, string filename)
 {
     var tr = new ScaleTransform(scale, scale);
     TransformedBitmap tb = new TransformedBitmap(bi, tr);
     //if (File.Exists(filename)) File.Delete(filename);
     var stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
     JpegBitmapEncoder encoder = new System.Windows.Media.Imaging.JpegBitmapEncoder();
     encoder.QualityLevel = quality;
     encoder.Frames.Add(BitmapFrame.Create(tb));
     encoder.Save(stream);
     stream.Close();
 }
开发者ID:agmarchuk,项目名称:Cassettes,代码行数:12,代码来源:ImageLab.cs


示例11: ShowMyFace

        public ShowMyFace()
        {
            Title = "Show My Face";

            ///******************************************************************
            //  3���� ShowMyFace ����
            //******************************************************************/
            Uri uri = new Uri("http://www.charlespetzold.com/PetzoldTattoo.jpg");
            //BitmapImage bitmap = new BitmapImage(uri);
            //Image img = new Image();
            //img.Source = bitmap;
            //Content = img;

            ///******************************************************************
            //  p1245 BitmapImage �ڵ�
            //******************************************************************/
            Image rotated90 = new Image();
            TransformedBitmap tb = new TransformedBitmap();
            FormatConvertedBitmap fb = new FormatConvertedBitmap();
            CroppedBitmap cb = new CroppedBitmap();

            // Create the source to use as the tb source.
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = uri;
            bi.EndInit();

            //cb.BeginInit();
            //cb.Source = bi;
            //Int32Rect rect = new Int32Rect();
            //rect.X = 220;
            //rect.Y = 200;
            //rect.Width = 120;
            //rect.Height = 80;
            //cb.SourceRect = rect;

            //cb.EndInit();

            fb.BeginInit();
            fb.Source = bi;
            fb.DestinationFormat = PixelFormats.Gray2;
            fb.EndInit();

            // Properties must be set between BeginInit and EndInit calls.
            tb.BeginInit();
            tb.Source = fb;
            // Set image rotation.
            tb.Transform = new RotateTransform(90);
            tb.EndInit();
            // Set the Image source.
            rotated90.Source = tb;
            Content = rotated90;
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:53,代码来源:ShowMyFace.cs


示例12: Convert

        /// <summary>
        /// Converts a bitmap and returns the result.
        /// </summary>
        /// <param name="bitmap">The bitmap to convert.</param>
        /// <returns>The result.</returns>
        public BitmapSource Convert(BitmapSource bitmap)
        {
            BitmapSource result = bitmap;

            if(bitmap.Format != _format)
                result = new FormatConvertedBitmap(result, _format, null, 0);

            if(Rotate != 0)
                result = new TransformedBitmap(result, new RotateTransform(Rotate));

            return result;
        }
开发者ID:skpdvdd,项目名称:Pdf2KT,代码行数:17,代码来源:BitmapSourceConverter.cs


示例13: ResizeImage

        /// <summary>
        /// Resizes the given Image
        /// </summary>
        /// <param name="source"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static BitmapImage ResizeImage(BitmapImage source, int width, int height)
        {
            var target = new TransformedBitmap(
                            source,
                            new ScaleTransform(
                                width / source.Width * 96 / source.DpiX,
                                height / source.Height * 96 / source.DpiY,
                                0, 0));

            var resizedFrame = BitmapFrame.Create(target);

            return FrameToBitmap(resizedFrame);
        }
开发者ID:ElderByte-,项目名称:Archimedes.Patterns,代码行数:20,代码来源:ImageSupport.cs


示例14: EncodeColorAsync

        public async Task EncodeColorAsync(byte[] colorData, BinaryWriter writer)
        {
            await Task.Run(() =>
            {
                var format = PixelFormats.Bgra32;
                int stride = (int)this.Width * format.BitsPerPixel / 8;
                var bmp = BitmapSource.Create(
                    this.Width,
                    this.Height,
                    96.0,
                    96.0,
                    format,
                    null,
                    colorData,
                    stride);
                BitmapFrame frame;
                if (this.Width != this.OutputWidth || this.Height != this.OutputHeight)
                {
                    var transform = new ScaleTransform((double)this.OutputHeight / this.Height, (double)this.OutputHeight / this.Height);
                    var scaledbmp = new TransformedBitmap(bmp, transform);
                    frame = BitmapFrame.Create(scaledbmp);
                }
                else
                {
                    frame = BitmapFrame.Create(bmp);
                }

                var encoder = new JpegBitmapEncoder()
                {
                    QualityLevel = this.JpegQuality
                };
                encoder.Frames.Add(frame);
                using (var jpegStream = new MemoryStream())
                {
                    encoder.Save(jpegStream);

                    if (writer.BaseStream == null || writer.BaseStream.CanWrite == false)
                        return;

                    // Header
                    writer.Write(this.OutputWidth);
                    writer.Write(this.OutputHeight);
                    writer.Write((int)jpegStream.Length);

                    // Data
                    jpegStream.Position = 0;
                    jpegStream.CopyTo(writer.BaseStream);
                }
            });
        }
开发者ID:tonyly,项目名称:Kinect,代码行数:50,代码来源:JpegCodec.cs


示例15: Initialize

		public async void Initialize()
		{
			_tempBitmapFile = await _page.GenerateThumbnail();

			Uri uri = new Uri(_tempBitmapFile.FileName, UriKind.Absolute);
			var image = new BitmapImage();
			image.BeginInit();
			image.CacheOption = BitmapCacheOption.OnLoad;
			image.UriSource = uri;
			image.EndInit();

			TransformedBitmap transformed = new TransformedBitmap(image, new RotateTransform(0));
			Image.Value = transformed;
			IsGeneratingImage.Value = false;
		}
开发者ID:baluubas,项目名称:Magic,代码行数:15,代码来源:DrawingViewModel.cs


示例16: GetBitmapFrame

        private static BitmapFrame GetBitmapFrame(MemoryStream original, int width, int height, BitmapScalingMode mode)
        {
            BitmapDecoder photoDecoder = BitmapDecoder.Create(original, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
            BitmapFrame photo = photoDecoder.Frames[0];

            TransformedBitmap target = new TransformedBitmap(
                photo,
                new ScaleTransform(
                    width / photo.Width * 96 / photo.DpiX,
                    height / photo.Height * 96 / photo.DpiY,
                    0, 0));
            BitmapFrame thumbnail = BitmapFrame.Create(target);
            BitmapFrame newPhoto = Resize(thumbnail, width, height, mode);

            return newPhoto;
        }
开发者ID:keyvan,项目名称:ImageResizer4DotNet,代码行数:16,代码来源:ResizerPrivate.cs


示例17: GenerateThumbnail

        internal static void GenerateThumbnail(Stream image, string path)
        {
            BitmapFrame img = BitmapFrame.Create(image);
            double scale = 300.0 / Math.Min(img.PixelHeight, img.PixelWidth);

            TransformedBitmap scaled = new TransformedBitmap(img, new ScaleTransform(scale, scale));

            int startX = (scaled.PixelWidth - 300) / 2;
            int startY = (scaled.PixelHeight - 300) / 2;
            CroppedBitmap cropped = new CroppedBitmap(scaled, new Int32Rect(startX, startY, 300, 300));

            BitmapSource rotated = ApplyOrientation(cropped, img.Metadata as BitmapMetadata);
            using (Stream t = File.Create(path))
            {
                JpegBitmapEncoder jpg = new JpegBitmapEncoder();
                jpg.Frames.Add(BitmapFrame.Create(rotated));
                jpg.Save(t);
            }
        }
开发者ID:digitalcivics,项目名称:happynotez,代码行数:19,代码来源:Helper.cs


示例18: RotateImage

        public ScannedImagesModel RotateImage( int rotate )
        {
            var bitmap = GetBitmapImage();

            var rotated = new TransformedBitmap();
            rotated.BeginInit();
            rotated.Source = bitmap;
            var transform = new RotateTransform( rotate );
            rotated.Transform = transform;
            rotated.EndInit();

            // get temporary file
            var filename = PathUtility.GetTempFileName();
            var landscape = ( rotate == 90 || rotate == 270 ) ? !Landscape : Landscape;

            SaveImage( rotated, filename );

            return new ScannedImagesModel( filename, landscape );
        }
开发者ID:rbobot,项目名称:rbscan,代码行数:19,代码来源:ScannedImagesModel.cs


示例19: ChoosePictureFromLibrary

        public void ChoosePictureFromLibrary(int maxPixelDimension, int percentQuality, Action<Stream, string> pictureAvailable, Action assumeCancelled)
        {
            var filePicker = new OpenFileDialog();
            filePicker.Filter = "Image Files (*.jpg, *.jpeg)|*.jpg;*.jpeg";
            filePicker.Multiselect = false;

            if (filePicker.ShowDialog() == true)
            {
                try
                {
                    var bm = new Bitmap(filePicker.FileName);
                    if (bm != null)
                    {
                        int targetWidth;
                        int targetHeight;

                        MvxPictureDimensionHelper.TargetWidthAndHeight(maxPixelDimension, bm.Width, bm.Height, out targetWidth, out targetHeight);
                        var transformBM = new TransformedBitmap(ConvertBitmapInBitmapSource(bm), new ScaleTransform(targetWidth / (double)bm.Width, targetHeight / (double)bm.Height));

                        JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                        encoder.QualityLevel = percentQuality;

                        MemoryStream stream = new MemoryStream();
                        encoder.Frames.Add(BitmapFrame.Create(transformBM));
                        encoder.Save(stream);

                        stream.Position = 0;

                        pictureAvailable(stream, filePicker.FileName);
                    }
                }
                catch (ArgumentException)
                {
                    assumeCancelled();
                }
            }
            else
            {
                assumeCancelled();
            }
        }
开发者ID:ChebMami38,项目名称:MvvmCross-Plugins,代码行数:41,代码来源:MvxPictureChooserTask.cs


示例20: DecreaseImage

        private static async Task<ImageAndSource> DecreaseImage(string inputFile)
        {
            var newLenght = maxFileLenght * 3;

            var initialLength = new FileInfo(inputFile).Length;

            var initialImage = await FileToImage(inputFile).ConfigureAwait(false);
            
            while (true)
            {
                using (var scaledImage = new MemoryStream())
                {
                    var scale = Math.Sqrt((((double)newLenght) / initialLength));

                    var transformed = new TransformedBitmap(initialImage, new ScaleTransform(scale, scale));

                    transformed.Freeze();

                    var saver = new JpegBitmapEncoder();

                    saver.Frames.Add(BitmapFrame.Create(transformed));

                    saver.Save(scaledImage);

                    scaledImage.Seek(0, SeekOrigin.Begin);

                    newLenght = newLenght * 4 / 5;

                    if (scaledImage.Length < maxFileLenght)
                    {
                        return new ImageAndSource
                        {
                            image = transformed,
                            source = scaledImage.ToArray()
                        };
                    }
                }
            }
        }
开发者ID:imanushin,项目名称:PhotoDecreaser,代码行数:39,代码来源:PhotoInfo.cs



注:本文中的System.Windows.Media.Imaging.TransformedBitmap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Imaging.WriteableBitmap类代码示例发布时间:2022-05-26
下一篇:
C# Imaging.RenderTargetBitmap类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap