• 0

[VB6 to VB.net] SetPixel


Question

i'm not exactly looking forward to moving over to VB.net to me VB6 is better but i'm just going to have to learn both

(VB6 for my own stuff/.Net for other...)

anyway my question is

VB.net removed the pset function and its a hassle to call Get/SetPixel API from .net

i had a look and found that VB.Net includes the SetPixel function within its library thats good but the problem is

it seems to only accept fixed data e.g. Color.Black, Color.White

Dim pixelColor As Color = myBitmap.GetPixel(50, 50)

I love doing per-pixel manipulation is .net going to stop me from doing this?

can i still do something like this

Dim Color1 As Long
Dim Color2 As Long

Dim Red1 As Long
Dim Green1 As Long
Dim Blue1 As Long

Dim Red2 As Long
Dim Green2 As Long
Dim Blue2 As Long

Dim X As Long
Dim Y As Long

	For X = 0 To Picture1.ScaleWidth - 1
		For Y = 0 To Picture1.ScaleHeight - 1
			Color1 = GetPixel(Picture1.hDC, X, Y)
			Color2 = GetPixel(Picture2.hDC, X, Y)

			Red1 = Fix(Color1 Mod 256)
			Green1 = Fix((Color1 Mod 65536) / 256)
			Blue1 = Fix((Color1 Mod 16777216) / 65536)

			Red2 = Fix(Color2 Mod 256)
			Green2 = Fix((Color2 Mod 65536) / 256)
			Blue2 = Fix((Color2 Mod 16777216) / 65536)


			Red1 = (Red1 + Red2) / 2
			Green1 = (Green1 + Green2) / 2
			Blue1 = (Blue1 + Blue2) / 2

			SetPixel Picture2.hDC, X, Y, RGB(Red1, Green1, Blue1)
		Next Y

		Picture2.Refresh
		DoEvents
	Next X

can someone show me an equivalent to that in .net? or should i just give up on .net all together

