2013-11-26 48 views
0

我使用這個圖片:圖像插值C#2010

Image

我想用出的顏色的混合超級它的大小。有沒有辦法通過C#中的顏色混合來放大它?我在網上查了一下,但所有的方法都沒有成功。

我應該給我怎麼回事,通過把圖像在屏幕上。

的Game1:(設置了整個程序)

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); 
    } 
} 

}

圖片:(載荷使用的圖像)

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:(繪製圖像並定位圖像)

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 
    } 
} 

編輯:(10:21_11/26/2013年)

我正在關閉,但需要多一點幫助,我準備好通過SpriteBatch.Begin Methods和他們做什麼,但還是很失落我喜歡一些幫助,這個問題。

+0

如果我使用矢量,它會超小,它將無法被看到。我需要增加它的尺寸,使它失去其全部顏色並保持它的顏色。 –

+0

請理解:http://i.imgur.com/Cgx9AYz.png我想有一個矩形具有正確的尺寸,並保持它好,因爲當它是小 –

+0

你的意思是'VECTOR',可容納無數的信息或將圖像定位在屏幕上的'vector2'。 –

回答

1

通過添加spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);我能解決這個問題。現在一切都按我需要的方式工作。

0

如果我正確地解釋你的問題,你想放大的圖像沒有它越來越模糊,所以不是任何「聰明」的調整,你只是想增加規模與「近鄰」的方法。 你可以這樣說:

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; 
} 

效果最好確切的倍數: 如果你有一個50x70的圖像也調整到 100x140/150x210等

我從這裏的解決方案: Resize a bitmap like MS Paint - no antialiasing

+0

位圖不在構造函數中,你知道添加到這個構造函數的類型嗎? (例如:'使用Microsoft.Xna.Framework.Graphics;')我也不知道我是否應該把它加載('圖像'),它的大小和放在屏幕上('TitleScreen')還是它被繪製('Game1')。 –

+0

您可以使用快捷鍵SPACE +。獲取自動導入建議。你需要這兩個:使用System.Drawing; using System.Drawing.Drawing2D; – Traubenfuchs

+0

此時它聲明名稱空間「System」中不存在類型或名稱空間名稱「Drawing」。我需要設置繪圖嗎? –