0

I am using this image:

Image

I want to super size it with out the mixing of colors. Is there a way to just enlarge it with color mixing in C#? I have looked up online but all methods seem void of success.

I should show how I am going through putting the images in on screen.

Game1: (Sets up the whole program)

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace **
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    enum GameStates { StartUp, TitleScreen, Options, Credits, Paused, Playing, Death, Continue }
    GameStates gameState = GameStates.TitleScreen;

    public static int screenHeight = 768;
    public static int screenWidth = 1024;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";

        graphics.PreferredBackBufferHeight = screenHeight;
        graphics.PreferredBackBufferWidth = screenWidth; 
        graphics.IsFullScreen = false; 
        graphics.ApplyChanges();

        StartUp.Images.Content = Content;
    }

    protected override void Initialize()
    {
        this.IsMouseVisible = true;
        base.Initialize();
    }

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);

        StartUp.Images.Load();
    }

    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        switch (gameState)
        {
            case GameStates.StartUp:
                break;
            case GameStates.TitleScreen:
                break;
            case GameStates.Options:
                break;
            case GameStates.Credits:
                break;
        }

        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin();

        if (gameState == GameStates.TitleScreen ||
            gameState == GameStates.Options ||
            gameState == GameStates.Credits)
        {
            spriteBatch.Draw(StartUp.Images.Background, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
        }

        if (gameState == GameStates.TitleScreen)
        {
            StartUp.TitleScreen.Draw(spriteBatch);
        }

        if (gameState == GameStates.Options)
        {
            StartUp.Options.Draw(spriteBatch);
        }

        spriteBatch.End();
        base.Draw(gameTime);
    }
}

}

Images: (Loads the images for use)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace **.StartUp
{
    class Images
    {
        #region Define
        public static ContentManager Content;

        //TitleScreen
        public static Texture2D Background;
        public static Texture2D Continue;
        public static Texture2D Credits;
        public static Texture2D Exit;
        public static Texture2D Logo;
        public static Texture2D Options;
        public static Texture2D Play;
        public static Texture2D Version;
        //End

        //Options
        public static Texture2D OptionsLogo;
        public static Texture2D OffNotSelected;
        public static Texture2D OffSelected;
        public static Texture2D OnNotSelected;
        public static Texture2D OnSelected;
        public static Texture2D FullScreen;
        public static Texture2D Menu;
        public static Texture2D Music;
        public static Texture2D SliderBackground;
        public static Texture2D Slider;
        public static Texture2D SoundFX;
        //End
        #endregion

        #region Load
        public static void Load()
        {
            Background = Content.Load<Texture2D>(@"Images\StartUp\Background");
            Continue = Content.Load<Texture2D>(@"Images\StartUp\Continue");
            Credits = Content.Load<Texture2D>(@"Images\StartUp\Credits");
            Exit = Content.Load<Texture2D>(@"Images\StartUp\Exit");
            FullScreen = Content.Load<Texture2D>(@"Images\StartUp\FullScreen");
            Logo = Content.Load<Texture2D>(@"Images\StartUp\Logo");
            Menu = Content.Load<Texture2D>(@"Images\StartUp\Menu");
            Music = Content.Load<Texture2D>(@"Images\StartUp\Music");
            OffNotSelected = Content.Load<Texture2D>(@"Images\StartUp\OffNotSelected");
            OffSelected = Content.Load<Texture2D>(@"Images\StartUp\OffSelected");
            OnNotSelected = Content.Load<Texture2D>(@"Images\StartUp\OnNotSelected");
            OnSelected = Content.Load<Texture2D>(@"Images\StartUp\OnSelected");
            Options = Content.Load<Texture2D>(@"Images\StartUp\Options");
            OptionsLogo = Content.Load<Texture2D>(@"Images\StartUp\OptionsLogo");
            Play = Content.Load<Texture2D>(@"Images\StartUp\Play");
            Slider = Content.Load<Texture2D>(@"Images\StartUp\Slider");
            SliderBackground = Content.Load<Texture2D>(@"Images\StartUp\SliderBackground");
            SoundFX = Content.Load<Texture2D>(@"Images\StartUp\SoundFX");
            Version = Content.Load<Texture2D>(@"Images\StartUp\Version");
        }
        #endregion
    }
}

