亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

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

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

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

2 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

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

嘗試從文件

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

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


查看完整回答
反對 回復 2021-11-28
?
婷婷同學_

TA貢獻1844條經驗 獲得超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 方法。


查看完整回答
反對 回復 2021-11-28
  • 2 回答
  • 0 關注
  • 335 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號