c#类与图像的混淆

本文关键字:图像 | 更新日期: 2023-09-27 18:08:47

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

任何帮助都将非常感激。谢谢你。

c#类与图像的混淆

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

所以这是我的解决方案

Image logo = new Bitmap("Path");
    public Image getlogo()
    {
        return logo;
    }

不需要setter,因为它是在声明

时设置的。我已经尝试了这个解决方案,它仍然工作,甚至与png,所以给它一个尝试

希望对大家有所帮助