• 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

    • Vivetool also has a GUI. Literally took me three clicks to enable this from there.
    • Microsoft Weekly: OneDrive horror stories, ramblings about Start menu, and more by Taras Buria This week's news recap is here, delivering you a roundup of the most important Microsoft stories, including a bunch of odd stuff and bugs in Windows, OneDrive horror stories, ramblings about the Start menu, a couple of new Windows 11 preview builds, important news from AMD, and a lot more. Quick links: Windows 10 and 11 Windows Insider Program Updates are available Reviews are in Gaming news Windows 11 and Windows 10 Here, we talk about everything happening around Microsoft's latest operating system in the Stable channel and preview builds: new features, removed features, controversies, bugs, interesting findings, and more. And, of course, you may find a word or two about older versions. Microsoft released a new out-of-band update to fix boot issues on certain Surface devices. The company announced certain Windows 365 updates, such as VBS and HVCI support (by default) and app provisioning in Windows 365 instead of entire cloud PCs. Microsoft is also removing legacy drivers from Windows Update in a new "strategic move." This is the default Windows 365 wallpaper On the negative side, we have the latest Patch Tuesday updates breaking the DHCP Server in all Windows Server editions. Also, there is some bad news for PC users with Windows Hello cameras: after the April 2025 Patch Tuesday updates, Windows Hello does not work in the dark. The change was quietly introduced to address security issues. Windows Goodbye That is not all, though. As it turned out, solid-state drives from WD could still block your computer from installing Windows 11 version 24H2, which was released in October 2024. Also, Microsoft's Family Safety feature is now blocking Chrome, for some reason. Here is an editorial from Usama Jawad (welcome back) about how, four years after the initial release, Windows 11 still does not offer strong enough reasons to upgrade from the outgoing Windows 10. Also, Usama shared his thoughts about the Start menu and why he had stopped caring about its changes altogether. Speaking of the Start menu, check out our overview of what users wanted from Microsoft and what the company delivered in the redesigned Start menu, which was recently announced. Windows Insider Program Here is what Microsoft released for Windows Insiders this week: Builds Canary Channel Build 27881 This week's Canary build introduced context menu improvements, new accessibility features, Settings app tweaks, and more. Dev Channel Nothing in the Dev Channel this week Beta Channel Nothing in the Beta Channel this week Release Preview Channel Build 26100.4482 (KB5060829) This build improves File Explorer and search performance, adds some changes to default browser settings, and fixes multiple bugs. Some hidden stuff in the recent Windows 11 preview builds includes a new adaptive battery saver. This feature dynamically adapts battery saver mode according to your workflow, but in its current form, it is not fully operational. Even though Microsoft acknowledged its existence, the adaptive part still needs improvements. Another useful change in the recent builds is the return of a clock in the notification center. This time, however, Microsoft makes it more customizable, and you can toggle it on or off. Also, the company is moving more Control Panel bits to the Settings app and adding a rather unexpected customization feature that will let you select where system indicators (flyouts and sliders) appear on the screen. Microsoft started rolling out a new update for the Snipping Tool app. The latest release lets you save screen recordings as GIFs. Shortly after that, we posted a guide with a bit more detail about the feature. Updates are available This section covers software, firmware, and other notable updates (released and coming soon) from Microsoft and third parties, delivering new features, security fixes, improvements, patches, and more. Microsoft is working on a Dashboard redesign for PowerToys. Developers published an early look at what is coming to the app in future updates, revealing a better-organized page with quick links, a shortcut overview, and a list of available modules. This week's Office updates are rather mixed. OneDrive, for one, is having problems finding files. Microsoft acknowledged the issue, which affects users on Windows, iOS, Android, and the web. Unfortunately, that is not the only negative story about OneDrive. A new report from a frustrated user revealed a scary tale of Microsoft locking them out of an account full of invaluable content. Outlook also has some issues, this time, with opening emails, and Microsoft 365 will soon disable outdated protocols for file access. Finally, Copilot in Excel received a major update for context awareness, which made the assistant more useful when answering questions about data. This week's browser updates include several releases. Firefox announced a new method for pinning and unpinning tabs. It is now available for testing in the Nightly channel. Microsoft Edge was updated with fixes for two security vulnerabilities (high severity) originating from Chromium. Finally, here is this week's Microsoft 365 Roadmap with an overview of all the new stuff that Microsoft added to the website. Here are other updates and releases you may find interesting: Microsoft 365 security in the spotlight after Washington Post hack. Microsoft expands European sovereign cloud offerings with new data and key controls. Microsoft Defender XDR received TITAN-powered Security Copilot recommendations. Microsoft reportedly plans more layoffs. Watchdog found Microsoft guilty of confusing advertising when it comes to Copilot. Here are the latest drivers and firmware updates released this week: AMD released a new chipset driver for Ryzen processors under version 7.06.02.123, which followed a security update for TPM-Pluton. Nvidia 576.80 WHQL with fixes for the RTX 5090 FE, new game support, and a long list of fixes. You can get some extra performance on certain AMD Ryzen chips with a simple system tweak. Surface Pro 11 and Surface Laptop 7 received big firmware updates with multiple fixes and improvements. Reviews are in Here is the hardware and software we reviewed this week This week, Steven Parker reviewed the TerraMaster D4 SSD, a palm-sized DAS with up to 32TB of storage that you can connect over USB4. This thing is rather impressive, and for a modest price tag, it delivers a tiny footprint, great looks, full RAID support in TOS 6, quick connection, and more. On the gaming side Learn about upcoming game releases, Xbox rumors, new hardware, software updates, freebies, deals, discounts, and more. AMD and Microsoft announced some big news this week. The two companies revealed a new multi-year partnership, which secures AMD as the future maker of chips for Xbox consoles and other hardware. Sarah Bond announced the partnership in a new video on the official Xbox media channels. Turn 10 Studios announced a new Forza Motorsport update. Update 21 brings IndyCar content, Career mode expansion, Featured Tours, new reward cars, and more. It is now available on Xbox and PC via the Microsoft Store and Steam. Minecraft is another Microsoft-owned game that received a big update this week. The long-anticipated graphics overhaul is finally here with directional lighting, volumetric fog, improved shadows, reflections, godrays, and a lot more. In addition, Mojang released Chase the Skies, the latest content drop, which adds happy ghasts, new music disks, a locator bar for players, environmental fog in the overworld, new background music, and all sorts of small gameplay changes. Microsoft announced new games for Game Pass. The latest additions include FBC: Firebreak, Crash Bandicoot 4: It's About Time, Start Trucker, Wildfrost, Rematch, Call of Duty: WWII, Rise of the Tomb Raider, and more. As usual, some games are leaving the subscription. Valve released a big update for the Steam overlay. The latest version introduced major upgrades to CPU and VRAM usage, temperatures, and other important metrics that you might want to track when playing games on your gaming rig. Deals and freebies Also, be sure to check out this week's Weekend PC Game Deals article, which features rhythm bundles, fishing festivals, DRM-free summer sales, and more. Other gaming news includes the following: Take-Two confirmed Borderlands 4 will not cost $80 for the base game. The Coalition expanded the Gears of War: Reloaded beta after its rocky start. Ara: History Untold 1.4 update delivered overhauls to AI, map generation, combat, and more. Star Citizen Alpha 4.2 update lands with radiation hazards, dynamic rain, and more. This link will take you to other issues of the Microsoft Weekly series. You can also support Neowin by registering a free member account or subscribing for extra member benefits, along with an ad-free tier option. Microsoft Weekly image background by steve_a_johnson on Pixabay
    • I'm afraid not, Microsoft does release updated installation images for Windows through MVS every month, but they do not include any update to Defender's components or signatures. That's what the package talked about in the article is for, it includes a PowerShell script for the update.
  • Recent Achievements

    • First Post
      Johnny Mrkvička earned a badge
      First Post
    • Week One Done
      viraltui earned a badge
      Week One Done
    • One Month Later
      serfegyed earned a badge
      One Month Later
    • Dedicated
      firey earned a badge
      Dedicated
    • Dedicated
      fettermanj earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      635
    2. 2
      ATLien_0
      230
    3. 3
      Michael Scrip
      217
    4. 4
      Xenon
      149
    5. 5
      Steven P.
      141
  • Tell a friend

    Love Neowin? Tell a friend!