Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > BOOK: Visual Basic 2010 Programmer's Reference
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2010 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2010 Programmer's Reference by Rod Stephens; ISBN: 9780470499832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2010 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 4th, 2012, 05:22 PM
Authorized User
Points: 193, Level: 3
Points: 193, Level: 3 Points: 193, Level: 3 Points: 193, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Question Changing selected pixels to a specific color

Hi Rod,

I've continued working on a project that you have helped me with before. I was wondering if you could give me some advice on a particular problem I'm having using pixels. I am working with images that will be a single solid color. They may be drawn and scanned or created in an image editing program. The files would be JPG files. I need to automatically change the single color to RGB (256,0,0,0). The back ground should not be changed. It will generally be white, but must not be the same color as the foreground image.

Perhaps code that would loop through all of the pixels and determine which ones would be a darker color and then change them to RGB(256,0,0,0) would work. Pure white would be RBG(256,256,256,256) I believe. Can you give me some insight on this one? As always, thank you for all of your great help. I've made a lot of progress on my application with you good advice and suggestions.

Regards,

Gary
Reply With Quote
  #2 (permalink)  
Old February 4th, 2012, 05:37 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Note that if you have a jpg then the colors probably aren't exactly what you expect. Two pixels right next to each other may have RGB values 128, 128, 128 and 127, 129, 130. They'll look the same to you but if you're looking for exact color values, they won't match.

I think you'll need to loop through the image and examine each pixel to see if it is close enough to the target value and, if it is, replace it with a new value. To decide whether it is "close enough," you may want to add up the absolute values of the differences in the R, G, B components. (You could square them, add, and take the square root to get a Euclidean distance in RGB space but just adding should work and will be quicker and easier.

Yes 256,0,0,0 is black and 256,256,256,256 is white.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change the color of selected text dynamically NEO1976 Flash (all versions) 1 December 18th, 2007 11:11 AM
How to change the color of selected row of an HTML bhavna HTML Code Clinic 4 February 11th, 2007 09:22 PM
Write to a text file in a specific font and color shai505 C# 1 May 21st, 2006 03:03 AM
Changing color conny Visual C++ 0 April 14th, 2005 07:57 PM
How a Specific word in JTextArea can be selected mrafaqi Java GUI 1 February 2nd, 2005 10:08 PM



All times are GMT -4. The time now is 08:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.