如何在winform中同时显示2个图像

时间:2017-08-16 15:53:58

标签: c# winforms

在winforms中,我有两个用于纵向的图片框,另一个用于Landscape。 做到文件的大小或他们没有同时下载的一些原因,

假设是先下载了人像图像,现在我点击更新按钮显示人像图像, 在我点击更新按钮后下载第二张图片后,它只显示了风景图像。

我需要在下载两张图片后显示两张图片,但在我的情况下,它只显示一张图片(最新下载的图片)。

我该怎么做,这是代码。

 private void DisplayLogos(LogoHeader imageHeader)
    {
        if (imageHeader.carId == 2)
        {
            PortraitLabel.Text = "Portrait Image";
            PortraitLabel.Visible = true;
            MemoryStream ms = new MemoryStream(imageHeader.Images.First());
            Image image = Image.FromStream(ms);
            Bitmap bmp = new Bitmap(image);
            PortraitPictureBox.Image = image;
            PortraitPictureBox.Visible = true;
        }
        else if (imageHeader.carId == 1)
        {
            LandscapeLabel.Text = "Landscape Image  ";
            LandscapeLabel.Visible = true;
            MemoryStream ms = new MemoryStream(imageHeader.Images.First());
            LandscapePictureBox.Image = Image.FromStream(ms);
            LandscapePictureBox.Visible = true;
        }                   
    }

public class LogoHeader 
{
    public LogoHeader(Access au, int Id)
    {
        carId = Id;
    }
    public int carId { get; set; }
    public byte[] image{ get; set; }

    public List<byte[]> Images
    {
        get
        {
            List<byte[]> logos = new List<byte[]>();
            logos.Add(image);            
            return logos;
        }

    }
}

1 个答案:

答案 0 :(得分:0)

为了保留图像,您无法关闭(或更改)流,您只需创建另一个。

private void DisplayLogos(LogoHeader imageHeader)
{
    if (imageHeader.carId == 2)
    {
        PortraitLabel.Text = "Portrait Image";
        PortraitLabel.Visible = true;
        MemoryStream ms1 = new MemoryStream(imageHeader.Images.First());
        Image image = Image.FromStream(ms1);
        Bitmap bmp = new Bitmap(image);
        PortraitPictureBox.Image = image;
        PortraitPictureBox.Visible = true;
    }
    else if (imageHeader.carId == 1)
    {
        LandscapeLabel.Text = "Landscape Image  ";
        LandscapeLabel.Visible = true;
        MemoryStream ms2 = new MemoryStream(imageHeader.Images.First());
        LandscapePictureBox.Image = Image.FromStream(ms2);
        LandscapePictureBox.Visible = true;
    }                   
}