用图像混淆c#类

用图像混淆c#类,c#,image,class,C#,Image,Class,我正在创建一个项目,该项目将使用streamreader读取数据文件,并以windows窗体显示数据 但是,该数据文件的属性之一是图像。因为我以前从未实际使用过图像,在c#中,我有点困惑 在做了一些前期研究后,我创建了一个名为团队的类,并使用System.Drawing成功地设置了图像的声明但是我不确定如何使用图像或get/setting方法为类设置构造函数 我在网上找到的只是图像类的一般用法和提示,没有什么关于将其放入自己创建的类中的内容。这是我到目前为止所拥有的 using System;

我正在创建一个项目,该项目将使用
streamreader
读取数据文件,并以windows窗体显示数据

但是,该数据文件的属性之一是图像。因为我以前从未实际使用过图像,在c#中,我有点困惑

在做了一些前期研究后,我创建了一个名为
团队
的类,并使用System.Drawing成功地设置了
图像
的声明
但是我不确定如何使用图像或get/setting方法为类设置构造函数

我在网上找到的只是
图像
类的一般用法和提示,没有什么关于将其放入自己创建的类中的内容。这是我到目前为止所拥有的

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

}
}

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

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

这就是我的解决方案

Image logo = new Bitmap("Path");

    public Image getlogo()
    {
        return logo;

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

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


希望这有助于享受

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

这就是我的解决方案

Image logo = new Bitmap("Path");

    public Image getlogo()
    {
        return logo;

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

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


希望这有助于享受

你的能手/二传手有点古怪。。您通常会使用这样的属性:
publicstringpropname{get{return}field;}set{{u field=value;}}
。关于你的问题,你没有理由不能像对待其他字段那样在构造函数中包含
图像
obj。嗨!C#有一种叫做属性(和自动属性)的东西。这是你应该在谷歌上搜索的东西(与你的问题无关,但与你发布的代码有关),你来自Java,不是吗?我按命名约定打电话给泰尔。我认为最好使用属性,而不是getter和setter方法。你对构造函数有什么误解?您实际上希望构造函数做什么?人们是对的,接球手和二传手都很奇怪,但这在技术上并没有什么问题。我能看到的唯一一件事是你没有在任何地方暴露你的图像,所以它只能在课堂上使用?是否要将流传输到图像中?是否要在构造函数中填充它?您打算如何读取图像…有很多问题?图像从正在读取的数据文件中获取路径(这是由其他人完成的),因此我无法再对此进行澄清。我希望在vs2010中的windows上显示该图像,因此我假设我希望将其暴露在那里。您的getter/setter有点奇怪。。您通常会使用这样的属性:
publicstringpropname{get{return}field;}set{{u field=value;}}
。关于你的问题,你没有理由不能像对待其他字段那样在构造函数中包含
图像
obj。嗨!C#有一种叫做属性(和自动属性)的东西。这是你应该在谷歌上搜索的东西(与你的问题无关,但与你发布的代码有关),你来自Java,不是吗?我按命名约定打电话给泰尔。我认为最好使用属性,而不是getter和setter方法。你对构造函数有什么误解?您实际上希望构造函数做什么?人们是对的,接球手和二传手都很奇怪,但这在技术上并没有什么问题。我能看到的唯一一件事是你没有在任何地方暴露你的图像,所以它只能在课堂上使用?是否要将流传输到图像中?是否要在构造函数中填充它?您打算如何读取图像…有很多问题?图像从正在读取的数据文件中获取路径(这是由其他人完成的),因此我无法再对此进行澄清。我想在vs2010中的窗口上显示图像,所以我假设我希望它在那里曝光。谢谢你的回答。不幸的是,该项目中给我们的徽标必须是.png,所以我认为我不能使用它。我的错是没有早点澄清。@zac:请阅读文档:位图类可以阅读PNGSorry,你的措辞让我有了不同的想法哈哈。谢谢,答案非常有效。很高兴它对您有效。请单击我的投票下面的绿色勾号,将我的答案标记为正确,如图所示。谢谢您的回答。不幸的是,该项目中给我们的徽标必须是.png,所以我认为我不能使用它。我的错是没有早点澄清。@zac:请阅读文档:位图类可以阅读PNGSorry,你的措辞让我有了不同的想法哈哈。谢谢你这个答案很好用。很高兴它对你有用。请单击我的投票下面的绿色勾号,将我的答案标记为正确,如图所示。谢谢