0

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

4

1 回答 1

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));
}
于 2012-04-06T08:08:51.583 回答