|
No, the thing is that I do not know what kind of table I will use in advance. What I need is application that gets a dataset with one table that need to reported! So I do not know how to build a report from a scratch. I know how to set a datasource for report but how to add columns (fields) to it I do not know! Of course if it is possible at all.
|
|
|
|
|
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
|
|
|
|
|
Sorry - that was me - but not signed in. Now I am
---------------------
A gasp of breath,
A sudden death:
The tale begun.
A rustled page
Passes an age:
The tale is done.
|
|
|
|
|
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...
<br />
using System;<br />
<br />
namespace ImageProcessor.Imaging<br />
{<br />
unsafe public struct PixelData<br />
{<br />
public byte Red;<br />
public byte Green;<br />
public byte Blue;<br />
}<br />
}<br />
THE CLASS
<br />
using System;<br />
using System.Drawing;<br />
using System.Drawing.Imaging;<br />
using System.Drawing.Drawing2D;<br />
<br />
namespace ImageProcessor.Imaging<br />
{<br />
<br />
public class Image<br />
{<br />
private String File;<br />
<br />
public String FileName<br />
{<br />
get<br />
{<br />
return File;<br />
}<br />
}<br />
<br />
private int H;<br />
private int W;<br />
<br />
public int Height<br />
{<br />
get<br />
{<br />
return H;<br />
}<br />
}<br />
<br />
public int Width<br />
{<br />
get<br />
{<br />
return W;<br />
}<br />
}<br />
<br />
private Bitmap img;<br />
public Bitmap BitmapImage<br />
{<br />
get<br />
{<br />
return img;<br />
}<br />
}<br />
<br />
private BitmapData Data;<br />
<br />
unsafe private Byte* PBase = null;<br />
private int ByteWidth = 0;<br />
Rectangle Bounds;<br />
<br />
private Image()<br />
{<br />
}<br />
<br />
<br />
unsafe public Image(String Path)<br />
{<br />
File = Path;<br />
img = new Bitmap(File);<br />
<br />
if(img.PixelFormat != PixelFormat.Format24bppRgb)<br />
throw new ImageProcessor.Exceptions.Imaging.InvalidImageFormatException("Invalid Image Format. Expecting: Format24bppRgb Provided: " + img.PixelFormat.ToString());<br />
<br />
Data = null;<br />
<br />
H = this.img.Height;<br />
W = this.img.Width;<br />
<br />
GraphicsUnit Unit = GraphicsUnit.Pixel;<br />
RectangleF BoundsF = img.GetBounds(ref Unit);<br />
<br />
Bounds = new Rectangle((int) BoundsF.X,(int) BoundsF.Y,(int) BoundsF.Width,(int) BoundsF.Height);<br />
ByteWidth = (int) BoundsF.Width * sizeof(PixelData);<br />
<br />
if (ByteWidth % 4 != 0)<br />
ByteWidth = 4 * (ByteWidth / 4 + 1);<br />
}<br />
<br />
<br />
unsafe public Image(int w,int h)<br />
{<br />
File = this.GetHashCode().ToString() + ".bmp";<br />
img = new Bitmap(w,h,PixelFormat.Format24bppRgb);<br />
Data = null;<br />
<br />
H = this.img.Height;<br />
W = this.img.Width;<br />
<br />
GraphicsUnit Unit = GraphicsUnit.Pixel;<br />
RectangleF BoundsF = img.GetBounds(ref Unit);<br />
<br />
Bounds = new Rectangle((int) BoundsF.X,(int) BoundsF.Y,(int) BoundsF.Width,(int) BoundsF.Height);<br />
ByteWidth = (int) BoundsF.Width * sizeof(PixelData);<br />
<br />
if (ByteWidth % 4 != 0)<br />
ByteWidth = 4 * (ByteWidth / 4 + 1);<br />
}<br />
<br />
<br />
unsafe public Image(Bitmap bmp)<br />
{<br />
File = this.GetHashCode().ToString() + ".bmp";<br />
img = bmp;<br />
Data = null;<br />
<br />
H = this.img.Height;<br />
W = this.img.Width;<br />
<br />
GraphicsUnit Unit = GraphicsUnit.Pixel;<br />
RectangleF BoundsF = img.GetBounds(ref Unit);<br />
<br />
Bounds = new Rectangle((int) BoundsF.X,(int) BoundsF.Y,(int) BoundsF.Width,(int) BoundsF.Height);<br />
ByteWidth = (int) BoundsF.Width * sizeof(PixelData);<br />
<br />
if (ByteWidth % 4 != 0)<br />
ByteWidth = 4 * (ByteWidth / 4 + 1);<br />
}<br />
<br />
<br />
unsafe public Color GetPixelAt(int x,int y)<br />
{<br />
this.LockImage();<br />
PixelData *temp = (PixelData*) (PBase + y * ByteWidth + x * sizeof(PixelData));<br />
this.UnlockImage();<br />
<br />
return Color.FromArgb(temp->Red,temp->Green,temp->Blue);<br />
}<br />
<br />
<br />
unsafe public Color GetPixelAtChecked(int x,int y)<br />
{<br />
if(x >= img.Width || y >= img.Height)<br />
throw new ImageProcessor.Exceptions.Imaging.ImageIndexOutOfBoundsException(y + " <- " + img.Height);<br />
<br />
this.LockImage();<br />
PixelData *temp = (PixelData*) (PBase + y * ByteWidth + x * sizeof(PixelData));<br />
this.UnlockImage();<br />
<br />
return Color.FromArgb(temp->Red,temp->Green,temp->Blue);<br />
}<br />
<br />
<br />
unsafe public void SetPixelAt(int x,int y,byte Red,byte Green,byte Blue)<br />
{<br />
this.LockImage();<br />
PixelData *temp = (PixelData*) (PBase + y * ByteWidth + x * sizeof(PixelData));<br />
temp->Red = Red;<br />
temp->Green = Green;<br />
temp->Blue = Blue;<br />
this.UnlockImage();<br />
}<br />
<br />
<br />
unsafe public void SetPixelAt(int x,int y,Color col)<br />
{<br />
this.LockImage();<br />
<br />
PixelData *temp = (PixelData*) (PBase + y * ByteWidth + x * sizeof(PixelData));<br />
temp->Red = col.R;<br />
temp->Green = col.G;<br />
temp->Blue = col.B;<br />
<br />
this.UnlockImage();<br />
}<br />
<br />
<br />
unsafe public void SetPixelAtChecked(int x,int y,byte Red,byte Green,byte Blue)<br />
{<br />
if(x >= img.Width || y >= img.Height)<br />
throw new ImageProcessor.Exceptions.Imaging.ImageIndexOutOfBoundsException();<br />
<br />
this.LockImage();<br />
PixelData *temp = (PixelData*) (PBase + y * ByteWidth + x * sizeof(PixelData));<br />
temp->Red = Red;<br />
temp->Green = Green;<br />
temp->Blue = Blue;<br />
this.UnlockImage();<br />
}<br />
<br />
<br />
unsafe private void LockImage()<br />
{<br />
Data = img.LockBits(Bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);<br />
PBase = (Byte*) Data.Scan0.ToPointer();<br />
}<br />
<br />
<br />
unsafe private void UnlockImage()<br />
{<br />
img.UnlockBits(Data);<br />
Data = null;<br />
PBase = null;<br />
}<br />
<br />
<br />
protected void Finalize()<br />
{<br />
img.Dispose();<br />
}<br />
<br />
<br />
unsafe public Image Clone()<br />
{<br />
Image temp = new Image();<br />
<br />
temp.File = this.File;<br />
temp.img = (Bitmap) this.img.Clone();<br />
<br />
temp.Data = null;<br />
<br />
temp.H = temp.img.Height;<br />
temp.W = temp.img.Width;<br />
<br />
GraphicsUnit Unit = GraphicsUnit.Pixel;<br />
RectangleF BoundsF = img.GetBounds(ref Unit);<br />
<br />
temp.Bounds = new Rectangle((int) BoundsF.X,(int) BoundsF.Y,(int) BoundsF.Width,(int) BoundsF.Height);<br />
temp.ByteWidth = (int) BoundsF.Width * sizeof(PixelData);<br />
<br />
if (temp.ByteWidth % 4 != 0)<br />
temp.ByteWidth = 4 * (temp.ByteWidth / 4 + 1);<br />
<br />
return temp;<br />
}<br />
<br />
<br />
public void SaveImageAs(String FileName)<br />
{<br />
this.img.Save(FileName);<br />
}<br />
<br />
public void ConvertToGreyScale()<br />
{<br />
byte r;<br />
Color c;<br />
<br />
for(int y = 0; y < this.img.Height; y++)<br />
{<br />
for(int x = 0; x < this.img.Width; x++)<br />
{<br />
c = this.GetPixelAt(x,y);<br />
r = (byte)((c.R + c.G + c.B) / 3);<br />
this.SetPixelAt(x,y,r,r,r);<br />
}<br />
}<br />
}<br />
<br />
unsafe public char[] GetBytes()<br />
{<br />
char[] temp = new char[this.Height * this.Width * 3];<br />
PixelData *Pixel;<br />
int index = 0;<br />
<br />
Data = img.LockBits(Bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);<br />
PBase = (Byte*) Data.Scan0.ToPointer();<br />
<br />
for(int y = 0; y < this.Height; y++)<br />
{<br />
for(int x = 0; x < this.Width; x++)<br />
{<br />
Pixel = (PixelData*) (PBase + y * ByteWidth + x * sizeof(PixelData));<br />
temp[index] = (char) Pixel->Red;<br />
temp[index + 1] = (char) Pixel->Green;<br />
temp[index + 2] =(char) Pixel->Blue;<br />
index = index + 3;<br />
}<br />
}<br />
<br />
img.UnlockBits(Data);<br />
Data = null;<br />
PBase = null;<br />
<br />
return temp;<br />
}<br />
<br />
<br />
unsafe public static Image BuildImage(int w, int h, char[] data)<br />
{<br />
if(data.Length != (w*h*3))<br />
throw new Exception("Process of Building Image Failed. Invalid Data Byte Array.");<br />
<br />
Image temp = new Image(w,h);<br />
int index = 0;<br />
PixelData *Pixel;<br />
<br />
temp.Data = temp.img.LockBits(temp.Bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);<br />
temp.PBase = (Byte*) temp.Data.Scan0.ToPointer();<br />
<br />
for(int y = 0; y < h; y++)<br />
{<br />
for(int x = 0; x < w; x++)<br />
{<br />
Pixel = (PixelData*) (temp.PBase + y * temp.ByteWidth + x * sizeof(PixelData));<br />
<br />
Pixel->Red = (byte) data[index];<br />
Pixel->Green = (byte) data[index + 1];<br />
Pixel->Blue = (byte) data[index + 2];<br />
index = index + 3;<br />
}<br />
}<br />
<br />
temp.img.UnlockBits(temp.Data);<br />
temp.Data = null;<br />
temp.PBase = null;<br />
<br />
return temp;<br />
}<br />
<br />
<br />
unsafe static public Image XOR(Image NewFrame,Image PreviousFrame)<br />
{<br />
bool NullTest = true;<br />
<br />
if(NewFrame.Height != PreviousFrame.Height && NewFrame.Width != PreviousFrame.Width)<br />
throw new Exception("Process of XORing Image Failed. Invalid Data Byte Array.");<br />
<br />
Image img = new Image(NewFrame.Width,NewFrame.Height);<br />
PixelData *Pixel1;<br />
PixelData *Pixel2;<br />
<br />
NewFrame.Data = NewFrame.img.LockBits(NewFrame.Bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);<br />
NewFrame.PBase = (Byte*) NewFrame.Data.Scan0.ToPointer();<br />
<br />
PreviousFrame.Data = PreviousFrame.img.LockBits(PreviousFrame.Bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);<br />
PreviousFrame.PBase = (Byte*) PreviousFrame.Data.Scan0.ToPointer();<br />
<br />
for(int y = 0; y < NewFrame.Height; y++)<br />
{<br />
for(int x = 0; x < img.Width; x++)<br />
{<br />
Pixel1 = (PixelData*) (NewFrame.PBase + y * NewFrame.ByteWidth + x * sizeof(PixelData));<br />
Pixel2 = (PixelData*) (PreviousFrame.PBase + y * PreviousFrame.ByteWidth + x * sizeof(PixelData));<br />
<br />
if(Pixel1->Red == Pixel2->Red && Pixel1->Green == Pixel2->Green && Pixel1->Blue == Pixel2->Blue)<br />
img.SetPixelAt(x,y,Color.White.R,Color.White.G,Color.White.B);<br />
else<br />
{<br />
img.SetPixelAt(x,y,Color.Black.R,Color.Black.G,Color.Black.B);<br />
NullTest = false;<br />
}<br />
}<br />
}<br />
<br />
NewFrame.img.UnlockBits(NewFrame.Data);<br />
NewFrame.Data = null;<br />
NewFrame.PBase = null;<br />
<br />
PreviousFrame.img.UnlockBits(PreviousFrame.Data);<br />
PreviousFrame.Data = null;<br />
PreviousFrame.PBase = null;<br />
<br />
if(NullTest)<br />
return null;<br />
else<br />
return img;<br />
}<br />
<br />
public Image ScaleImage(int width, int height)<br />
{<br />
Bitmap result = new Bitmap(width,height);<br />
<br />
Graphics bmpGraphics = Graphics.FromImage(result);<br />
bmpGraphics.InterpolationMode = InterpolationMode.High;<br />
bmpGraphics.SmoothingMode = SmoothingMode.AntiAlias;<br />
<br />
bmpGraphics.DrawImage(this.img, new Rectangle(0, 0, width, height));<br />
<br />
return new Image(result);<br />
}<br />
}<br />
}<br />
---------------------
A gasp of breath,
A sudden death:
The tale begun.
A rustled page
Passes an age:
The tale is done.
|
|
|
|
|
thank you very much!
let me try it!
big thanks!
|
|
|
|
|
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.
|
|
|
|
|
Your class is very helpful, thank you!
I was wondering myself how to do that in C#
Best regards
--
Ralf
|
|
|
|
|
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
|
|
|
|
|
oh!
i found that page editing the unsafe options
thanks!
|
|
|
|
|
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.
|
|
|
|
|
Hi there,
my problem is, that i have to create web references to 10 different servers (i only got there ip) at Runtime. On all of theses servers are running the same web services (i now the name of the provided services). How can i do that? Is there a class where i can create the wsdl, disco, etc. files or do i have to generate them manually?
If i can create the web references, how do the client knows, how to call the web services? (I can't use the "using"-statement, because at compilation the web references aren't created.
I appreciate any help you can give me
Thanks
Sven
|
|
|
|
|
|
|
Hi!
I've developed some c# app which uses some external libraries such as magic (docking manager) and crystal reports. The app works fine, so I wanted to create setup program for it. I've added msi setup project to my solution and pointed external merge modules such as crystal licensing etc. When I try to build my setup, there is an error thrown during msi file creation:
ERROR: Could not find file 'G:\DOCUME~1\hgs\USTAWI~1\Temp\VSDB.tmp\reportengine.A95D0BB4_0582_442D_B456_D295EAEB7628\Program Files\Common Files\Crystal Decisions\2.0\bin\crxf_html_res_en.dll' 'Interface is not registered.'
The file crxf* is included in msm files, so why the compiler needs it at external location?
When I decided to remove crystal libraries (for testing purposes), similar error was thrown on Magic.dll which is pointed directly in project references. When I've excluded all of dependent libraries, the error thrown was:
ERROR: Could not find file 'E:\praca\23.09\17.30\WindowsApplication21\obj\Release\WindowsApplication21.exe' ''Interface is not registered.'
WindowsApplication21.exe is my project output file.
What is going wrong?
Did I miss something?
thanks
h.
|
|
|
|
|
is it possible to tell if a socket is already bound ..or in listening state ?
Thanks for your time.
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
Hi!
Naive question 101: what is the easier method (not necesarily the most performant) to blit a System.Drawing.Image into a DirectDraw.Surface?
Thanks in advance,
--
Ralf
|
|
|
|
|
Wouldn't something like this work?
(assuming surface is 'mySurface' and Image is 'myImage')
System.IntPtr pDC = mySurface.GetDC();
Graphics g = Graphics.FromHdc( pDC );
g.DrawImage( myImage, ..... );
g.ReleaseHdc( pDC );
The key is to remember to release the Device Context, or else you'll leak resources.
Let me know if this works (not in front of Studio at the moment)
Jeremy Kimball
|
|
|
|
|
Thanks, I'm going to try this approach too.
In the meantime, I found out that a DirectDraw.Surface can be created directly out of a Bitmap:
SurfaceDescription desc = new SurfaceDescription();
desc.SurfaceCaps.OffScreenPlain = true;
desc.Width = width;
desc.Height = height;
Surface surf = new Surface(bitmap, desc, localDevice);
It's then easy to use Surface.Draw to blit the surface into another.
Your method would let me reuse the same surface always though, so it seems better.
Regards
--
Ralf
|
|
|
|
|
hi,
i want my richtextbox scroll down to show the bottom text after i appended a new text in it automatically.
i did sth similar in VC++ ListBox with SetTopIndex().
would anyone give me some idea how to do it in C# 's RichTextBox control?
thanks,
jim
|
|
|
|
|
i had the same problem before to jim..but i was able to overcome it with something like...
<br />
<br />
public void AppendText(string Message)<br />
{<br />
if(this.TextArea.Text!=null)<br />
this.TextArea.Text +=Message+System.Environment.NewLine;<br />
else<br />
this.TextArea.Text = Message+System.Environment.NewLine;<br />
this.TextArea.Select();<br />
this.TextArea.Select(TextArea.Text.Length-1,TextArea.Text.Length);<br />
this.TextArea.ScrollToCaret();<br />
}<br />
that should fix it.....as always..im sure there might be a better way..but it seemed to work for me.
The Code Project Is Your Friend...
|
|
|
|
|
Set the caret position to the end of the text, and use the ScrollToCaret() method to scroll to the caret position. Be sure to have HideSelection set to false, or it won't work. (I don't know how many times people have asked about why ScrollToCaret doesn't work, when they have HideSelection on! )
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
|
I am a newbie at design, and I've been studying design patterns but I can't figure what to do in this case.
I have a security object that has properties for a list of fields that also happen to be the properties of another object.
class security {
//"true" value for each property means yes, user has permission to access these fields in client
bool ssNumber;
bool hourlyRate;
bool dateOfBirth;
//getters and setters, functions to pull data from database, etc.
}
class empInfo {
string ssNumber;
decimal hourlyRate;
DateTime dateOfBirth;
//getters and setters, functions to pull data from database, etc.
}
I need empInfo to be aware as to which of its properties are considered permissible for access by a particular user.
What would be the best way to tell if a particular property in empInfo is allowed access by the user?
Should empInfo be extended to include security class and then when empInfo is instantiated and populated, grab security data then?
Since each field represents a datacolumn on the web, I would like to keep as much data manipulation in the middle tier as possible.
Thanks in advance!
|
|
|
|
|