Aurigma Forums
»
Legacy Products
»
Archive
»
Other Products
»
how can I change color "automatically"
Rank: Member
Groups: Member
Joined: 9/13/2004(UTC) Posts: 4
|
I need to take a black and white image that is uploaded and convert it to red and white, or blue and white, etc. The color will be one of a few (5 or 6) and I need to do this basically without user intervention.
Is there an easy way to process the image to apply the color in place of the black in the image? The interface I have is so incredibly simple that the user is just "approving" uploaded images for copyright and objectional material, so I want to apply the color in VB6 code in the background when I open the file. Then it will be saved for printing with the color instead of the black.
And ideas or help would be greatly appreciated?
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration Joined: 8/2/2003(UTC) Posts: 876
Thanks: 2 times Was thanked: 27 time(s) in 27 post(s)
|
If you work with indexed image (1-bit, 4-bit, or non-grayscale 8-bit), you can just replace an appropriate color in the palette. Even if you use 24-bit RGB bitmaps, you can convert them to 8-bit indexed bitmap. Since you said that actually the image contains only few colors, it will not make any problems (moreover, it will save some memory). Code:Dim objBmp As New Bitmap
objBmp.LoadFromFile "c:\image.bmp"
If Not objBmp.Data.IsIndexed Then
objBmp.Data.ConvertTo8bppIndexed DitheringTypeNone
End If
Dim intBlackColorIndex As Integer
intBlackColorIndex = objBmp.Data.Palette.FindNearestIndex(ColorBlack)
objBmp.Data.Palette(intBlackColorIndex) = ColorBlue
objBmp.SaveToFile "c:\result.bmp"
FindNearestIndex method works quite slowly (which is noticeable for large palettes). If you are sure that the color you replace is presented in the bitmap, you can just iterate the palette entries and replace an appropriate ones: Code:Dim I As Integer
For I = 0 To objBmp.Data.Palette.Count - 1
If objBmp.Data.Palette(I) = ColorBlack Then
objBmp.Data.Palette(I) = ColorBlue
End If
Next
Hope this helps. Edited by user Thursday, December 20, 2007 4:33:13 PM(UTC)
| Reason: Not specified
|
|
|
|
Aurigma Forums
»
Legacy Products
»
Archive
»
Other Products
»
how can I change color "automatically"
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.