第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將圖像添加到 C# 中的對象列表

將圖像添加到 C# 中的對象列表

C#
忽然笑 2021-11-28 20:18:42
我正在嘗試在 C# 中創(chuàng)建圖像列表。我的問題是我不確定如何引用圖像以將其添加到列表中。我已經(jīng)嘗試在括號中添加文件路徑,但它拋出錯誤“無法創(chuàng)建抽象類或接口‘Image’的實例”。下面是我嘗試過的示例。我對此很陌生,所以如果有明顯的錯誤或解決方案,我深表歉意。謝謝!:)private void button1_Click(object sender, EventArgs e){    imageList = new List<Image>();    imageOne = new Image("image.jpg");}
查看完整描述

2 回答

?
慕妹3242003

TA貢獻1824條經(jīng)驗 獲得超6個贊

Image是一個抽象類。這意味著你不能new

嘗試從文件

imageOne = Image.FromFile("image.jpg");

它返回一個Image對象,您可以將其添加到列表中


查看完整回答
反對 回復(fù) 2021-11-28
?
婷婷同學(xué)_

TA貢獻1844條經(jīng)驗 獲得超8個贊

如果要從文件加載圖像,可以使用FromFile 方法。


來自 msdn 的例子:


private void Button2_Click(System.Object sender, System.EventArgs e)

{

    try

    {

        Bitmap image1 = (Bitmap) Image.FromFile(@"C:\Documents and Settings\" +

            @"All Users\Documents\My Music\music.bmp", true);


        TextureBrush texture = new TextureBrush(image1);

        texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;

        Graphics formGraphics = this.CreateGraphics();

        formGraphics.FillEllipse(texture, 

            new RectangleF(90.0F, 110.0F, 100, 100));

        formGraphics.Dispose();


    }

    catch(System.IO.FileNotFoundException)

    {

        MessageBox.Show("There was an error opening the bitmap." +

            "Please check the path.");

    }


}

如果要從流加載圖像,也可以使用FromStream 方法。


查看完整回答
反對 回復(fù) 2021-11-28
  • 2 回答
  • 0 關(guān)注
  • 344 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號