本文整理汇总了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( );
}
示例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;
}
}
}
示例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;
}
}
//}
}
示例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;
//.........这里部分代码省略.........