Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Eu quero carregar a imagem do banco de dados em uma caixa de imagem usando LoadAsync e um MemoryStream


Não carregue os bytes na imagem, isso anulará o propósito do que você está tentando alcançar ... (observe que este é um procedimento rápido e sujo para colocar a imagem em um arquivo temporário ... muitas considerações adicionais aqui, incluindo excluir o arquivo temporário quando terminar)
byte[] byteBLOBData = (byte[])ds.Tables["magazine_images"].Rows[c - 1]["image"];
string tempImageFileName = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".jpg");
using( FileStream fileStream = new FileStream(tempImageFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite) ) {
    using( BinaryWriter writer = new BinaryWriter(fileStream) ) {
        writer.Write(byteBLOBData);
    }
}

pictureBox1.LoadCompleted += LoadCompleted;
pictureBox1.WaitOnLoad = false;
pictureBox1.LoadAsync(tempImageFileName);

...
private static void LoadCompleted( object sender, AsyncCompletedEventArgs e ) {
    if( e.Error != null ) {
        // will get this if there's an error loading the file
    } if( e.Cancelled ) {
        // would get this if you have code that calls pictureBox1.CancelAsync()
    } else {
        // picture was loaded successfully
    }
}

veja também o LoadProgressChanged evento