Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pixel graber
#9
(07-20-2011, 07:13 AM)RP Deliverance Wrote: Ya i know it is pretty basic its a tutorial when i first started to learn VB but i dont mess much with Visual Basic or Visual programming im more in Java and C/C# scripting but thanks for the feedback.

Though you can still program in C, C#, and C++ in Visual. It's all the same
- Here's my interpretation for others -

'This part defined the pixel as a 1x1 dimension
Code:
Dim BMP As New Drawing.Bitmap(1, 1)

'Getting a Bitmap value with the 1x1 dimension defined previously
Code:
Dim GFX As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP)
Note: I wouldn't suggest using System.Drawing in this way, you should have Imported it at the top of the class and did something like:
Code:
Dim GFX As Graphics = Graphics.FromImage(BMP)

'sets the graphics point as the point at the mouse position with the size of BMP (1x1) on the screen
Code:
GFX.CopyFromScreen(New Drawing.Point(MousePosition.X, MousePosition.Y), _
  New Drawing.Point(0, 0), BMP.Size)

'Pixel is now a system.drawing.color which is equal to the pixel at the mouse position (0,0)
Code:
Dim Pixel As Drawing.Color = BMP.GetPixel(0, 0)
Again I wouldn't put part of the namespace in there, instead do something like this assuming you have imported System.Drawing:
Code:
Dim Pixel As Color = BMP.GetPixel(0,0)

'Puts the color of Pixel found from the color at the mouse location to the backcolor of the form, you can define it as the backcolor of a picturebox if you wanted.
Code:
Me.BackColor = Pixel

You've overused the namespace in your code.
here's a full, more tidy version:
Code:
'Imports System.Drawing

Dim BMP As New Bitmap(1, 1)
  Dim GFX As Graphics = Graphics.FromImage(BMP)
  GFX.CopyFromScreen(New Point(MousePosition.X, MousePosition.Y), New Point(0, 0), BMP.Size)
  Dim Pixel As Color = BMP.GetPixel(0, 0)
  Me.BackColor = Pixel
Reply


Messages In This Thread
Pixel graber - by Phoenix - 07-09-2011, 05:48 PM
RE: Pixel graber - by Relapse - 07-12-2011, 07:30 PM
RE: Pixel graber - by Phoenix - 07-19-2011, 06:17 PM
RE: Pixel graber - by AceInfinity - 07-19-2011, 07:56 PM
RE: Pixel graber - by Phoenix - 07-20-2011, 07:13 AM
RE: Pixel graber - by Drakon - 07-20-2011, 07:51 AM
RE: Pixel graber - by Phoenix - 07-28-2011, 07:38 PM
RE: Pixel graber - by Terridax - 07-28-2011, 07:44 PM
RE: Pixel graber - by AceInfinity - 07-28-2011, 07:48 PM
RE: Pixel graber - by Phoenix - 08-03-2011, 03:28 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)