当前位置: 首页>>代码示例>>C#>>正文


C# TransformedBitmap.CopyPixels方法代码示例

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


在下文中一共展示了TransformedBitmap.CopyPixels方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Zoom

 private void Zoom( bool zoomIn, double Scale )
 {
     var InverseScale = 1.0 / Scale;
     var transformed = new TransformedBitmap( Bmp, new ScaleTransform( Scale, Scale ) );
     var buffer = new byte[PixelWidth * PixelHeight * 4];
     if ( zoomIn ) {
         var offsetX = Convert.ToInt32( PixelWidth * ( Scale - 1 ) * 0.5 );
         var offsetY = Convert.ToInt32( PixelHeight * ( Scale - 1 ) * 0.5 );
         transformed.CopyPixels( new Int32Rect( offsetX, offsetY, PixelWidth, PixelHeight ), buffer, PixelWidth * 4, 0 );
         Bmp.WritePixels( new Int32Rect( 0, 0, PixelWidth, PixelHeight ), buffer, PixelWidth * 4, 0 );
     } else {
         var offsetX = Convert.ToInt32( PixelWidth * ( 1 - Scale ) * 0.5 );
         var offsetY = Convert.ToInt32( PixelHeight * ( 1 - Scale ) * 0.5 );
         transformed.CopyPixels( new Int32Rect( 0, 0, (int)transformed.Width, (int)transformed.Height ), buffer, PixelWidth * 4, 0 );
         Bmp.WritePixels( new Int32Rect( 0, 0, PixelWidth, PixelHeight ), new byte[PixelWidth * PixelHeight * 4], PixelWidth * 4, 0 ); // Clear
         Bmp.WritePixels( new Int32Rect( offsetX, offsetY, (int)transformed.Width, (int)transformed.Height ), buffer, PixelWidth * 4, 0 );
     }
     RealHeight = RealHeight * InverseScale;
     Draw( );
 }
开发者ID:rbrother,项目名称:Mandelbrot,代码行数:20,代码来源:ComplexFunctionWindow.cs

示例2: GetBitmap

        private System.Drawing.Bitmap GetBitmap(System.Windows.Controls.Image image)
        {
            System.Windows.Media.Imaging.BitmapSource bitmapSource = image.Source as BitmapSource;

            System.Windows.Media.Imaging.BitmapSource transformedBitmapSource = new System.Windows.Media.Imaging.TransformedBitmap(bitmapSource,new System.Windows.Media.ScaleTransform(1,1));

            int width = transformedBitmapSource.PixelWidth;
            int height = transformedBitmapSource.PixelHeight;
            int stride = width * ((transformedBitmapSource.Format.BitsPerPixel + 7) / 8);

            byte[] bits = new byte[height * stride];

            transformedBitmapSource.CopyPixels(bits, stride, 0);
            unsafe
            {
                fixed (byte* pBits = bits)
                {
                    IntPtr ptr = new IntPtr(pBits);

                    System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(
                        width,
                        height,
                        stride,
                        System.Drawing.Imaging.PixelFormat.Format32bppPArgb,
                        ptr);

                    return bitmap;
                }
            }
        }
开发者ID:erspicu,项目名称:ez_stack,代码行数:30,代码来源:MainWindow.xaml.cs

示例3: convertBitmapSourceToBitmap

        private System.Drawing.Bitmap convertBitmapSourceToBitmap(BitmapSource paco)
        {
            //using (Stream stm = File.Open("bitmapsource_to_bitmap.jpg", FileMode.Open, FileAccess.Read))
            //{
                // Since we're not specifying a System.Windows.Media.Imaging.BitmapCacheOption, the pixel format
                // will be System.Windows.Media.PixelFormats.Pbgra32.
                //System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Media.Imaging.BitmapFrame.Create(
                //    stm,
                //    System.Windows.Media.Imaging.BitmapCreateOptions.None,
                //    System.Windows.Media.Imaging.BitmapCacheOption.OnLoad);

                 BitmapSource bitmapSource = paco;       
                // Scale the image so that it will display similarly to the WPF Image.
                double newWidthRatio = image1.Width / (double)bitmapSource.PixelWidth;
                double newHeightRatio = ((image1.Width * bitmapSource.PixelHeight) / (double)bitmapSource.PixelWidth) / (double)bitmapSource.PixelHeight;

                System.Windows.Media.Imaging.BitmapSource transformedBitmapSource = new System.Windows.Media.Imaging.TransformedBitmap(
                    bitmapSource,
                    new System.Windows.Media.ScaleTransform(newWidthRatio, newHeightRatio));

                int width = transformedBitmapSource.PixelWidth;
                int height = transformedBitmapSource.PixelHeight;
                int stride = width * ((transformedBitmapSource.Format.BitsPerPixel + 7) / 8);

                byte[] bits = new byte[height * stride];

                transformedBitmapSource.CopyPixels(bits, stride, 0);

                unsafe
                {
                    fixed (byte* pBits = bits)
                    {
                        IntPtr ptr = new IntPtr(pBits);

                        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(
                            width,
                            height,
                            stride,
                            System.Drawing.Imaging.PixelFormat.Format32bppPArgb,
                            ptr);


                        return bitmap;//picture.Image = bitmap;
                    }
                }
            //}
        }
