图像插值C#2010
我正在使用此图像: 我想在不混合颜色的情况下对其进行超大尺寸调整。有没有办法用C#中的颜色混合来放大它?我在网上查过,但所有的方法似乎都不成功 我应该向大家展示一下我是如何把图像放到屏幕上的 游戏1:(设置整个程序) } 图像:(加载图像以供使用) 编辑:(10:21_11/26/2013)图像插值C#2010,c#,image,visual-studio-2010,xna,interpolation,C#,Image,Visual Studio 2010,Xna,Interpolation,我正在使用此图像: 我想在不混合颜色的情况下对其进行超大尺寸调整。有没有办法用C#中的颜色混合来放大它?我在网上查过,但所有的方法似乎都不成功 我应该向大家展示一下我是如何把图像放到屏幕上的 游戏1:(设置整个程序) } 图像:(加载图像以供使用) 编辑:(10:21_11/26/2013) 我正接近尾声,但需要更多的帮助,我正在准备使用SpriteBatch.Begin方法以及它们所做的事情,但仍然丢失了,我希望在这个问题上得到一些帮助。如果我正确地解释了您的问题,您希望放大图像而不使其变得
我正接近尾声,但需要更多的帮助,我正在准备使用
SpriteBatch.Begin方法
以及它们所做的事情,但仍然丢失了,我希望在这个问题上得到一些帮助。如果我正确地解释了您的问题,您希望放大图像而不使其变得模糊,因此,不要使用任何“智能”调整大小您只想使用“最近邻”方法增加大小。
您可以这样做:
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等
我从这里得到了解决方案:
通过添加
spriteBatch.Begin(SpriteSortMode.FrontToBack、BlendState.AlphaBlend、samplestate.PointClamp、DepthStencilState.Default、RasterizerState.cull逆时针)代码>我能够解决这个问题。现在一切都按我需要的方式运行。如果我使用向量,它将非常小,无法被看到。我需要增加它的大小,而不丢失它的全色并保持它应有的颜色。请理解:我希望有一个矩形来纠正大小,并保持它与小时候一样好。你是指可以容纳无限量信息的向量
,还是定位屏幕上的图像。我刚才用画笔放大图像并将其放大,但这意味着每个图像都必须有完全相同的放大,可能会搞乱整个游戏。为什么我可以放大图像并保持图像不模糊,而C#不能这样做。位图不在构造函数中,您知道要添加什么类型的构造函数吗。(示例:使用Microsoft.Xna.Framework.Graphics;
)我也不知道如果加载了(图像
),它的大小和放在屏幕上(标题屏幕
),或者它是绘制的(游戏1
)。您可以使用快捷方式空格+。获取自动导入建议。您需要这两个:使用System.Drawing;使用System.Drawing.Drawing2D;此时,它表示名称空间“System”中不存在类型或名称空间名称“Drawing”。我需要设置绘图吗?我现在可以添加绘图了。我有方法,但对如何将其放入图像中感到困惑,是否需要将其用于所有图像,如果需要,我是否将其放入?对不起,我不考虑XNA,也许此线程可以帮助您:
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
}
}
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
}
}
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;
}