|
-
Dec 30th, 2001, 04:33 AM
#1
Thread Starter
Member
grey scale
How do i convert any image into a greyscale?
and save?
Regards..
-
Dec 30th, 2001, 07:44 AM
#2
Fanatic Member
I guess you already know how to use the Getpixel and Setpixelv API functions?
Then, use this function to convert the color back to a red, a green and a blue part:
Code:
ripped from an article on vbworld.com
Public Function UnRGB(RGBCol As Long, Part As Integer) As Integer
'Part: 0=Red, 1=Green, 2=Blue
Select Case Part
Case 0
UnRGB = RGBCol And &HFF
' mask 000000000000000011111111 and shift bits right
Case 1
UnRGB = (RGBCol And &HFF00) / &HFF
' mask 000000001111111100000000 and shift bits right
Case 2
UnRGB = (RGBCol And &HFF0000) / &HFFFF
' mask 111111110000000000000000 and shift bits right
End Select
End Function
Then do something like this:
Code:
Dim Average As Integer
Dim NewColor As Long
Average = RedPart + GreenPart + BluePart
NewColor = RGB(Average/3, Average/3, Average/3)
You can save to a JPEG using this code from vbAccelerator. You can also make your own saving routines, file format specifications of common file types can be found at wotsit.org. It's quite hard to make a saving routine for GIF or JPEG. Saving to a BMP is relatively easy.
I didn't make working code for you, but I think this will help you a lot on your way.
-
Dec 30th, 2001, 02:36 PM
#3
Another greyscale approach is to sep out colors the oetje shows, and then use luminance.
For RGB colors
luminance = 0.299*Red + 0.587*Green + 0.114*Blue
The gray color for the pixel is then
RBG(luminance,luminance,luminance)
-
Dec 30th, 2001, 11:27 PM
#4
Thread Starter
Member
Hi,
Thanks ,
Will this reduce the size of the original image?
Regards,
LXS
-
Dec 31st, 2001, 11:19 AM
#5
Fanatic Member
In memory it's not easy to reduce the size. If you save it the right way it reduces the size a lot. If you save it to a 8 bit greyscale BMP, instead of a 24 bit color BMP the size will be divided by 3. If you save it to GIF it won't matter much, because GIF only supports 256 colors. (A 256 color palette) I'm not sure about JPEG.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|