TitleScreen: (Draws the image and positions the image)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace **.StartUp
{
    class TitleScreen
    {
        #region Define
        static new Rectangle con = new Rectangle(330, 246, 364, 84);
        static new Rectangle cre = new Rectangle(330, 430, 364, 84);
        static new Rectangle exit = new Rectangle(330, 522, 364, 84);
        static new Rectangle logo = new Rectangle(216, 37, 591, 71);
        static new Rectangle opt = new Rectangle(330, 338, 364, 84);
        static new Rectangle play = new Rectangle(330, 154, 364, 84);
        static new Rectangle ver = new Rectangle(7, 701, 215, 39);
        static Vector2 love = new Vector2(100, 100);
        #endregion

        #region Update and Draw
        public static void Update(GameTime gameTime)
        {
            MouseState mouse = Mouse.GetState();
        }

        public static void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Images.Continue, con, Color.White);
            spriteBatch.Draw(Images.Credits, cre, Color.White);
            spriteBatch.Draw(Images.Exit, exit, Color.White);
            spriteBatch.Draw(Images.Play, play, Color.White);
            spriteBatch.Draw(Images.Options, opt, Color.White);
            spriteBatch.Draw(Images.Logo, logo, Color.White);
            spriteBatch.Draw(Images.Version, love, Color.White);
        }
        #endregion

        #region Methods
        #endregion
    }
}

EDIT: (10:21_11/26/2013)

I am getting closes but need a little more help, I am readying through SpriteBatch.Begin Methods and what they do but still am lost I would love some help with this problem.

Ryan Foy
  • 322
  • 6
  • 19
  • If I use a vector it will be super small, it will not be able to be seen. I need to increase its size with out it losing its full color and keeping its colors were they should be. – Ryan Foy Nov 26 '13 at 13:51
  • Please understand : http://i.imgur.com/Cgx9AYz.png I would like to have a rectangle to have to correct size and keep it as good as when it was small – Ryan Foy Nov 26 '13 at 13:57
  • Do you mean the `vector` that can hold endless amounts of information or a `vector2` that positions the image on screen. – Ryan Foy Nov 26 '13 at 14:08
  • I used paint just a moment ago to zoom in on the image and super size it, but that would mean that every image would have to have the exact same zoom in and would possible mess up the whole game. Why is it that I can zoom in on the image and keep the image not blurry and C# cant do the same. http://i.imgur.com/CCopnqA.png – Ryan Foy Nov 26 '13 at 14:15

2 Answers2

1

By adding spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise); I was able to fix the problem. Everything now works the way I need.

Ryan Foy
  • 322
  • 6
  • 19
0

If I am correctly interpreting your question you want to enlarge the image without it getting blurry, so instead of any "smart" resizing you just want to increase the size with the "nearest neighbor" method. You can do it like this:

using System.Drawing;
using System.Drawing.Drawing2D;

private Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
{
    Bitmap result = new Bitmap(nWidth, nHeight);
    using (Graphics g = Graphics.FromImage((Image)result))
    {
        g.InterpolationMode = InterpolationMode.NearestNeighbor;
        g.DrawImage(b, 0, 0, nWidth, nHeight);
    }
    return result;
}

Works best with exact multiples: If you have an 50x70 image resize it to 100x140 / 150x210 etc.

I got the solution from here: Resize a bitmap like MS Paint - no antialiasing

Community
  • 1
  • 1
ASA
  • 1,911
  • 3
  • 20
  • 37
  • Bitmap is not in the constructor, do you know what type of constructor to add to this. (example: `using Microsoft.Xna.Framework.Graphics;`) I also dont know if I should place this were it is loaded(`Images`), were its sized and put on the screen(`TitleScreen`) or were it is drawn(`Game1`). – Ryan Foy Nov 26 '13 at 14:22
  • You can use the shortcut SPACE+. to get auto import recommendations. You need those two: using System.Drawing; using System.Drawing.Drawing2D; – ASA Nov 26 '13 at 14:23
  • At thew moment it says that the type or namespace name 'Drawing' does not exist in the namespace 'System'. Do I need to set up drawing? – Ryan Foy Nov 26 '13 at 14:27
  • I was able to add Drawing now. I have the method but am confused on how to put it into the images, does it need to be for all images, if so were do I put it? – Ryan Foy Nov 26 '13 at 14:35
  • Sorry, I disn't regard XNA, maybe this thread can help you: http://stackoverflow.com/questions/9215027/nearest-neighbor-zoom – ASA Nov 26 '13 at 14:51
  • I am confused, how does he use the `spriteBatch.Begin()` and add 5 arguments but it will not allow 1 argument, `SamplerState.PointClamp`, how do I do this, I am not an expert at this and would like a little nudge in the right direction. Sorry for you inconvenience and my thick head. – Ryan Foy Nov 26 '13 at 15:05
  • I fixed the problem using `spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);`, I was doing something with it and `spriteBatch.End()` was having a problem. Now it works to 100 percent. – Ryan Foy Nov 26 '13 at 15:27