用于在字节数组中水平翻转原始图像的算法

时间:2012-04-06 06:29:39

标签: c# image image-processing

当我使用字节数组时,如何水平翻转图像。我无法找到执行此操作的算法,所有示例似乎都建议使用我无法使用的已建立的图形库。

1 个答案:

答案 0 :(得分:0)

我使用WPF功能水平翻转图像,希望这个帮助

<Image Name="image" Stretch="Fill" RenderTransformOrigin="0.5,0.5">
    <Image.RenderTransform>
        <TransformGroup>
            <ScaleTransform ScaleY="1" ScaleX="-1"/>
            <SkewTransform AngleY="0" AngleX="0"/>
            <RotateTransform Angle="0"/>
            <TranslateTransform/>
        </TransformGroup>
    </Image.RenderTransform>
</Image>


public Window2()
{
    InitializeComponent();
    var open = new OpenFileDialog();
    open.ShowDialog();
    var localImage = new Bitmap(open.FileName);
    var stream = new MemoryStream();
    localImage.Save(stream, ImageFormat.Png);

    var byteArray = ImageToByteArray(localImage);
    var imageAgain = ByteArrayToImage(byteArray);

    var imageSource = new BitmapImage();
    imageSource.BeginInit();
    var ms = new MemoryStream();
    imageAgain.Save(ms, ImageFormat.Bmp);
    ms.Seek(0, SeekOrigin.Begin);
    imageSource.StreamSource = ms;
    imageSource.EndInit();

    image.Source = imageSource;
}
public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
    var memoryStream = new MemoryStream();
    imageIn.Save(memoryStream, ImageFormat.Gif);
    return memoryStream.ToArray();
}
public System.Drawing.Image ByteArrayToImage(byte[] byteArrayIn)
{
    return System.Drawing.Image.FromStream(new MemoryStream(byteArrayIn));
}