简体   繁体   中英

Algorithm to Horizontally flip a raw image in a byte array

How do I flip the image Horizontally when I am working with a byte array. I am having trouble finding the algorithm for doing this, all examples seem to suggest using established graphics libraries which I cannot use.

i used WPF power to flip the image horizontally, hope this help

<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));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM