Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > BOOK: Visual Basic 2010 Programmer's Reference
| 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 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
  #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
  #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!)


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





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