Click here to Skip to main content
15,929,263 members
Home / Discussions / C#
   

C#

 
AnswerRe: About Web Printing? Pin
Heath Stewart18-Mar-04 3:41
protectorHeath Stewart18-Mar-04 3:41 
GeneralRe: About Web Printing? Pin
Anonymous23-Mar-04 0:35
Anonymous23-Mar-04 0:35 
GeneralForum Board Pin
mil_an17-Mar-04 13:59
mil_an17-Mar-04 13:59 
GeneralRe: Forum Board Pin
Dave Kreskowiak17-Mar-04 16:57
mveDave Kreskowiak17-Mar-04 16:57 
GeneralRe: Forum Board Pin
Michael Flanakin17-Mar-04 17:58
Michael Flanakin17-Mar-04 17:58 
GeneralRe: Forum Board Pin
Dave Kreskowiak18-Mar-04 1:52
mveDave Kreskowiak18-Mar-04 1:52 
GeneralRe: Forum Board Pin
Michael Flanakin19-Mar-04 9:05
Michael Flanakin19-Mar-04 9:05 
GeneralOptimising Code for Image Blur Pin
damianp17-Mar-04 13:42
damianp17-Mar-04 13:42 
I have created a method to blur an image and was wondering if anyone could find a way of further optimising it for speed.

<br />
		public Bitmap BlurBitmap(Bitmap bitmapToBlur, byte blurLevel)<br />
		{<br />
			DateTime currentTime = DateTime.Now;<br />
<br />
			//get the width and height of the bitmap<br />
			short bitmapWidth = (short)bitmapToBlur.Width;<br />
			short bitmapHeight = (short)bitmapToBlur.Height;<br />
<br />
			//create an array of pixels<br />
			float[,,] colourArray = new float[bitmapWidth, bitmapHeight, 3];<br />
			float[,,] colourArrayBlur = new float[bitmapWidth, bitmapHeight, 3];<br />
<br />
			//populate the array with the pixel info<br />
			for (short i = 0; i < bitmapWidth; i++)<br />
			{<br />
				for (short j = 0; j < bitmapHeight; j++)<br />
				{<br />
					colourArray[i, j, 0] = bitmapToBlur.GetPixel(i, j).R;<br />
					colourArray[i, j, 1] = bitmapToBlur.GetPixel(i, j).G;<br />
					colourArray[i, j, 2] = bitmapToBlur.GetPixel(i, j).B;<br />
				}<br />
			}<br />
<br />
			float redValue = 0.0F;<br />
			float greenValue = 0.0F;<br />
			float blueValue = 0.0F;<br />
			byte counter = 0;<br />
<br />
			//blur<br />
			for (short blurPass = 0; blurPass < blurLevel; blurPass++)<br />
			{<br />
				for (short i = 0; i < bitmapWidth; i++)<br />
				{<br />
					for (short j = 0; j < bitmapHeight; j++)<br />
					{<br />
<br />
						for (sbyte k = -1; k <= 1; k++)<br />
						{<br />
							for (sbyte l = -1; l <= 1; l++)<br />
							{<br />
								if (i + k > 0 && i + k < bitmapWidth && j + l > 0 && j + l < bitmapHeight)<br />
								{<br />
									redValue += colourArray[i + k, j + l, 0];<br />
									greenValue += colourArray[i + k, j + l, 1];<br />
									blueValue += colourArray[i + k, j + l, 2];<br />
									counter++;<br />
								}<br />
							}<br />
						}<br />
<br />
						colourArrayBlur[i, j, 0] = redValue / counter;<br />
						colourArrayBlur[i, j, 1] = greenValue / counter;<br />
						colourArrayBlur[i, j, 2] = blueValue / counter;<br />
												<br />
						redValue = 0.0F;<br />
						greenValue = 0.0F;<br />
						blueValue = 0.0F;<br />
						counter = 0;<br />
					}<br />
				}<br />
<br />
				Trace.WriteLine("blur pass " + blurPass);<br />
				//swap array values<br />
				colourArray = colourArrayBlur;<br />
			}<br />
<br />
			//rebuild the bitmap<br />
			for (short i = 0; i < bitmapWidth; i++)<br />
			{<br />
				for (short j = 0; j < bitmapHeight; j++)<br />
				{<br />
					bitmapToBlur.SetPixel(i, j, Color.FromArgb((int)colourArrayBlur[i, j, 0], (int)colourArrayBlur[i, j, 1], (int)colourArrayBlur[i, j, 2]));<br />
				}<br />
			}<br />
<br />
			Trace.WriteLine(DateTime.Now - currentTime);<br />
<br />
			//return it<br />
			return bitmapToBlur;<br />
		}<br />
	}<br />

GeneralRe: Optimising Code for Image Blur Pin
Heath Stewart17-Mar-04 13:46
protectorHeath Stewart17-Mar-04 13:46 
GeneralRe: Optimising Code for Image Blur Pin
Heath Stewart17-Mar-04 13:49
protectorHeath Stewart17-Mar-04 13:49 
GeneralRe: Optimising Code for Image Blur Pin
damianp17-Mar-04 14:00
damianp17-Mar-04 14:00 
Generalgaining file access from a network Pin
Marveyles17-Mar-04 13:14
Marveyles17-Mar-04 13:14 
GeneralRe: gaining file access from a network Pin
Heath Stewart17-Mar-04 13:28
protectorHeath Stewart17-Mar-04 13:28 
GeneralSimple problem Pin
Gary Kirkham17-Mar-04 11:09
Gary Kirkham17-Mar-04 11:09 
GeneralRe: Simple problem Pin
Heath Stewart17-Mar-04 13:21
protectorHeath Stewart17-Mar-04 13:21 
GeneralRe: Simple problem Pin
Gary Kirkham17-Mar-04 14:08
Gary Kirkham17-Mar-04 14:08 
GeneralRe: Simple problem Pin
Gary Kirkham18-Mar-04 3:32
Gary Kirkham18-Mar-04 3:32 
GeneralDragging controls Pin
PaleyX17-Mar-04 9:43
PaleyX17-Mar-04 9:43 
GeneralRe: Dragging controls Pin
Heath Stewart17-Mar-04 13:20
protectorHeath Stewart17-Mar-04 13:20 
GeneralRe: Dragging controls Pin
PaleyX18-Mar-04 1:08
PaleyX18-Mar-04 1:08 
GeneralAutomatically select first row of datagrid Pin
Code Toad17-Mar-04 9:09
Code Toad17-Mar-04 9:09 
GeneralRe: Automatically select first row of datagrid Pin
Mazdak17-Mar-04 10:28
Mazdak17-Mar-04 10:28 
GeneralMarshaling Arrays Pin
Tristan Rhodes17-Mar-04 7:37
Tristan Rhodes17-Mar-04 7:37 
GeneralRe: Marshaling Arrays Pin
Jeremy Kimball17-Mar-04 8:02
Jeremy Kimball17-Mar-04 8:02 
GeneralRe: Marshaling Arrays Pin
Tristan Rhodes17-Mar-04 8:10
Tristan Rhodes17-Mar-04 8:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.