1

我正在创建一个项目,该项目将使用 a 读取数据文件streamreader并以 Windows 形式显示数据。

然而,该数据文件的属性之一是图像。由于我以前从未真正使用过图像,在 c# 中,我有点困惑。

做一些先前的研究,我创建了一个名为team并设法设置声明的类,Image using System.Drawing;但我不确定我应该如何为具有图像或获取/设置方法的类设置构造函数。

我设法在网上找到的只是该Image课程的一般用途和提示,没有将其放入您自己创建的课程中。这是我到目前为止所拥有的。

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Drawing;

namespace teams_2
{
class Team
{
    string teamName;
    string teamLeague;
    string teamManager;
    string teamNickname;
    string teamStadium;
    int leaguePosistion;
    int leaguePoints;
    int gamesPlayed;
    int goalDifference;
    int playerNumber;
    Image teamLogo; //the problem

    //constructor(image?)
    //team order = teamName teamLeague teamManager teamNickname teamStadium leaguePosistions leaguePoints gamesPlayed goalDifference playerNumber teamLogo

    public Team( string inTeamName, string inTeamLeague, string inTeamManager, string inTeamNickname,
                 string inTeamStadium, int inLeaguePosistion, int inLeaguePoints, int inGamesPlayed,
                 int inGoalDifference, int inPlayerNumber)
    {//
        teamName = inTeamName;
        teamLeague = inTeamLeague;
        teamManager = inTeamManager;
        teamNickname = inTeamNickname;
        teamStadium = inTeamStadium;
        leaguePosistion = inLeaguePosistion;
        leaguePoints = inLeaguePoints;
        gamesPlayed = inGamesPlayed;
        goalDifference = inGoalDifference;
        playerNumber = inPlayerNumber;

    }//end constructor
    //begin getters
    public string getTeamName()
    {
        return teamName;
    }
    public string getTeamLeague()
    {
        return teamLeague;
    }
    public string getTeamManager()
    {
        return teamManager;
    }
    public string getTeamNickname()
    {
        return teamNickname;
    }
    public string getTeamStadium()
    {
        return teamStadium;
    }
    public int getLeaguePosistion()
    {
        return leaguePosistion;
    }
    public int getLeaguePoints()
    {
        return leaguePoints;
    }
    public int getGamesPlayed()
    {
        return gamesPlayed;
    }
    public int getGoalDifference()
    {
        return goalDifference;
    }
    public int getPlayerNumber()
    {
        return playerNumber;
    }
    //end getters

    //begin setters
    public void setTeamName(string inTeamName)
    {
        teamName = inTeamName;
    }
    public void setTeamLeague(string inTeamLeague)
    {
        teamLeague = inTeamLeague;
    }
    public void setTeamManager(string inTeamManager)
    {
        teamManager = inTeamManager;
    }
    public void setTeamNickname(string inTeamNickname)
    {
        teamNickname = inTeamNickname;
    }
    public void setTeamStadium(string inTeamStadium)
    {
        teamStadium = inTeamStadium;
    }
    public void setLeaguePosistion(int inLeaguePosistion)
    {
        leaguePosistion = inLeaguePosistion;
    }
    public void setLeaguePoints(int inLeagePoints)
    {
        leaguePoints = inLeagePoints;
    }
    public void setGamesPlayed(int inGamesPlayed)
    {
        gamesPlayed = inGamesPlayed;
    }
    public void setGoalDifference(int inGoalDifference)
    {
        goalDifference = inGoalDifference;
    }
    public void setPLayerNumber(int inPlayerNumber)
    {
        playerNumber = inPlayerNumber;
    }
    //end setters

}
}

任何帮助将不胜感激。谢谢你。

4

1 回答 1

1

您可能最好使用位图类而不是图像类,因为它允许您从文件路径引用图像

所以这是我的解决方案

Image logo = new Bitmap("Path");

    public Image getlogo()
    {
        return logo;

    }

应该不需要设置器,因为它是在声明时设置的

编辑我已经尝试过这个解决方案,即使使用 png 仍然可以工作,所以试一试

希望这有助于享受

于 2013-04-12T16:38:26.747 回答