Reduce number of colors in an Image

Hi,
I have a bufferedimage that is a screenshot of my pc, what can i do to reduce the number of colors in the image to 512 or somthing? The final image will be in JPEG form.
Thanks

I tried this code, but there must be a bug or something cos most things turn black and red....even when i specify 512 colors...I saw http://forum.java.sun.com/thread.jsp?forum=31&thread=446716 that someone else had this problem, but i did not find a fix. Its weird cos I used another java quantizer that did the same thing..
Here is my code:
byte[] = toByteArray(getScreenshot());
/*****Takes a screenshot*****/
private BufferedImage getScreenshot() {
     try {
          Robot robo = new Robot();
          Rectangle rect = (GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds());
          BufferedImage img = robo.createScreenCapture(rect);
          return img;
     } catch (AWTException exc) {
          exc.printStackTrace();
     return null;
/*****Saves a BufferedImage as a JPEG*****/
private byte[] toByteArray(BufferedImage img) {
     try {     
          //WANT TO QUANTIZE img HERE
          //Encode
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
          JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
          param.setQuality(.45f, false);
          encoder.encode(img, param);
          out.flush();
          out.close();
          return out.toByteArray();
     } catch (Exception e) {}
     return null;
}

Similar Messages

  • How to reduce number of colors in an image

    I am fairly new to Photoshop and I'm learning as I go, so I apologize for using your time.  I haven't worked with images that much - I've used MS Digital Image Suite with photos from my camera.  That's the extent of my knowledge.
    I am taking over a job from someone who is gone and I can't ask him how to do this.  He used Photoshop to reduce the number of colors in an image (for example, a color drawing or clipart) to 2-6 colors.  I haven't been able to figure this out.  I've visited this site that explains how to reduce tones but it's still a lot of colors.  I thought I might learn something from this link that explained how to make Photoshop cartoons, but I didn't.  I've done a lot of searching but nothing seems to explain this.  I know that the other guy had some knowledge of Photoshop but he wasn't a power user.
    Thanks to anyone who will help me.  (I am using CS5.)

    Are you sure that he was using Photoshop? (see my third solution)
    There are some plug-ins for Photoshop, but they basically do the same as the posterize or index mode: http://www.topazlabs.com/simplify/ (commercial) see this panel for colorizing comic art: http://vimeo.com/user3771002/videos
    I would rather use posterize, as an adjustment layer, as you can control it.
    Try with this layer stack, from bottom to top:
    Convert the original image in a Smart Object, in order to use Smart filters and blur the image (Gaussian Blur, or noise>median or blur>smart blur or blur>surface blur could be interesting internatives) would be useful, to make smoother posterized areas.
    A dodge/burn layers (a neutral gray layer in overlay mode) to adjust areas using the Dodge/burn tools.
    the Posterize Adjustment layer, with very few colors
    On top of it, put a gradient map adjustment layer, to control the posterized colors
    Vectorizing in Illustrator can also be used to reduce the number of colors. Live Trace: http://help.adobe.com/en_US/illustrator/cs/using/WS714a382cdf7d304e7e07d0100196cbc5f-6229a .html
    More on the topic: http://help.adobe.com/en_US/illustrator/cs/using/WS714a382cdf7d304e7e07d0100196cbc5f-622aa .html

  • Does anyone know of a way to reduce the number of colors of an image

    I have read all the documentation on this and there is no clear and easy way to reduce the number of colors of a bufferedimage. It would be also handy to know how to ensure that the image stays under specific size.
    thanks for any help
    Lee

    Yeah Abuse you are sooo right, i have written code to do this and it was/wasnt fun depending on your sense of humour...
    Heres how it works..
    *1 pick a pallet, the more colours, the bigger the result file, but better quality
    -so decide what you want
    *2 for each pixel find the nearest colour in your pallet that matches it.
    -its important to count each pixel rather than each colour in the original as a large block of 1 colour should have more weight
    *3 then for each colour in you pallet average out the colour of all pixels that would become that colour
    -the average becomes the new best colour for that pallet entry
    -since the pallet has now changed repeat 2 and 3 as long as you want, or rather untill nothing changes
    * if at any time a pallet entry has nothing that maps to it then make it become a colour that is near the most used pallet entry.
    have fun, its called cluster theory and is used lots in converting images to .GIF

  • Levels adjusment to only selected colors in indexed image?

    I regularly have to adjust ranges of colors in indexed images. I usually use "Image -> Adjustments -> Replace color..." to do this since it effectively allows me to pick multiple color table entries and apply Hue, Saturation, and Lightness adjustments to them. What I could *really* use now and then, however, is the ability to apply a Levels adjustment to the selection. Unfortunately, I can only seem to apply a Levels adjustment to the whole indexed image, not just ranges of color table entries. I can't convert to RGB first because the color tables I end up with have to be applicable to the same image (the pixels in the image have to continue to reference the same color table index; converting to RGB and back breaks this association).
    Does anyone know if there's something I'm overlooking? The "Lightness" adjustment in the "Replace color..." tool just doesn't cut it for the level of adjustment I need.

    Here's a test I did.  First I created the rhinestone shape (rough shaped), with transparent background). I used a size of 30px and made a pattern of it.
    Then I took this photo and reduced it to the number of pixels that I wanted for each of the dots.  So in this case, I wanted 100 dots across the top, So I reduced the image to 100px wide.
    Then I converted it to index color with the five colors your wanted: white, black, red, yellow, and blue.
    After that, I converted back to RGB and upscaled it using nearest neighbor to keep the pixelated look.  I upscaled it so each pixel was my pattern size of 30px, so 3000%.
    Then I created a blank layer under this pixelated layer, and used the fill command using the pattern I created in the first image.  I clipped the pixelated layer to the fill layer, so that the colors would just show where my pattern had pixel values (round dots).  Then I set the pixelated layer's bend mode to overlay to get the look of a rounded dot.
    It looks a bit flat, but you can play with different patterns to get different looks.  I also put a solid black layer under everything to fill in the gaps between the dots.

  • Changing colors of an image in real time

    Hi,
    I am trying to get an image raw data in an int[] array using getRGB() in order to change the color of the image.
    But it is working fine in simulator for any image. if i install it in real device say Nokia 6600 the getRGB() method is not working for large .png image like size (88X57) because the device gets hang while we are using large image but it is working fine for small image.
    Pls give me some idea how to use getRGB() for large image.
    Following is the sample code
    int imageWidth = img.getWidth(); 
    int imageHeight = img.getHeight();
    int[] raw = new int[imageWidth*imageHeight];
    img.getRGB(raw, 0, imageWidth, 0, 0, imageWidth, imageHeight);Thanks in advance

    Use the AI CONFIG to set up your acquisition.
    Use AI CLOCK config to set up your timing.
    Use AI TRIGGER CONFIG to set up your trigger.
    Use AI CONTROL to start the DAQ (use TOTAL SCANS TO ACQUIRE = 0 for unlimited scanning.
    repeat (While loop)
    Use AI READ with a NUMBER of SCANS TO READ = 0. This tells you the backlog (how many scans in the buffer)
    Use AI READ with NUMBER OF SCANS TO READ = to the backlog number from above. (this empties the buffer)
    Process the scans received into your image - append to previous data and re-display.
    If you are doing a fixed number of scans, add this backlog number to the total done so far, and see if you're done. If you're doing continuous, skip this step.
    Wait 100 mSec if you can, 10 m
    Sec if you can't.
    Loop (until # scans done >= # scans wanted OR Quit button, whatever).
    Use AI CONTROL to stop the DAQ.
    The idea is that the DAQ operation happens in the background. You just ask how many are available, and then read that many and use them.
    You wait 100 mSec to allow the display update to happen.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • 6120c - number of colors seems to be decreased in ...

    Hi all.
    It seems like number of colors is being decreasend in the theme background image every time I install a theme. It can be best noticed in gradient-like images where color transition is not smooth.
    nokia noir theme may be a good example here - on my 6300 background is nice and smooth, on 6120c it looks like it was just 256 colors or so...
    Has anybody else noticed that ? It's really annoying because all nice themes don't look like they should.

    but it can only be seen on images used as a background in a theme.
    when you set your own background everything's fine - image is displayed properly (no banding, smooth color transitions), but that's not the solution I am looking for.

  • How can I search for a particular color in an image?

    Hi,
       I am working on images of colored balls.
    I want to search for the particular color (of the ball) and select them .
    How can I do it?
    Your suggestions will be helpful.
    Thanks
    dsk

    Hi Dsk, 
                   you can apply color threshold and extract the required color in the image. Try color threshold in vision assistant.
                  see  here
    Thanks as kudos only

  • Spry vertical menu button shows background color instead of image in preview

    Hello All, I'm a newbie (to the forum and Dreamweaver) so my apologies if my question is not in good form.  I've searched for this issue but cannot seem to find the exact problem I have. 
    I've created a website (my first) and used the spry menu bar.  It works well using the default blue and grey colors for button and hover.  However, I decided I want to spruce it up a little and change the buttons to use a background image (rainbow pattern) instead of background color.  I internet researched this for some time and watched all the youtube videos people have posted for this process and editing the spry vertical menu bar CSS.  Using the .a and hover lines from the CSS, I was able to add my background .jpg image file.  In the design view, the button look exactly how I want them to.  However, when I attempt to preview in IE, Chrome, or FF, the buttons still have the default colors and no image.  I've gone back and deleted the default blue and grey, but then the preview just shows dark grey and white for the buttoms.  is there something that I am overlooking that would cause the background color to show instead of the image I have attached to the buttons.  I can't figure out why it looks right in DW but not in preview.
    BTW, I'm editing a template file and all the pages are updated with the new image buttons, but none of the pages show correctly in preview. 
    Thanks

    Point taken :-)
    This is my spry vertical css code.  No sub-menus. 
    DESIGN INFORMATION: describes color scheme, borders, fonts
    /* Outermost menu container has borders on all sides */
    ul.MenuBarVertical
    border: 1px solid #CCC;
    /* Submenu containers have borders on all sides */
    ul.MenuBarVertical ul
    border: 1px solid #CCC;
    /* Menu items are a light gray block with padding and no text decoration */
    ul.MenuBarVertical a
    display: block;
    cursor: pointer;
    padding: 0.5em 0.75em;
    color: #333;
    text-decoration: none;
    font-weight: bold;
    background-image: url(/Images/Rainbow_Button.jpg);
    background-color: ;
    background-repeat: no-repeat;
    background-position: center;
    /* Menu items that have mouse over or focus have a blue background and white text */
    ul.MenuBarVertical a:hover, ul.MenuBarVertical a:focus
    background-color: #666666;
    color: #333333;
    background-image: url(/Images/Rainbow_Button_Hover.jpg);
    /* Menu items that are open with submenus are set to MenuBarItemHover with a blue background and white text */
    ul.MenuBarVertical a.MenuBarItemHover, ul.MenuBarVertical a.MenuBarItemSubmenuHover, ul.MenuBarVertical a.MenuBarSubmenuVisible
    background-color: #0000FF;
    color: #FFF;

  • IDVD is stripping most color from my images in my slideshow. Please help!

    I have received so much help from this forum....
    I am running iDVD 7.1.2 and Mavericks 10.9.5.
    So I started an iDVD project about 18 months ago on a different computer.
    I saved the project to an external HDD so I could move it from an iMac with a bad DVD drive to a MacBook with an awesome superdrive.  This has always worked for me.
    But I don't think think that information affects my current problem.... just tossing it out there because sometimes information we don't think is relevant is certainly relevant to a knowledgeable person!
    Fast forward 18 months or so. I open the project on another computer, but iDVD is stripping all but the brightest colors from the images in my slideshow.
    Is this a Mavericks thing?
    I have tried, in numerous variations, even to the point of starting a completely new DVD project and dropping the images into the app..... still the same problem:  all the images are mostly black and white (or gray tones at best), with the occasional colored brightest elements from the original photo.  (It's a cool effect, just not appropriate or desirable for this particular project.)
    I have tried the project on different computers, both with opening a new project and with building a new project.   It just doesn't matter.  The slideshow images lose color.  Except, an interesting caveat is that if I pause the playback, click the previous slide button, then play: the image has full color again.  But subsequent images are again B&WwC.
    I figure it must be something awry with the settings in Wirecast.....
    Thank you so much for any assistance.
    Dee Dee

    Hi
    In what kind of format is Your photos ? .jpg, .tif, .bmp else
    What size are they ?
    How many ?
    How many slideshow set's ?
    You are aware of the 99 photos per serie limit. And 99 series/chapters limit per DVD disk ( not iDVD but DVD-Standard in general ).
    Yours Bengt W

  • How do you keep the colors of an image true when you set it as a background?

    I have an image with lines in it and a black blackground. When I set it as a background :
    html {
        background: url(../Images/backgroundimage.jpg);
        background-repeat:auto;
        background-position:center top;
    the black is a couple shades lighter so when I place a <div> with an <img>that is also mainly black on top of it, the top image is much darker than the background. I have no other css tags on the div other than a margin. The only difference in the images is I saved the background from photoshop and the image in the div from illustrator but I dont think that should have effected anything. Does anybody know anything about this because I am seriously stumped.
    Thanks

    We have been here before…
    Firstly, Adobe' Photoshop has the ability to save a color profile with an image. That color profile will be consistent across all versions of Adobe software. Problem is, Adobe does not make web browsers (and that is probably a good thing).
    When you save images for websites, you need to go through the proper Photoshop or Illustrator dialog. You want to Save for Web & Other Devices. Why? because the applications will take the image out of CMYK color space (if it is in that color space) and make it RGB. They will also try to translate the colors in a sensible way. When you use this dialog, you will see various options for JPG, including ICC Profile. Turning this on or off will change how the colors get mapped, and some experimentation to get best results is a good idea.
    I have it turned off, presently.
    The image will be set up for 72 dots per inch automatically, and you can, then, resize the image to optimize it for the website you are working on. If you are trying to fill a hole for an image that is 350 pixels wide by 250 tall, don't save the image as 1125 wide by 1024 high. That will take a long time to download from your server to whatever device is displaying it. Your original image will not be changed and you can navigate your path to your defined website's images folder.
    This should help you immeasurably. I should mention that If I am trying to match a background exactly, I will tend to knock out that color from the image, save the image as a .PNG file with transparency (where that particular color is) and place the image on the background in question with the background color I am trying to match on the website.
    -Mark

  • How can we change the  color of the image for product display for different

    Hi All,
    How can we change the  color of the image for product display for different colors, to be displayed on site.
    jeff

    Hi priya,
    The requirement that you have stated is not a standard feature in ISA CRM. In order to do the same, you will need to modify the standard ISA code in Java. A common path for the solution would be as follows:
    1. Colours
        a. Maintain a text type for Color under the object - PCAT_ITM in Customizing.
        b. Modify the standard search of ISA to search within your new text type as well. (In standard it only searches in Description.
       c. Maintain all shirts colour data in the new type created in step a.
       d. Your requirement will be done!
    2. Price
      a. Use list prices for your shop and assign the appropriate condition type, acces in your catalog.
      b. Modify the standard search of ISA to search on the list prices as well.
      c. This too will be done!
    3. Accessories - This is very tricky, and will require some exploration. However, here's my opinion,
    a. Search for the standard function module, which will return the accessories when provided the product as an input.
    b. Modify this function module according to your requirement and ensure that it can be accessed remotely.
    c. Modify the JSP as in steps 1b and 2b above to call this new remote-enabled function module.
    d. Now you're done!!
    The ISA modification part is not so simple, you need a really good guy like "Sateesh Chandra" who'll be able to handle your requirements. This is all I could manage, hope it is some help to you!
    Thanks & Regards,
    Nelson.

  • How to determine the color of any image sent to me

    Hi All,
    I was sent a gif image to work on and use the color of the image (RGB) to apply themes to the website.
    But I don't know the RGB code of the color used in creating the image. How can I find the color in Photoshop CS4?
    Thanks

    … and color code is available from the color picker, or the window/color panel (web color sliders)

  • How to set canvas extension color for arbitrary image rotation?

    I'm using Photoshop CS4 v 11.0 with Windows XP.  When adjusting canvas size there's a menu for chosing the canvas extension color.  Where is the menu for chosing canvas extension color for arbitrary image rotation?
    Thanks.

    This will be the background colour selected in your toolbox.

  • How can I increase the number of pixels in an image?

    How can I increase the number of pixels in an image?

    You can't.
    The number of pixels in an image is decided by the camera that shoots the image
    With an app like Photoshop you can interpolate - this will make a guess as to what a particular pixel may look like based on the ones around it. Results can vary wildly and Photoshop is expensive.
    Regards
    TD

  • How can I reduce number of rows in Planning webform in Smartview?

    Hi,
    I downloaded a Planning webform into Smartview. I want to reduce the 1000 rows down to 20 for a particular user as he does not submit data for the other 980 rows. How can I reduce number of rows in Planning webform in Smartview?
    Someone said that I can insert vlookup code into Smartiveiw pointing to a new worksheet that has only 20 rows. I could not test it as our Planning 9.3.1 has a bug that would not take sub variables from Smartview.
    Thanks.

    Hi,
    My first reaction is why do you have a form with a 1000 rows, surely this is a design issue and doesn't benefit anybody when entering data, anyway why not have security on the dimensions then users will only see what they have access to when they retrieve the form in smart view or through the planning web front end.
    Cheers
    John
    http://john-goodwin.blogspot.com/

Maybe you are looking for

  • Logon Failed DAO Error Code Oxccb

    I received a new project for the creation of a Crystal Report in the form of an Excel spreadsheet.  I created the report, but then my boss decided to modify the spreadsheet.  I saved his new file as the same name as the old file and said replace.  Th

  • Aperture web galleries

    Ok, an Aperture update. It still appears that published web galleries do not show up in the Iweb insert menu. If a gallery created in Iphoto or Aperture is viewed all galleries created by both appear in the gallery area on the web. Only guessing this

  • Storage location issue in case of BOM

    Hi All, I have a issue related to storage location determination. There are three materials X,Y and Z. Material X is main item and Y, Z are components of X. While creating sales order when we enter X it explodes BOM. Now in customizing for material X

  • Consumed project materials - inventory in ps ?

    dear ps experts, pl let me know whether projects materials consumed in project (ie., gr against nw pr-po done), can any where the same material shown as projects material inventory (virual)? currently i am creating the automatic pr-material in networ

  • Multi Pages TIF Images

    Dear All, I have an attachments form that read an image files from client machine and store it in an oracle BLOB column. I use the following code to transfer the file from client machine to my database table : webutil_file_transfer.Client_to_db(filep