Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2005, 12:21 AM
Registered User
 
Join Date: Jun 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default changing pixel color in if/then construct

Hi all,

I am new to VB.net and have a question. I have created a bitmap image of a form, and I am attempting to loop through pixels, starting with the pixel at a mouse-click and color them blue if they are gainsboro. The For loop is working correctly, but if I click on a color which I know is gainsboro, the loop never seems to enter the if statement. Any help for this rookie would be greatly appreciated! A bit of code is below.

        If e.Button = MouseButtons.Left Then
            StartX = e.X
            StartY = e.Y

            For i = StartY To 1 Step -1
                color1 = m_PrintBitmap.GetPixel(StartX, i)
                If color1.ToString.Equals(gainsboro.ToString) Then
                    m_PrintBitmap.SetPixel(StartX, i, blue)
                ElseIf color1.ToString = blue.ToString Then
                    Exit For
                End If
            Next i
        End If

 
Old June 19th, 2005, 09:12 AM
Registered User
 
Join Date: Jun 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Solution:

Must use "color.ToArgb" logic. "Color.Tostring" logic produces different results for system.drawing.color, than for a picture.getpixel(x,y).

If e.Button = MouseButtons.Left Then
            StartX = e.X
            StartY = e.Y
            For i = StartY To 1 Step -1
                color1 = m_PrintBitmap.GetPixel(StartX, i)
                If color1.ToArgb.Equals(gainsboro.ToArgb) Then
                    m_PrintBitmap.SetPixel(StartX, i, blue)
                ElseIf color1.ToArgb.Equals(blue.ToArgb) Then
                    Exit For
                End If
            Next i
        End If






Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Page Color darkestangel1980 CSS Cascading Style Sheets 6 February 6th, 2008 12:40 PM
color changing windows casemaker Oracle 0 May 28th, 2006 08:29 PM
Changing color conny Visual C++ 0 April 14th, 2005 07:57 PM
changing a link's text color WalterD Dreamweaver (all versions) 3 February 24th, 2005 05:15 PM
Need help changing color on text, please larry Javascript How-To 1 December 23rd, 2003 10:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.