Reputation: 322
I am using this 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.
Upvotes: 0
Views: 789
Reputation: 322
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.
Upvotes: 1
Reputation: 1971
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
Upvotes: 0