开发者ID:ravidasghodse,项目名称:genericva,代码行数:47,代码来源:WCamera.xaml.cs

示例4: FilterEffects

        public void FilterEffects()
        {
            if (ImageParameters.Instance.EffectImage != null)
            {
                try
                {
                    BitmapSource b = null;
                    int[] sourceImagePixels = null;
                    int sourceWidth = -1;
                    int sourceHeight = -1;

                    Dispatcher.Invoke(DispatcherPriority.Normal,
                        new DispatcherOperationCallback(delegate(object arg)
                        {
                            BitmapSource bitmap = ImageParameters.Instance.EffectImage;

                            sourceWidth = bitmap.PixelWidth;
                            sourceHeight = bitmap.PixelHeight;

                            sourceImagePixels = new int[sourceWidth * sourceHeight * 4];
                            bitmap.CopyPixels(sourceImagePixels, sourceWidth * 4, 0);

                            return null;
                        }
                    ), null);

                    if (sourceWidth < 0 || sourceHeight < 0 || sourceImagePixels == null)
                    {
                        return;
                    }

                    //Clone so that this thread owns the image
                    b = BitmapSource.Create(sourceWidth, sourceHeight, 96, 96, PixelFormats.Bgra32,
                        null, sourceImagePixels, sourceWidth * 4);

                    /*
                     * Sequence of applying effects and operations to the image is as follows:
                     * 
                     * Crop
                     * Rotate
                     * Flip
                     * Adjustment Filters
                     * Advanced Adjustment Filter
                     * Effects Filters
                     * */

                    if (cropData != Rect.Empty)
                    {
                        // Create a CroppedBitmap based off of a xaml defined resource.
                        b = new CroppedBitmap(b, new Int32Rect(
                            (int)(cropData.X),
                            (int)(cropData.Y),
                            (int)(cropData.Width),
                            (int)(cropData.Height)));
                    }

                    if (ImageParameters.Instance.Rotate != Rotation.Rotate0)
                    {
                        TransformedBitmap rotate = new TransformedBitmap();
                        rotate.BeginInit();

                        double rotationAngle = 0.0;

                        switch (ImageParameters.Instance.Rotate)
                        {
                            case Rotation.Rotate180: rotationAngle = 180.0;
                                break;
                            case Rotation.Rotate270: rotationAngle = 270.0;
                                break;
                            case Rotation.Rotate90: rotationAngle = 90.0;
                                break;
                        }

                        rotate.Source = b;
                        rotate.Transform = new RotateTransform(rotationAngle);
                        rotate.EndInit();

                        int[] pixels = new int[rotate.PixelWidth * rotate.PixelHeight];
                        rotate.CopyPixels(pixels, rotate.PixelWidth * 4, 0);

                        b = BitmapSource.Create(rotate.PixelWidth, rotate.PixelHeight,
                            96, 96, PixelFormats.Bgr32, null, pixels, rotate.PixelWidth * 4);
                    }

                    if (ImageParameters.Instance.Flip != FlipType.None)
                    {
                        TransformedBitmap flip = new TransformedBitmap();
                        flip.BeginInit();

                        double scaleX = 1.0;
                        double scaleY = 1.0;

                        switch (ImageParameters.Instance.Flip)
                        {
                            case FlipType.Horizontal:
                                scaleX = -1.0; break;
                            case FlipType.Vertical:
                                scaleY = -1.0; break;
                            case FlipType.Both:
                                scaleX = scaleY = -1.0; break;
//.........这里部分代码省略.........
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:101,代码来源:Main.xaml.cs


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