111,126
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="700" Width="700" Background="Green"
>
<Grid>
<TextBlock Name="TB"></TextBlock>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Test
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
BitmapImage bi = new BitmapImage(new Uri("D:\\03.png"));
byte[] b = new byte[4 * bi.PixelWidth * bi.PixelHeight];
Int32Rect rect = new Int32Rect(0, 0, bi.PixelWidth, bi.PixelHeight);
bi.CopyPixels(rect, b, bi.PixelWidth * 4, 0);
for (int i = 1; i <= bi.PixelHeight; i++)
{
for (int j = 1; j <= bi.PixelWidth; j++)
{
int z = 4 * (i - 1) * bi.PixelWidth + 4 * (j - 1);
this.TB.Text += (b[z + 0] + "、" + b[z + 1] + "、" + b[z + 2] + "、" + b[z + 3] + "、 ");
}
this.TB.Text += "\r\n";
}
}
}
}
BitmapImage bi = new BitmapImage(new Uri(@"C:\Users\LionHeart\Pictures\rb.png"));
byte[] b = new byte[4 * bi.PixelWidth * bi.PixelHeight];
Int32Rect rect = new Int32Rect(0, 0, bi.PixelWidth, bi.PixelHeight);
bi.CopyPixels(bi.SourceRect, b, bi.Format.BitsPerPixel * bi.PixelWidth/8, 0);
Bitmap targe = new Bitmap(bi.PixelWidth, bi.PixelHeight);
MemoryStream ms= new MemoryStream(b);
BinaryReader sr= new BinaryReader(ms);
for (int i = 0; i < bi.PixelHeight; i++)
{
for (int j = 0; j < bi.PixelWidth; j++)
{
targe.SetPixel(j, i, Color.FromArgb(sr.ReadInt32()));
}
}
sr.Close();
ms.Close();
pictureBox1.Image = targe;