473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

set image color

im trying to read an image(*.bmp) from file and then color the black pixels
in it to the color i want using argb. Below is the code of what im trying to
do but this gives me an error "setPixel is not supported for images with
indexed pixel format"
Please tell me what im doing wrong.

Dim c1 As Color = Color.Black
Dim c2 As Color = Color.FromArgb(CInt(colour))
Dim bm AsNew Bitmap(img)
Dim eX AsInteger
Dim eY AsInteger
Dim r AsInteger
Dim g AsInteger
Dim b AsInteger
r = c2.R
g = c2.G
b = c2.B
For eX = 0 To bm.Width - 1
For eY = 0 To bm.Height - 1
If bm.GetPixel(eX, eY).ToArgb = c1.ToArgb() Then
bm.SetPixel(eX, eY, Color.FromArgb(r, g, b))
EndIf
Next eY
Next eX
PeBox2.Image = bm
PeBox2.Location = New System.Drawing.Point(x, y)
PeBox2.Size = New System.Drawing.Size(width, height)
PeBox2.BorderStyle = BorderStyle.FixedSingle
PeBox2.Name = "PeBox2"
PeBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchIma ge
PeBox2.TabStop = False
Me.Controls.Add(PeBox2)
Nov 21 '05 #1
2 3820
"sympatico" <fe******@a1vbcode.com> schrieb:
im trying to read an image(*.bmp) from file and then color the black
pixels
in it to the color i want using argb. Below is the code of what im trying
to
do but this gives me an error "setPixel is not supported for images with
indexed pixel format"


A simple (A)RGB image stores the color values of each pixel, in other words,
it's a rectangular matrix of (A)RGB values. In an indexed format, each
color used in the image is added to a color table that maps color indices to
actual color values. Instead of storing the RGB(A) values for each pixel,
the number of the pixel's color color in the color lookup table is stored.
When drawing the indexed image, for each pixel the actual color value of the
index stored for the pixel is taken from the loopup table (which is a
mapping of index -> (A)RGB).

What you need to do is converting the image from an indexed format to a
"raw" (A)RGB format. To do this, you will have to create a new bitmap
object with non-indexed pixel format, obtain a 'Graphics' object for it
('Graphics.FromImage') and paint the indexed bitmap onto this image
('Graphics.DrawImage'), for example.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2

"sympatico" <fe******@a1vbcode.com> wrote
im trying to read an image(*.bmp) from file and then color the black pixels
in it to the color i want using argb. Below is the code of what im trying to
do but this gives me an error "setPixel is not supported for images with
indexed pixel format"
Please tell me what im doing wrong.


You might want to try a different approach (assume White is the new color)

Dim bmp As New Bitmap("d:\temp\test.bmp")
bmp.MakeTransparent(Color.Black)
PictureBox1.BackColor = Color.White
PictureBox1.Refresh()
PictureBox1.CreateGraphics.DrawImageUnscaled(bmp, 0, 0)

HTH
LFS

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Phil Powell | last post by:
I borrowed this code from a source: for($a=0;$a<imagecolorstotal ($image_id);$a++) { $color = imageColorsForIndex($image_id,$i); $R=.299 * ($color)+ .587 * ($color)+ .114 * ($color);...
7
by: Paul Charlton-Thomson | last post by:
Hi! I have nearly cracked this and am stuck on the last bit. I am asking my visitors to rank 8 different items (a,b,c,d,e,f,g,h) from 1 to 10 and then I want to draw a pie chart of those values....
5
by: Roger Shrubber | last post by:
I have a page with images that the user can drag from one frame to another. I need them to see a "ghost image" of the image they are dragging, while the original stays put. I use the onmousemove...
2
by: Mekon | last post by:
I have never written a line of script in my life but I need some help with it now. I have this auto generated code which I want to modify if possible The script generates a strip of...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
3
by: Kristof Thys | last post by:
Hello, I'm writing a ASP.net webservice wich will visualize an image, generated by another application. The generated image is a char*. I can transform this to a String*, but I want to view it...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
6
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional)...
2
by: studentofknowledge | last post by:
For some unknown reason ie is placing images I have in a div in a weird way. One image is overlapping another but this problem is not occuring in mozilla. I have looked at my code over and over again...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.