Convert image from color to black&white

Hi,
I'd like to transform a colored picture (from a gif or jpeg file for
exemple) in a Black and White image (wbmp format). I use a
ColorConvertOp to do that, but I don't know how to param it to have a nice
conversion, not a pixel level conversion. Here is the code I used:
BufferedImage bi4 = new BufferedImage(bi3.getWidth(), bi3.getHeight(),
BufferedImage.TYPE_BYTE_BINARY);
ColorConvertOp cco2 = new
ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
cco2.filter(bi3, bi4);
Where bi3 is my original BufferedImage.
Do you know where I can find more information on this conversion, because in
the help I don't understand everything (I have no knowledge on picture
conversion)?
Thanks for all
Vincent

Try this example
regards
Stas
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
public class Test {
JScrollPane scroll;
JEditorPane edit=new JEditorPane();
public Test() throws Exception {
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BufferedImage sourceImage=new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
Graphics g=sourceImage.getGraphics();
g.setColor(Color.red);
g.fillRect(0,0,100,100);
g.setColor(Color.blue);
g.fillRect(10,10,80,80);
g.setColor(Color.yellow);
g.fillRect(20,20,60,60);
g.setColor(Color.white);
g.drawString("test",5,15);
frame.getContentPane().add(new JLabel(new ImageIcon(sourceImage)));
BufferedImage grayImage=new BufferedImage(100,100,BufferedImage.TYPE_BYTE_GRAY);
grayImage.getGraphics().drawImage(sourceImage,0,0,null);
frame.getContentPane().add(new JLabel(new ImageIcon(grayImage)),BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.show();
public static void main(String[] args) throws Exception {
new Test();

Similar Messages

  • AppleScript-Droplet: convert image to monochrome / grayscale / black&white

    Hello,
    i am used to applescript itself and now willing to write me a small droplet which converts dropped images (jpg & png) to grayscale images.
    right now i am wondering which might be the best application i could use for that ?
    First ideas was ImageMagick (somehow special ...macports) or Sips.
    Is there any chance that i can use a more usual application like Preview from applescript to do the convert task ?
    any ideas ?
    Best regards
    fidel

    Hi Piere,
    that looks great - i added the applescript/keystroke part for save & quit and the result is perfect for my needs.
    My mistake was to just check the offered options in automator - ignoring the keystroke possibilities.
    Thanks once again
    Best regards
    fidel
    code:
    on open droppedImages
    tell application "Preview"
    activate
    repeat with currentImage in droppedImages
    open currentImage
    tell application "System Events"
    keystroke "c" using {option down, command down}
    tell process "Preview"
    set value of value indicator 1 of slider 2 of window 1 to 0
    -- other image modifications are possible here
    end tell
    end tell
    end repeat
    tell application "System Events" to tell process "Preview" to click button 1 of window 1
    -- save
    tell application "System Events"
    keystroke "s" using command down
    end tell
    -- quit preview
    quit
    end tell
    end open

  • URGENT - how do I convert and image from colour to black and white?

    Hi,
    I'm new to Java, and I really need some code to convert an image from colour to black and white! I would really appreciate any help, but since I don't know much about Java I would prefer some code or links to websites with the code.
    Thanks!!!

    http://forum.java.sun.com/thread.jsp?forum=5&thread=368759

  • Can I change more than one photo from color to black and white at one time?

    can I change more than one photo from color to black and white at one time?

    Check out iPhoto Batch Enhancer
    http://www.feroxsoft.com/ibe/index.php.en
    Regards
    TD

  • How do I change an hp officejet j6400 printer change from color to black and white?  I have a Mac 10.8 OX system

    How do I change an hp officejet j6400 printer change from color to black and white?
    I have a Mac 10.8 OX system

    Hi JasperNM,
    You may access a card within the cart reader by mapping a network drive to access it, then you may transfer the fies to your Mac.
    First locate the printer IP address as following:
    Follow these steps to print a Wireless Network Test Report, the IP address will be listed within that report:
    On the control panel, press the Setup button ( ).
    Press the Right Arrow button ( ) to scroll to Network Setup , and then press the OK button.
    Press the OK button to select Print Network Settings .
    Press the Right Arrow button ( ) to scroll to Wireless Test Report , and then press the OK button. The Wireless Network Test Report prints.
    Now map a network driver by following the steps below:
    Click the Finder icon on your Mac.
    Click the Go menu.
    Click on Connect to Server.
    In the Server Address field enter “smb://ipaddress of the printer” and click on Connect.
    You will be prompted to enter the password. leave it as is and click on Connect.
    The Memory card will be mounted as a disk in the Finder.
    Shlomi

  • Trying to update and my nano screen goes from color to black and white...

    Last time this happened I lost all of the information on my ipod.
    I was trying to get my newly purchased music from itunes to my nano. I couldn't. The help sections told me to update my ipod. I'm currently trying to update with 2006-03-23 and the screen still says "initializing" and actually as I type this the screen that says initializing appears frozen (although I've learned apple stuff is weird because it appears frozen but it's not). How long should this take? Is there something I'm doing wrong? Why does my ipod screen go from color to black and white? Do I need to redo anything? Do I need to reset my nano?
    Please help with the ******** mac user (I've always used Windows and I am lost in the mac world apparently when it comes to ipods)

    Can you get the exact wording for that error? Is it can't mount iPod?
    Also, make sure iTunes is up to date...
    iTunes
    Finally, make sure your iPod's battery is charged up.
    btabz

  • My iPhone 6 went from color to black and white

    My iPhone 6 went from color to black and white.  How do I get back to color?

    Of course it's not the quick fix lol. Sorry that didn't work for you, that is the only setting I'm aware that would cause that behavior. Hopefully someone else will assist if they know of another way that may happen. The next thing I would recommend is backing up the iPhone and then doing a reset.
    Since you have an iPhone 6 Plus it is most likely still under warranty. If you have time you could try reaching out to Apple support directly by going to there support page, linked below, and clicking "Get Started".
    https://www.apple.com/support/contact/
    If there are any other important details, like it only occurs in a specific app, feel free to include those in this post as it may help others to figure out what happened.

  • Adding Color to Black & White Photo

    I have PE 9 and I know how to change a photo from Color to Black and White.  I am having trouble adding color back to the photo...Could someone please help me selectively add color to my now black and white photo.
    Thanks in advance.

    That's the easiest. 
    Open your full colour image.
    Choose the Smart Brush tool I showed in my previous post.
    On the Options bar for the tool,
    hit the dropdown arrow (1).
    Hit the effects dropdown box and choose "Black and White" (2).
    Select "Grayscale" (3).
    Set your brush to a small size.
    Paint over the areas you want to be in Black & White.  The brush automatically selects entire areas as you paint.
    If it goes too far, set the brush to "minus"
    and paint over the excess area to return it to the original colour.
    The automatic selection kind of "learns" what you want, so by going back and forth between "plus" and "minus", you'll ultimately get what you want.
    Ken
    Message was edited by: photodrawken to correct typo.

  • Printing in color or black & white in VB6 and Crystal Reports 8.5

    Post Author: elsyvaldez
    CA Forum: General
    How can I programatically print in color or black & white?  I am programming in Visual Basic 6.0 using the Crystal Reports 8.5 Active X Designer Runtime Report object (CRAXDRT.dll).    Our users want the option to print either in color or black & white to a color printer.  I am trying to print many separate reports (for a large group of accounts) in one click of the VB6 "Print" command button without having to display the Printer Setup dialog box for each separate report.  The Report object in CRAXDRT has a method to display the printer setup dialog box but has no property to change "Color" mode (similar to the "PaperOrientation" or "PrinterDuplex" properties).  Is there a way that our users can bring up the Printer Setup dialog box just once, choose color mode, and then make this choice effective for all separate reports printed using CRAXDRT?

    Hi Sastry
    I can print multiple pages from notepad without any issues. It is only the print from the crystal OCX control that has the issue. It has it's own print dialog box.
    Thanks
    Peter

  • Convert image from RGB to CMYK and back to RGB

    Hey.
    I wonder if anyone has experience with converting image from RGB to CMYK and back to RGB?
    I had a TIF in RGB then converted to CMYK but I figured that it might be better to keep in RGB, so I converted back. I read that it supposed to cause some loss in the data, but I can't see anything on the image, it is still very huge and the 2 RGB files has the same size as well. Is there a way to compare the resolution of 2 images somehow, or how can I see what I lost through the 2 conversions?
    Thanks for help

    I had a TIF in RGB then converted to CMYK but I figured that it might be better to keep in RGB, so I converted back.
    The original RGB data is not being restored by converting from the CMYK version, so the term "keep" seems inappropriate.
    What are the actual Color Spaces (ICC profiles) involved?
    Is there a way to compare the resolution of 2 images somehow, or how can I see what I lost through the 2 conversions?
    How did resolution come into this?
    To determine how large a portion of the image has been changed you could
    • make a flattened copy of the original image
    • place a flattened copy of the RGB->CMYK->RGB image on top of that and set it to Blend Mode Difference
    • add an Adjustment Layer (Curves for example) to brighten the image

  • How can I convert RGB Color to Black-White Color?

    Dear everyone!
    I am using Photoshop CS5. I have got a file from my customer which is done as RGB and the resolution is 300dpi. There are black texts and color images in the file. I wish to print Black-White Process Film (1 black color), but I don't know how to solve it. I started converting my file to Grayscale and then the black texts are not black enough because it becomes lighter. When I go to Level and adjust the color, both the image and texts becomes darker. What must I do to make only texts blacker without effecting the image?
    Please find the attached file for the reference.
    For more information, please let me know.
    My Best Regards,
    LUCK

    luck_lesson wrote:
    ...I have got a file from my customer which is done as RGB and the resolution is 300dpi. ..
    What file format was supplied to you? Was it truly RGB @ 300ppi or did you rasterize a PDF?
    300ppi is lousy for text. You might converse with your customer to instruct them on the ideal way to supply a file to you.

  • My screen went from color to black and white spontaneously. I checked the grayscale and invert color options under Accessibility but neither were activated. Hard reset failed to cure the problem.

    Iphone 5 with IOS 8 just switched from color display to black and white. Accessibility options were not changed and hard reset failed to cure

    Problem solved by resetting all preferences, which was not my preference.

  • How to tell b&w image from color?

    Sounds spectacularly dumb, I know, and maybe it is, but here goes:
    I have been scanning old b/w photos as color for a book; however, I believe that when I wasn't paying attention, a handful were scanned as b/w. How can I tell whether they were scanned in color or in b/w, in which case I'll have to rescan them?
    flat-screen iMac   Mac OS X (10.4.4)  

    Hi Eliot,
    I don't understand why you would want them in RGB. A b&w photo is just that, b&w. Having it in RGB is still b&w (all pixels with identical values in each channel). The only thing you succeed in is tripling the size of each image by having them in RGB rather than grayscale.
    Then there's the problem of RGB when it comes to printing. I'm talking about professional publication here, not ink jet or laser prints. If you convert a b&w file saved as an RGB file to CMYK, most of the color will be converted to the CMY channels with a minimal black. This causes huge headaches on press. Any slight variation of ink on paper will cause the images to shift blue, pink or green depending on which of the CMY inks go off balance during the print run. You are far better off saving b&w images as grayscale. Both for printing and saving space on your drive. A grayscale image will print as black only. With no problems of color shifting as would happen if separated as a CMYK image.

  • How to insert cropped images from photoshop without the white background

    Basically all I want to do is take a peice of writing from a video and insert it into another video. To do this I've took a screenshot of the font from the video and imported it into photoshop. I've then cropped/cut/took the the peice of writing I want, letter by letter. I want to be able to insert it into another video, but whenever I attempt to do it, I have the default white background of photoshop. Is there anyway to insert an image from photoshop, without taking the background with it, or even insert a layer from photoshop straight into final cut pro? Sorry if this is confusing.

    I don't think so. I cropped the letters, put them each an individual file, removed the background, saved them as a TIF then tried to import them onto Final Cut Pro, but a white background still appeared in the TIF file. Basically I just want to make the background transparent I believe.

  • How to keyframe from colour to black & white

    I am trying to do a video from present then moved to the past. So I am starting a clip from colour, then slowly it turns into black & white.
    I have 2 questions:
    1) How do I keyframe the above effects ?
    2) Instead of using the Sepia effect, is there other effects to make the video black & white ?
    Thanks

    Tom Wolsky wrote:
    Use the desaturate filter. Open the clip with the filter applied into the viewer and in the Filters tab keyframe the values from to go from 0 up to 100 to be fully black and white.
    Thanks Tom, it works !!

Maybe you are looking for

  • Cant change line length in terminal.  I googled at least 2^3x.

    I googled at least 2^3x. I am troubleshooting something out of Head First Python.  It has to do with a server and I ran ps x to see if the server was running. But a good number of the processes were longer than the 137 characters my terminal is set a

  • Urgent MPEG2 question (pixel aspect ratio)

    Is a composition that is set as a D1/DV NTSC Pixel Aspect Ratio (0.91) able to be exported as a MPEG2 file? I have a very large, very complicated project file with a D1/DV NTSC Pixel Aspect Ratio and I'm trying to save it as a MPEG2 file type because

  • Unable to assign values to Document Objects.

    Hi, I am trying to create a Purchase Order via the Business Objects but the code seem to break when I assign a field to a value. Here is my code: 'To create a new PO Dim oPurchaseOrder As SAPbobsCOM.Documents oPurchaseOrder = vCompany.GetBusinessObje

  • "This Apple ID has not purchased 'OS X Lion'"

    Hello, I recently wiped my hard drive and now when I get to the Mac OS X Utilities screen and try to reinstall my Mac OS X, it tells me that my Apple ID has not purchased Lion. When I first got this computer, I'm pretty sure it was running Lion, but

  • I getting document type error

    hi,         I am trying to extend material from one plant to another. But system showing error like Please enter document type 50. Any how I want to copy this material. ( I mean , I dont want create manualy in another plant). so, please some tell me