views:

285

answers:

1

Hi, I'm trying to do some ocr by myself in C#. I originally come from Java and this is my first "project" with 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.

Those are my methods to get a 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

+2  A: 

Instead of doing:
Graphics g = this.CreateGraphics();
to draw to the screen, you create a new bitmap:

Bitmap bmpNew = new Bitmap( width, height );

and then you draw onto that bitmap, using a Graphics object obtained like this:
Graphics g = Graphics.FromBitmap( bmpNew );

danbystrom
thanks, i did this before when I tried to draw a rectangle over a the bmp (e.g. marking found lines for debuggin), but didn't realize this would work the same..Thanks for your help
BeatMe