如何修改位图并在以后使用它而不存储或绘图

时间:2023-01-24 10:14:20

I'm trying to do some ocr by myself in C#. I originally come from Java and this is my first "project" with C#

我想在C#中自己做一些事情。我最初来自Java,这是我用C#的第一个“项目”

So I know, how you can make different ColorMatrizes to draw a processed bitmap in your application. I also do have those, but I want to use the processed picture to better analyze a picture.

所以我知道,如何使用不同的ColorMatrizes在应用程序中绘制处理过的位图。我也有这些,但我想使用处理过的图片来更好地分析图片。

Those are my methods to get a ImageAttribute

这些是获取ImageAttribute的方法

public static ImageAttributes ToGrayscale(Bitmap b)
public static ImageAttributes ToNegative(Bitmap b)
public static ImageAttributes ToSepia(Bitmap b)
public static ImageAttributes SetBrightness(Bitmap b, float Brightness)
public static ImageAttributes SetContrast(Bitmap b, float Contrast)

This is my method to draw it

这是我绘制它的方法

Graphics g = this.CreateGraphics();
g.DrawImage(bmp,new Rectangle(0, 0, bmp.Width, bmp.Height), 
            0, 0, bmp.Width, bmp.Height, 
            GraphicsUnit.Pixel, ImageAnalysis.ToGrayscale(bmp));
g.Dispose(); 

This is what I want:

这就是我要的:

FindLines( setConrast(toGrayscale(bmp),200) )

But I found no method to save the changes permanently to bitmap object. Maybe someone did this before and can help me

但是我找不到将更改永久保存到位图对象的方法。也许有人之前这样做过,可以帮助我

1 个解决方案

#1


Instead of drawing to the screen with this

而不是用这个绘制到屏幕上

Graphics g = this.CreateGraphics();

You create a new bitmap and then you draw onto that bitmap, using a Graphics object obtained like this

您创建一个新的位图,然后使用像这样获得的Graphics对象绘制到该位图

Bitmap bmpNew = new Bitmap( width, height );
Graphics g = Graphics.FromBitmap( bmpNew );

#1


Instead of drawing to the screen with this

而不是用这个绘制到屏幕上

Graphics g = this.CreateGraphics();

You create a new bitmap and then you draw onto that bitmap, using a Graphics object obtained like this

您创建一个新的位图,然后使用像这样获得的Graphics对象绘制到该位图

Bitmap bmpNew = new Bitmap( width, height );
Graphics g = Graphics.FromBitmap( bmpNew );