(I would like to use Dibits, However i'd like to take one step at a time :))

Link to comment
https://www.neowin.net/forum/topic/578353-vb6-to-vbnet-setpixel/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

In .NET, a Color is represented by a 'Color' object. Colors.Red is just a color with 255,255,0,0 (red, full opacity) in it. You can pass any Color object to the SetPixel method, so you can make your own Color object very easily.

There's a static method in Color, FromArgb that should do what you want.

Just pass Color.FromArgb(Red,Blue,Green) to the SetPixel method.

  • 0
  MioTheGreat said:
In .NET, a Color is represented by a 'Color' object. Colors.Red is just a color with 255,255,0,0 (red, full opacity) in it. You can pass any Color object to the SetPixel method, so you can make your own Color object very easily.

There's a static method in Color, FromArgb that should do what you want.

Just pass Color.FromArgb(Red,Blue,Green) to the SetPixel method.

is there a To Argb method?

like if i use getpixel can i break it down? (ill check soon)

also umm wouldn't that be much slower? is there a way to get around using the color object and just hand it decimals? :D

if not then thats ok whats Dibits like? does it still exist or can i use its api call? (i'm not liking this new programming language)

  • 0

A color object is just a class that contains 4 byte objects, A, R, G, and B. All the .NET methods that do ANYTHING with color will expect you to hand it a System.Drawing.Color object. You'll never see passing of just the component values around.

.NET is overall much better than vb6. .NET is very object oriented, has good error handling, etc. vb6 just....sucked.

  • 0
  MioTheGreat said:
A color object is just a class that contains 4 byte objects, A, R, G, and B. All the .NET methods that do ANYTHING with color will expect you to hand it a System.Drawing.Color object. You'll never see passing of just the component values around.

.NET is overall much better than vb6. .NET is very object oriented, has good error handling, etc. vb6 just....sucked.

I don't know

VB6 just....its perfect i love it Lol

VB.NET on the other hand....makes me sick to be honest

I can't accept the fact that VB.net is a newer version then VB6 rather then its a completely different language all together with somewhat similar syntax

the code just looks messier and slower (even though it runs faster) which means they are hiding more from the programmer

OO may be good for some but...if this is whats involved, Then no thanks ^_^

I'll try the setpixel stuff out maybe i can write a DLL to bring back some functionality from VB6 that i liked :)

  • 0

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe

Additional information: Object reference not set to an instance of an object.

CType(PictureBox1.Image, Bitmap).SetPixel(x, y, Color.Black)

I just wan't to cry......theres no way in hell that .net is better then VB6

only benefits i've seen so far is speed in run time nothing else

and since speed isn't an issue....

Edit:

Ahh forget it thanks everyone for your help but vb.net just isn't worth it i'll stick to vb6/c++/asm

shouldn't have to hassle so much to use a simple function

setpixel hdc, x, y, cr

^ That was the best function ever and they ruined it with all this object crap

don't get me wrong objects are great but they've just over done it the only objects i want to see

are the ones i've written not to confuse them with api calls

Edited by DDStriker
  • 0

Er. Really, sticking with vb6 is a pretty crappy idea. It'll hopefully be dying out soon. More and more is going .NET because it's simply better.

  Quote
the code just looks messier and slower (even though it runs faster) which means they are hiding more from the programmer

That's because you're still thinking like a vb6 developer. The code in .NET can be much cleaner and more sensible than the stuff in .NET. You have to rid yourself of the poor programming practices vb6 enforced.

A NullReferenceException means you've got an object somewhere that is null, and you tried to use it. Post the full details of the exception for more information.

Most likely, your PictureBox1.Image casted to a Bitmap was null. Are you sure the Image was set?

  Quote
only benefits i've seen so far is speed in run time nothing else

You have to remember that VB.NET an entirely different language to vb6. It shares some syntax, but the underlying principles have been radically altered for the better.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • “Ask Photos” is coming to more Google Photos users in the US by Paul Hill Google has announced several improvements to a Gemini-powered Google Photos feature called Ask Photos. The feature launched last year in early access and it was great for longer search requests, however, when users typed “Dog” or “Beach” looking for those types of pictures, Ask Photos underperformed. Now, Google has addressed this and is bringing the feature to more eligible users in the United States. The search giant said that users enjoyed asking queries such as “suggest photos that’d make great phone backgrounds” or “what did I eat on my trip to Barcelona?” and getting Gemini-powered responses to these complex questions. Unfortunately, simple searches like “beach” or “dogs” were generating less than optimal results and people complained. To remedy the situation, Google has brought the best of Google Photos’ classic search feature to Ask Photos to improve latency. Easy, short requests will be dealt with by the old search mechanism and when you ask complex queries, it will switch over to the Gemini-powered search results. Now that Google has addressed this main issue of simple searches by integrated functionality from the previous search model, the company feels more confident to open up beyond early access and deliver it to more users in the United States. To be eligible, you must be 18+, be in the US, have your Google Account language set to English (United States), and have Face Groups turned on. This feature is only available on Android and iOS. To start using it, open Google Photos and tap on Ask at the bottom, then press Try now and agree to the terms. If you do not see the Ask button, it means you’re not yet eligible. The feature also can’t be used on computers yet. Hopefully, Google will quickly expand this feature outside the US so that international users can try it out too.
    • When are MS going to learn. Traditional home users who email, watch cat videos and perform basic tasks don't care if W11 is slightly faster...assuming it's true. Few home users care about faster speed and more secure claims.
    • They have. https://www.xda-developers.com...-25h2-update-kind-of-small/
    • Microsoft shares detailed performance benchmarks for Windows 11 vs 10 to show the faster PC by Sayan Sen In the past, Microsoft has always made big claims regarding Windows 11 performance and how it is faster and better than Windows 10. For example, back in 2021, the company stated how the former was designed to get the best out of your system hardware. Later in 2023, Microsoft shared detailed Windows 11 performance improvements and upgrades it achieved on the new OS. While the claims were not substantiated with data, they were certainly quite interesting. Then, in 2024, Microsoft highlighted the differences in performance, citing a paid study, to show Windows 11 was way faster. As with most commissioned studies, the data was not represented fairly. This week, Microsoft has shared new numbers based on its December 2024 testing in a new support document. Here are the performance claims Microsoft made: Top Windows 11 PCs have up to 2.7 more hours of battery life than Windows 10 PCs Windows 11 PCs are up to 2.3x faster than Windows 10 PCs Windows 11 PCs offer up to 3.2x faster web browsing than Windows 10 PCs Windows 11 PCs offer up to 2x faster Microsoft Office productivity than Windows 10 PCs Thus, if you ask Microsoft, it will say that Windows 11 is better than Windows 10 in everything there is, be it web browsing, Office use, battery life, and overall performance in general. The company notes that the results are "based on a 95% confidence interval" for each OS across multiple tests. Microsoft also accounted for outliers. To reach such numbers, Microsoft used the following test metrics: For battery life, a local 1080p 24 fps MP4 video file playback was tested till 90% battery discharge on the Windows Media Player app. During the test, all settings were default except that screen brightness was set to 150 nits and Auto-brightness was disabled. Wi-Fi was connected to a network. For the "2.3x faster" claim, Geekbench 6 results have been cited. For web browsing, Speedometer was used, though Microsoft does not mention the version. And finally, for Office, Procyon Office productivity was used. Interestingly, Microsoft only used Intel CPUs (the company also recently recommended Intel chips for Windows 11 Pro PCs). The company has played it a smarter this time as it has "tested performance, battery life and application capabilities of a selection of Windows 11 PCs in comparison to a selection of Windows 10 PCs", where the Windows 10 PCs feature Intel Core 6th, 8th, and 10th gen chips and Windows 11 PCs pack Intel Core 12th and 13th gen. Thus, this is Microsoft essentially acknowledging that the underlying hardware itself actually plays a big role in the claims it has made. But to be fair to the company, there is also no way to run Windows 11, at least officially, on unsupported PCs, such that a direct comparison can be made. You can find the support document with full battery results in this article here on Microsoft's website.
    • So, do nothing basically, as long as you deploy Windows Updates? Pretty much yeah. Some Linux distros distribute update the secureboot certs as well, assuming you do use SecureBoot.
  • Recent Achievements

    • Week One Done
      Marites earned a badge
      Week One Done
    • One Year In
      runge100 earned a badge
      One Year In
    • One Month Later
      runge100 earned a badge
      One Month Later
    • One Month Later
      jfam earned a badge
      One Month Later
    • First Post
      TheRingmaster earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      567
    2. 2
      +FloatingFatMan
      177
    3. 3
      ATLien_0
      169
    4. 4
      Michael Scrip
      127
    5. 5
      Xenon
      119
  • Tell a friend

    Love Neowin? Tell a friend!