473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Faster image processing?

I am defining a bitmap pixel by pixel, and I searched through the documentation,
but could not find an obvious fast way to do what I want. My first attempt used
the underlying graphics object to draw 1 by 1 rectangles. This was SLOOOOOOW.
It took about 1800 milliseconds for a bitmap that was pretty small. Using the
following code, I got it down to 500 milliseconds, but that is still pretty slow.

For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1
bmp.SetPixel(x, y, SomeColor)
Next
Next

I'm looking for something like Java's MemoryImageSource class where I can just
create an array of values, then create an Image from that. Any ideas?
Nov 20 '05 #1
4 2000
Look into LockBits and UnlockBits


"Jeremy" <jm**********@yahoo.com> wrote in message
news:11**************************@posting.google.c om...
I am defining a bitmap pixel by pixel, and I searched through the documentation, but could not find an obvious fast way to do what I want. My first attempt used the underlying graphics object to draw 1 by 1 rectangles. This was SLOOOOOOW. It took about 1800 milliseconds for a bitmap that was pretty small. Using the following code, I got it down to 500 milliseconds, but that is still pretty slow.
For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1
bmp.SetPixel(x, y, SomeColor)
Next
Next

I'm looking for something like Java's MemoryImageSource class where I can just create an array of values, then create an Image from that. Any ideas?

Nov 20 '05 #2
* jm**********@yahoo.com (Jeremy) scripsit:
I am defining a bitmap pixel by pixel, and I searched through the documentation,
but could not find an obvious fast way to do what I want. My first attempt used
the underlying graphics object to draw 1 by 1 rectangles. This was SLOOOOOOW.
It took about 1800 milliseconds for a bitmap that was pretty small. Using the
following code, I got it down to 500 milliseconds, but that is still pretty slow.

For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1
bmp.SetPixel(x, y, SomeColor)
Next
Next


<URL:http://www.google.de/groups?q=dotnet+lockbits+vb+marshal.copy>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Thanks everyone for your help! This code runs in about 25 ms, which is
more than acceptable.
Private Sub Draw1()
Dim lStart, lEnd As Integer

lStart = Environment.TickCount
If bmpDouble Is Nothing Then
bmpDouble = New Bitmap(Panel1.Width, Panel1.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb )
ReDim buffer(bmpDouble.Width * 4 * bmpDouble.Height)
End If

Dim bmd As System.Drawing.Imaging.BitmapData

With bmpDouble
bmd = .LockBits(New Rectangle(0, 0, .Width, .Height), _
Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppRgb)
For y As Integer = 0 To .Height - 1
For x As Integer = 0 To .Width - 1
Dim bufferIndex, Argb As Integer
Argb = Colors((Values(y, x) Mod 255 + iOffset) Mod 255).ToArgb
buffer(bufferIndex) = CByte((Argb And &HFF0000) \ CInt(2 ^ 16))
buffer(bufferIndex + 1) = CByte((Argb And &HFF00) \ CInt(2 ^ 8))
buffer(bufferIndex + 2) = CByte(Argb And &HFF)
bufferIndex += 4
Next
Next
Runtime.InteropServices.Marshal.Copy(buffer, 0, bmd.Scan0, _
.Width * 4 * .Height)
.UnlockBits(bmd)
End With

lEnd = Environment.TickCount
lblDrawTime.Text = CStr(lEnd - lStart)
gMain.DrawImage(bmpDouble, 0, 0)

End Sub
Nov 20 '05 #4
"Jeremy" <jm**********@yahoo.com> schrieb
buffer(bufferIndex) = CByte((Argb And &HFF0000) \ CInt(2
^ 16))
dividing by &H10000...
buffer(bufferIndex + 1) = CByte((Argb And &HFF00) \ CInt(2 ^
8)) buffer(bufferIndex + 2) = CByte(Argb And &HFF)


resp. by &H100

would be even faster.

In VB 2003, use >> 16 resp. >> 8. Should be more faster.
--
Armin

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: no | last post by:
I'm using PHP with GD2 to create image thumbnails, but it gets extremely slow when processing large images (1600x1200 or more). I had to raise max_execution_time to more than 120 secs and I don't...
1
by: jasonshohet | last post by:
I read recently that: "if a before-image was made before an interruption in database processing, you use the before-image dump & simply begin processing again from just before the last...
1
by: bongoo | last post by:
I'm reading pixel values (RGB) from a bitmap object using function from system.drawing namespace & vb.net (.net framework 1.1) But I would like to make it faster, so is there any another way of...
2
by: | last post by:
Hi, we are planning to rewrite an extisting C++ image processing application/library in C#. Now several question arouse where I hope you can help me: So far we allocated a block of memory as...
10
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All...
16
by: bartj1 | last post by:
Hi, I did a benchmark comparison of a National Instruments Active-x "Strip Chart" control in both Vb5 and vb.net(2005). The code is identical: For I = 1 to 10000 ARR(1,0) = J...
3
by: birensubudhi | last post by:
hey guys,can anyone tell me what is image processing, how to do it using C. IN KSHITIJ 2007 held at IIT kgp a que by INFOSYS is asked, they hav given an image then cut in different orientation...
5
by: whisk3rs | last post by:
Hello, I have a conceptual question. I need to write a program that will take as input a list of images and then process each image individually (extract useful features from the image) ...
0
by: tavares | last post by:
(Our apologies for cross-posting. We appreciate if you kindly distribute this information by your co- workers and colleagues.) ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.