Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Interface and Graphics > Old VB5 picture1.point....


Reply
 
Thread Tools Display Modes
  #1  
Old 12-31-2007, 11:03 AM
reinkeluke reinkeluke is offline
Freshman
 
Join Date: Jan 2004
Posts: 46
Default Old VB5 picture1.point....


In vb5 i could get the color of any x,y point in my picture box with this command:

isect = Picture1.Point(Xsect, Ysect)

What would be the equivalent in VS?

I am using the bouncing ball program:

http://www.xtremevbtalk.com/showthread.php?t=291335

but modifying so it does not "erase" the ball before it draws it again. As the ball moves, it fills the screen with it's trail. I want to look at where the ball is going to be drawn, find the color of that spot, and "increment" the color up a chart. If the ball has already been to a spot, the next time it shows up there, change the color that is drawn. Thanks.
Reply With Quote
  #2  
Old 12-31-2007, 12:23 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,505
Default

VB .NET separates the logic of images from the picture box control, making it a control that displays images rather than an image that can be displayed. But that's not getting us closer to a solution.

The first step is to get the image that is displayed in the picture box. This is easy enough; there is an Image property that does just that. Once you have the image, you can get a Bitmap instance. Bitmap has the GetPixel function which does precisely what you want. The example code below handles a MouseMove over a picture box by displaying the color under the mouse.
Code:
    Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        Dim img As Image = PictureBox1.Image
        ' Be careful that this cast is actually valid
        Dim bmp As Bitmap = DirectCast(img, Bitmap)
        Dim pnt As Point = e.Location
        Dim color As Color = bmp.GetPixel(pnt.X, pnt.Y)
        Dim colorText As String = "Color at location {0} is {1}."
        colorText = String.Format(colorText, pnt, color)

        Label1.Text = colorText
        PictureBox1.Invalidate()
    End Sub
If you want to change the value of the pixel, use the Bitmap.SetPixel() method.
Reply With Quote
  #3  
Old 12-31-2007, 12:35 PM
reinkeluke reinkeluke is offline
Freshman
 
Join Date: Jan 2004
Posts: 46
Default

Thanks for your reply....

I don't need to use a picture box. That was the only way I could find to describe the old VB5 function....

I want the ball bouncing on the form just like the program in the link above, but I want to know the color of the back ground where the new ball will be drawn.... Can I use "lineargradientbrush" to change the color of each new overlap following a gradient scheme?
Reply With Quote
  #4  
Old 12-31-2007, 01:31 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,505
Default

Oh I see, you are drawing to a bitmap then drawing that bitmap to the form.

With the previously posted code, you already have the bitmap so everything above (except the PictureBox parts) applies.

Using a linear gradient brush might prove difficult depending on how complicated an effect you desire. To make the gradient, the brush's constructor requires the size of the area the gradient will occupy as either two points or a rectangle in advance. In a simple implementation, the gradient would be told to fill the form's area, and it would look as if the ball were wiping away some layer of paint over a gradient pattern. A more complex implementation would want the gradient to only fill the area of the ball's track. In this case, your current architecture makes things kind of difficult and you'd be better served by storing simpler geometry objects and using a more traditional Form painting model.

So I guess the answer is "maybe".
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->