Tag: 位图

如何扩展Bitmap类

我正在尝试扩展Bitmap类,以便我可以将自己的效果应用于图像。 当我使用这段代码时: namespace ImageEditor { public class Effects : System.Drawing.Bitmap { public void toBlackAndWhite() { System.Drawing.Bitmap image = (Bitmap)this; AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(); this = filter.Apply(this); } } } 我收到以下错误: ‘ImageEditor.Effects’: cannot derive from sealed type ‘System.Drawing.Bitmap’ 那么有没有办法绕过这个或者根本不可能扩展这个类? 谢谢。

如何让我的游戏引擎更快(GDI +,C#)

我目前正在使用GDI在C#中构建2D游戏引擎。 我知道有更好的GDI替代方案,但我对项目的处理也很深入,现在我无法回头。 所以,我目前有一个图形引擎,根据我的相机位置和窗口大小呈现位图的一部分,这给了我很大的性能提升。 大! 但是,我注意到如果我放置一堆游戏对象,在相同的位置,我得到相同的帧速率,如果我将对象放在不同的位置。 那么,也许图形引擎渲染的位图部分不需要渲染? 如果是这种情况我该如何解决? 我相信代码并不是真的需要,但只是为了确保这是我的图形引擎在我的主游戏循环中所做的事情 namespace GameEngine.Graphics { public class GraphicsEngine { private Window window; private View view; private System.Drawing.Graphics frontBuffer; private System.Drawing.Graphics backBuffer; private System.Drawing.Bitmap backBufferBitmap; public GraphicsEngine(Window window, View view) { this.window = window; this.view = view; frontBuffer = window.CreateGraphics(); backBufferBitmap = new Bitmap((int)view.Size.X, (int)view.Size.Y); backBuffer = System.Drawing.Graphics.FromImage(backBufferBitmap); frontBuffer.CompositingMode = […]

如何从winform控件生成位图?

如何使用C#在winform上生成控件的位图?

Bitmap.Maketransparent函数的结果不同

我的问题是我想让图像背景透明。 以下function对我来说很好,但在不同的机器上测试时,我发现有很多神器颜色,透明度不像我的机器和其他机器那样清晰。 我正在使用调试版本,测试是在发布版本上完成的。 但即使使用发布版本,我们也会在不同的计算机上看到不同 Image CreateTransparentBackgroundImage(Image image) { using (Bitmap tempBitmap = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)) { var g = Graphics.FromImage(tempBitmap); Rectangle rec = new Rectangle(0 ,0,image.Width, image.Height); g.DrawImage(image,rec, 0, 0,image.Width,image.Height, GraphicsUnit.Pixel); tempBitmap.MakeTransparent(System.Drawing.Color.White); g.Dispose(); return (Image)tempBitmap.Clone(); } } 任何帮助将非常感激。

将BitmapImage加载到WriteableBitmap中但不存在任何方法

使用Windows 8的WriteableBitmap类的构造函数只接受两个参数:此对象的高度和宽度。 与Silverlight同时,它接受一个BitmapImage对象作为参数。 (在MSDN上validation: WriteableBitmap.WriteableBitmap构造函数 ) 我想加载这个BitmapImage因为我试图模糊我的Assets文件夹中已经存在的图像。

如何有效地裁剪和缩放图像数据

我需要对图像中的像素值进行操作。 因此我写了这样一堂课: public class image_class { #region property public int width { get; private set; } public int height { get; private set; } byte[] buffer; #endregion #region constructors public image_class() { ; } public image_class(int Width, int Height, byte[] data) { if (data.Count() == (Width * Height * 3)) { this.width = Width; this.height […]

Bitmap.Save,巨大的内存泄漏

我有一个应用程序,我正在使用位图并使用GZipStream压缩它并通过套接字将其发送到内存中。 我已经将脏的scumbag内存泄漏跟踪到以​​下行: frame.Save(inStream, jpegCodec, parameters); 浏览好的信息高速公路我发现了很多关于Image类泄漏内存的主题在各种编解码器的保存方法中。 问题是我找不到任何修复方法。 所以我的问题如下: 是什么原因造成的 我怎样才能解决这个问题 这是我的FrameStream类中的完整Write()方法,其中包含泄漏。 /// /// Writes a frame to the stream /// /// The frame to write public void Write(Bitmap frame) { using (EncoderParameter qualityParameter = new EncoderParameter(Encoder.Quality, 50L)) { using (EncoderParameters parameters = new EncoderParameters(1)) { parameters.Param[0] = qualityParameter; ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo jpegCodec = […]

C#OpenTK – 纹理四边形

我最近下载了OpenTK。 我创建了一个基本的游戏类和四元组。 我尝试在我的四边形中渲染纹理,但它不起作用。 这是我的代码。 这是纹理的加载。 (纹理类只包含一个ID和一个Bitmap.GetWidth()和GetHeight()只返回Bitmap.Width和Bitmap.Height)。 Texture Texture = new Texture (); Texture.Bitmap = new Bitmap (Path); Texture.ID = GL.GenTexture (); GL.BindTexture (TextureTarget.Texture2D, Texture.ID); BitmapData data = Texture.Bitmap.LockBits (new Rectangle (0, 0, Texture.GetWidth (), Texture.GetHeight ()), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Texture.GetWidth(), Texture.GetHeight(), 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.Bitmap, data.Scan0); Texture.Bitmap.UnlockBits (data); GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear); GL.TexParameter […]

图像属性的值(C#)

我正在尝试解决为Bitmap对象更改值ImageDescription的问题。 添加文件的描述。 搜索相关主题,我还没有找到解决方案。 我的代码: public Bitmap ImageWithComment(Bitmap image) { string filePath = @”C:\1.jpg”; var data = Encoding.UTF8.GetBytes(“my comment”); var propItem = image.PropertyItems.FirstOrDefault(); propItem.Type = 2; propItem.Id = 40092; propItem.Len = data.Length; propItem.Value = data; image.SetPropertyItem(propItem); image.Save(filePath); return image; } 但带有新评论的图片不保存在文件夹中((请帮帮我

Bitmap.Save保存图标实际上可以保存.png

我需要编写一个程序,根据tileset图像生成108个图标组合(标准窗口.ico文件)。 我使用System.Drawing.Bitmap类来构建每个组合,我将它们保存为: Bitmap IconBitmap = new Bitmap(16, 16); // Some processing, writing different parts of the source tileset // … IconBitmap.Save(Path.Combine(TargetPath, “Icon” + Counter + “.ico”), ImageFormat.Icon); 但我发现保存的文件实际上是PNG。 Windows资源管理器和Visual Studio都无法正确显示它,但GIMP可以,如果我在Hex查看器中打开它,这就是我所看到的: 00000000 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 ‰PNG……..IHDR 00000010 00 00 00 10 00 00 […]