how to speed up GDI+ without using pointer
-
hi, i read an article by Christian Graus http://www.codeproject.com/cs/media/displacementfilters.asp in which, he showed how to do filter with C#. in my case, i need to some analysis on image in order to do some segmentation, binarization stuffs. i used Bitmap.GetPixel() to access the bitmap. however, it is extremely slow comparing Christian method using Bitmap.Scan0() to get the pointer of bitmap and go thro' the structure in system memory. i want to know any method prevent using pointer in order to access bitmap in high speed? i want to know any other method to speed up the process. and, i don't want to handle the structure of each different image format after employed pointer access. thanks, jim
-
hi, i read an article by Christian Graus http://www.codeproject.com/cs/media/displacementfilters.asp in which, he showed how to do filter with C#. in my case, i need to some analysis on image in order to do some segmentation, binarization stuffs. i used Bitmap.GetPixel() to access the bitmap. however, it is extremely slow comparing Christian method using Bitmap.Scan0() to get the pointer of bitmap and go thro' the structure in system memory. i want to know any method prevent using pointer in order to access bitmap in high speed? i want to know any other method to speed up the process. and, i don't want to handle the structure of each different image format after employed pointer access. thanks, jim
Can't you build a wrapper arround the unsafe code? I mean create a class which does that. I have done it, and if you say, I can paste the whole code here too... its MUCH faster then the Bitmap provided by .NET. Actually in .NET they have written a thin wrapper arround the old GDI so thats why it is too slow. Anyway, let me know if you want to get password. mE
-
Can't you build a wrapper arround the unsafe code? I mean create a class which does that. I have done it, and if you say, I can paste the whole code here too... its MUCH faster then the Bitmap provided by .NET. Actually in .NET they have written a thin wrapper arround the old GDI so thats why it is too slow. Anyway, let me know if you want to get password. mE
-
hi, i read an article by Christian Graus http://www.codeproject.com/cs/media/displacementfilters.asp in which, he showed how to do filter with C#. in my case, i need to some analysis on image in order to do some segmentation, binarization stuffs. i used Bitmap.GetPixel() to access the bitmap. however, it is extremely slow comparing Christian method using Bitmap.Scan0() to get the pointer of bitmap and go thro' the structure in system memory. i want to know any method prevent using pointer in order to access bitmap in high speed? i want to know any other method to speed up the process. and, i don't want to handle the structure of each different image format after employed pointer access. thanks, jim
Here is the code... Instead of making Bitmap object, make object of this class, constructors are more then enough :) I claim that it VERY FAST as compared to GDI of .NET... the operation done by GDI in 9 seconds will be done in 3 seconds.. with same ease! Don foget to compile with /unsafe switch... A structure me using...
using System; namespace ImageProcessor.Imaging { /// /// This structure contains structure information to be used in Facer.Imaging.BitmapImage.FaceRImage Class. /// unsafe public struct PixelData { public byte Red; public byte Green; public byte Blue; } }
THE CLASSusing System; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; namespace ImageProcessor.Imaging { /// /// Summary description for BitmapImage. /// public class Image { private String File; public String FileName { get { return File; } } private int H; private int W; public int Height { get { return H; } } public int Width { get { return W; } } private Bitmap img; public Bitmap BitmapImage { get { return img; } } private BitmapData Data; unsafe private Byte* PBase = null; private int ByteWidth = 0; Rectangle Bounds; private Image() { } unsafe public Image(String Path) { File = Path; img = new Bitmap(File); if(img.PixelFormat != PixelFormat.Format24bppRgb) throw new ImageProcessor.Exceptions.Imaging.InvalidImageFormatException("Invalid Image Format. Expecting: Format24bppRgb Provided: " + img.PixelFormat.ToString()); Data = null; H = this.img.Height; W = this.img.Width; GraphicsUnit Unit = GraphicsUnit.Pixel; RectangleF BoundsF = img.GetBounds(ref Unit); Bounds = new Rectangle((int) BoundsF.X,(int) BoundsF.Y,(int) BoundsF.Width,(int) BoundsF.Height); ByteWidth = (int) BoundsF.Width * sizeof(PixelData); if (ByteWidth % 4 != 0) ByteWidth = 4 * (ByteWidth / 4 + 1); } unsafe public Image(int w,int h) { File = this.GetHashCode().ToString() + ".bmp"; img = new Bitmap(w,h,PixelFormat.Format24bppRgb); Data = null; H = this.img.Height; W = this.img.Width; GraphicsUnit Unit = GraphicsUnit.Pixel; RectangleF BoundsF = img.GetBounds(ref Unit); Bounds = new Rectangle((int) BoundsF.X,(int) BoundsF.Y,(int) BoundsF
-
Here is the code... Instead of making Bitmap object, make object of this class, constructors are more then enough :) I claim that it VERY FAST as compared to GDI of .NET... the operation done by GDI in 9 seconds will be done in 3 seconds.. with same ease! Don foget to compile with /unsafe switch... A structure me using...
using System; namespace ImageProcessor.Imaging { /// /// This structure contains structure information to be used in Facer.Imaging.BitmapImage.FaceRImage Class. /// unsafe public struct PixelData { public byte Red; public byte Green; public byte Blue; } }
THE CLASSusing System; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; namespace ImageProcessor.Imaging { /// /// Summary description for BitmapImage. /// public class Image { private String File; public String FileName { get { return File; } } private int H; private int W; public int Height { get { return H; } } public int Width { get { return W; } } private Bitmap img; public Bitmap BitmapImage { get { return img; } } private BitmapData Data; unsafe private Byte* PBase = null; private int ByteWidth = 0; Rectangle Bounds; private Image() { } unsafe public Image(String Path) { File = Path; img = new Bitmap(File); if(img.PixelFormat != PixelFormat.Format24bppRgb) throw new ImageProcessor.Exceptions.Imaging.InvalidImageFormatException("Invalid Image Format. Expecting: Format24bppRgb Provided: " + img.PixelFormat.ToString()); Data = null; H = this.img.Height; W = this.img.Width; GraphicsUnit Unit = GraphicsUnit.Pixel; RectangleF BoundsF = img.GetBounds(ref Unit); Bounds = new Rectangle((int) BoundsF.X,(int) BoundsF.Y,(int) BoundsF.Width,(int) BoundsF.Height); ByteWidth = (int) BoundsF.Width * sizeof(PixelData); if (ByteWidth % 4 != 0) ByteWidth = 4 * (ByteWidth / 4 + 1); } unsafe public Image(int w,int h) { File = this.GetHashCode().ToString() + ".bmp"; img = new Bitmap(w,h,PixelFormat.Format24bppRgb); Data = null; H = this.img.Height; W = this.img.Width; GraphicsUnit Unit = GraphicsUnit.Pixel; RectangleF BoundsF = img.GetBounds(ref Unit); Bounds = new Rectangle((int) BoundsF.X,(int) BoundsF.Y,(int) BoundsF
-
Also... please don look at the name space names... like Facer.Imaging.BitmapImage.FaceRImage.. okay? Another thing, the SetPixelAtChecked is slow as compared to SetPixelAt... coz in checked, the bounds are checked and is good for test-your-algo purpose. if you have any problem, just put it here I will answer it. Also... a request, do let me know whether it helped you or not :) mE --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.
-
Also... please don look at the name space names... like Facer.Imaging.BitmapImage.FaceRImage.. okay? Another thing, the SetPixelAtChecked is slow as compared to SetPixelAt... coz in checked, the bounds are checked and is good for test-your-algo purpose. if you have any problem, just put it here I will answer it. Also... a request, do let me know whether it helped you or not :) mE --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.
-
Also... please don look at the name space names... like Facer.Imaging.BitmapImage.FaceRImage.. okay? Another thing, the SetPixelAtChecked is slow as compared to SetPixelAt... coz in checked, the bounds are checked and is good for test-your-algo purpose. if you have any problem, just put it here I will answer it. Also... a request, do let me know whether it helped you or not :) mE --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.
-
hi, would u tell me how can i enable /unsafe in VS IDE? i don't know why i can't see Build Property Page that the help file tell me..! regards, jim
-
Also... please don look at the name space names... like Facer.Imaging.BitmapImage.FaceRImage.. okay? Another thing, the SetPixelAtChecked is slow as compared to SetPixelAt... coz in checked, the bounds are checked and is good for test-your-algo purpose. if you have any problem, just put it here I will answer it. Also... a request, do let me know whether it helped you or not :) mE --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.
hi, your class is faster than framework's Bitmap class but i found that Christ's method still much much much faster... i did greyscale for 1600x1200 image with 20s. but, christian's application used less than 1s . just a little report. i will check the code to find the reason of this.
-
hi, your class is faster than framework's Bitmap class but i found that Christ's method still much much much faster... i did greyscale for 1600x1200 image with 20s. but, christian's application used less than 1s . just a little report. i will check the code to find the reason of this.
Yes, this is an old story... fight between ease of programmer and the performance. You get best possible speed when you write code in assembly. But you can't write big programs in it. Since machines are faster now, so we compromise performance on ease. Anyway, thank for telling me :) Good Day; mE --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.