c#类与图像混淆

时间:2013-04-12 16:09:32

标签: c# image class

我正在创建一个项目,它将使用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

}
}

非常感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:1)

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

所以这是我的解决方案

Image logo = new Bitmap("Path");

    public Image getlogo()
    {
        return logo;

    }

当声明

时,不需要设置setter

编辑我已经尝试过这个解决方案,它甚至可以用png工作,所以试一试

希望这有助于享受