• 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

    • Apple CarPlay to let you stream iPhone videos to your car screen by Sagar Naresh Bhavsar In an official post for developers, Apple announced that CarPlay users will be able to watch iPhone videos on their car's display. This feature will be powered by Apple AirPlay, allowing users to stream videos wirelessly from their iPhones to their car's infotainment screen. For safety reasons, users will be able to enjoy videos on their car's display, but only when their vehicle is parked. Users won't be able to watch videos while the car is on the move. The connected iPhone will automatically detect when the car moves and will stop playing the video to avoid driver distraction. According to Apple, devs need to "integrate support for CarPlay with AirPlay video to enable this feature in your car." Carmakers will need to add support for CarPlay with AirPlay video to let users watch videos in their cars. So, this may take a while to roll out. Apple hasn't specifically mentioned whether it will be exclusive to the newly introduced and limited CarPlay Ultra, or standard CarPlay users will also be able to enjoy videos through AirPlay on their car's screen. Also, there is no clarity if existing models will get support via software update, or if it will be limited to newer models only. On the Android side, Google has also announced a bunch of new capabilities soon to be coming to Android Auto. The company has extended support for weather apps in beta for Android Auto and has confirmed that Android Auto will soon support video and browser apps as well. Image via Depositphotos
    • For a moment there I thought it speeds up Windows installation, but alas...
    • PNY's DUO LINK V3 promises truly incredible speed for a USB flash drive by Sayan Sen PNY today announced a new USB flash drive that blends modern design with high performance. The new DUO LINK™ V3 supports USB 3.2 Gen 2 and offers both Type-C and Type-A connectors. Housed in a metal shell with a matte black finish, the device is built for users who need reliable results when transferring and storing files. The drive is available in multiple storage sizes ranging from 256GB, all the way up to 2TB. According to PNY, the DUO LINK V3 is engineered to deliver read speeds of up to 1,000 MB/s and write speeds of up to 800 MB/s. These speeds are significantly higher than those achieved by standard USB 2.0 flash drives, allowing users to move large files. The product reminds us of the "Poxiao" flash memory we recently covered, which promises even more incredible speeds. The DUO LINK V3 flash drive’s design uses the common swivel mechanism with dual connectors. One side of the device features a USB Type-C connector, while the other side has a USB Type-A connector. This dual-connector system is intended to maximize compatibility, making the DUO LINK V3 useful across a broad range of devices, including smartphones, tablets, laptops, and desktop computers. Thus, in practical terms, users can easily manage files between newer mobile devices and traditional computers without needing extra adapters. Durability and ease of use are emphasized by the metal housing, which is designed to protect the drive during everyday handling. A built-in key loop further supports portability, an important factor for professionals who need to carry important data with them. The device also maintains backward compatibility with older USB standards such as USB 3.2 Gen 1, USB 3.0, and USB 2.0, ensuring that users will find it adaptable to many existing systems. The DUO LINK V3 flash drive is now available directly from PNY and through selected online marketplaces like Amazon. The pricing starts at $34.99 for the 256GB version and reaches $159.99 for the 2TB version. This release provides users with a tool that meets the growing demands of data-intensive work while remaining accessible to those needing a reliable and versatile storage solution. This article was generated with some help from AI and reviewed by an editor. As an Amazon Associate we earn from qualifying purchases.
    • Message from Campbell Wilson, MD & CEO, Air India: https://www.instagram.com/airindia/reel/DKzZQUPhafx/
    • I mean they have been proven to be safer than human drivers in many cases so at the end of the day they will be allowed on the road, the fact that you don't trust them doesn't mean that policy has to be changed to make you more comfortable I am afraid.
  • Recent Achievements

    • Week One Done
      fashionuae earned a badge
      Week One Done
    • One Month Later
      fashionuae earned a badge
      One Month Later
    • Week One Done
      elsafaacompany earned a badge
      Week One Done
    • Week One Done
      Yianis earned a badge
      Week One Done
    • Veteran
      Travesty went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      ATLien_0
      263
    3. 3
      +FloatingFatMan
      193
    4. 4
      +Edouard
      174
    5. 5
      snowy owl
      125
  • Tell a friend

    Love Neowin? Tell a friend!