Feedback

Bitmap in Byte Array schreiben

Sprache: C#

Diese Funktion schreibt ein Image in ein Byte Array. Dieses Array kann somit z.B. einfach in eine DB geschrieben werden.
private byte[] BildToByteArray(Image Bild, ImageFormat Bildformat)
        {            
            MemoryStream IS = new MemoryStream();
            Bild.Save(IS, Bildformat);
            IS.Flush();
            return IS.ToArray();
        }
private byte[] BildToByteArray(Image Bild, ImageFormat Bildformat)
        {            
            MemoryStream IS = new MemoryStream();
            Bild.Save(IS, Bildformat);
            IS.Flush();
            return IS.ToArray();
        }

2 Kommentare

  1. [b]Dieses Array kann somit z.B. einfach in eine DB geschrieben werden.[/b]

    Also ich würde Bilder eher zu Base64 codieren und in die Datenbank schreiben…

    Das Ganze noch auf [b]English[/b], weil ich ein [b]Code-Nazi[/b] bin 😀
    [code]
    private byte[] ImageToByteArray(Image image, ImageFormat imageFormat )
    {
    MemoryStream ms = new MemoryStream();
    image.Save(ms , imageFormat );
    ms.Flush();
    return ms .ToArray();
    }
    [/code]