Convert RGB to hex!! (Help!)

Hello programmers,
i've have a problem... i get the rgb values of a color easily by getRGB() or getRed(),.... but do not know how to convert them (Example 255,255,255)to #rrggbb value (hexadecimal value)(like in photoshop)... can anyone help me in finding a function to do it or give me an algorithm to produce hex values out of digits (the rgb values)
Thanks in advance
Bernard

public String rgbToHex(Color c)
    String s = Integer.toHexString(c.getRGB() & 0xFFFFFF);
    while(s.length() < 6)
        s = "0" + s;
    return s;
}

Similar Messages

  • Converting RGB images (sRGB or Adobe RGB) to 709 color space.

    I'm trying to determine the correct way to convert RGB images (sRGB or Adobe RGB) to 709 color space.  I can't just use the "covert to profile" function to do this because it does not produce results that fall within the 16 to 235 range that 709 dictates.  I've read that you can simply use the "Levels" adjustment and change the output levels to 16 to 235.  While this would clearly compress the luminance to the correct range, I'm not entirely clear if the end result would be a proper conversion (i.e. if color and gamma, for example, would be technically correct.)
    I noticed that converting the profile to "HDTV (Rec. 709)" does alter the image, so I'm wondering what the result would be if I did both this AND used the levels control to compress the output range to 16 to 235.
    Thanks for any feedback on this.

    (1)
    http://en.wikipedia.org/wiki/Rec._709
    (2)
    http://en.wikipedia.org/wiki/Rec._601
    The transfer functions for Rec.709 (1) refer to the range [0..1] or for 8 bits per pixel [0...255].
    It seems that the clipping, black=16 and white=235 has to happen after the application of the
    transfer function. If this should be true, then we don't have a level compression but a level
    clipping at both ends, as already for Rec.601 (2), like here:
    The ICC-Profile HDTV(Rec.709) in Photoshop contains the primaries and the white point
    (both like that in sRGB) and the transfer functions for [0..1], coded by a LUT with high resolution,
    as found by Profile Inspector. There is no clipping.
    By the way, that`s the internal profile name, I don't know the file name of the profile.
    Softproofing, source in sRGB, target HDTV(Rec.709), without clipping:
    With numbers not preserved: no change of the appearance, as expected.
    With numbers preserved: shows the effect of different effective gammas. 
    Your questions are very clear and I'm not sure whether my comments help. The information
    in the internet is not convincing.
    Best regards --Gernot Hoffmann

  • ICC profile to convert RGB to CMYK,   jpeg is ok, png format have a problem

    When I use ICC profile to convert RGB to CMYK, jpeg format is ok, but png format have a problem.the color is lossy.
    It means, the png file color is shallow than jpeg file after convert.Could anybody help me?
    thanks
    source code
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.Iterator;
    import javax.imageio.IIOImage;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageTypeSpecifier;
    import javax.imageio.ImageWriteParam;
    import javax.imageio.ImageWriter;
    import javax.imageio.metadata.IIOMetadata;
    import javax.imageio.metadata.IIOMetadataNode;
    import javax.imageio.stream.ImageOutputStream;
    import org.w3c.dom.Node;
    import com.sun.image.codec.jpeg.ImageFormatException;
    import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGEncodeParam;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
    public class TestImage {
         public static void main(String args[]) throws ImageFormatException, IOException{
              BufferedImage readImage = null;
              try {
                  readImage = ImageIO.read(new File("C:\\TEST.jpg"));
              } catch (Exception e) {
                  e.printStackTrace();
                  readImage = null;
              readImage = CMYKProfile.getInstance().doChColor(readImage);
              writeImage(readImage, "C:\\TEST_after_.jpg", 1.0f);
        protected static String getSuffix(String filename) {
            int i = filename.lastIndexOf('.');
            if(i>0 && i<filename.length()-1) {
                return filename.substring(i+1).toLowerCase();
            return "";
        protected static void writeImage(BufferedImage image, String filename, float quality) {
            Iterator writers = ImageIO.getImageWritersBySuffix(getSuffix(filename));
            System.out.println("filename�F"+filename);
            if (writers.hasNext()) {
                ImageWriter writer = (ImageWriter)writers.next();
                try {
                    ImageOutputStream stream
                        = ImageIO.createImageOutputStream(new File(filename));
                    writer.setOutput(stream);
                    ImageWriteParam param = writer.getDefaultWriteParam();
                    if (param.canWriteCompressed()) {
                        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);//NO COMPRESS
                        param.setCompressionQuality(quality);
                    } else {
                        System.out.println("Compression is not supported.");
                    IIOMetadata metadata = null;
                    if(getSuffix(filename).equals("png") || getSuffix(filename).equals("PNG")){
                         ImageTypeSpecifier imageTypeSpecifier = new ImageTypeSpecifier(image);
                         metadata = writer.getDefaultImageMetadata(imageTypeSpecifier, param);
                            String sFormat = "javax_imageio_png_1.0";
                            Node node = metadata.getAsTree(sFormat);
                            IIOMetadataNode gammaNode = new IIOMetadataNode("gAMA");
                            String sGamma = "55556";
                            gammaNode.setAttribute("value", sGamma);
                            node.appendChild(gammaNode);
                            metadata.setFromTree(sFormat, node);
                    writer.write(null, new IIOImage(image, null, metadata), param);
                    writer.dispose();
                    return;
                } catch (IOException ex) {
                    ex.printStackTrace();
    }

    Hi,
    I am having similar problems. I have read somewhere that png format can not handle CMYK colorspace anyway, which I find odd (and plainly stupid IM(NS)HO) which would mean that converting to RGB and therefore using profiles is mandatory.
    May be you should check if the internal format of the png files claims it is RGB or CMYK (using ImageMagick's "identify" command for example).
    HTH
    JG

  • Exception occuring while i'm trying to convert decimal to Hex

    Hello all you genius people, please help me out. I'm using this simple code(given below) to read String from a file then convert it to Hex and write in anoher file. But i'm getting this exception that, after reading few lines it gives such exception:
    java.lang.NumberFormatException: For input string: "2826111134"
    import java.io.*;
    public class DecimalToHexConv {
      String line;
      String hexEsn;
      String temp;
      int esn=0;
      public DecimalToHexConv(){
      try{
        FileWriter fwr = new FileWriter("CTGHLR201005_out.txt");
        BufferedReader bfr = new BufferedReader(new FileReader("testin.txt"));
        while((line=bfr.readLine())!=null){
          line= line.replace('|',';');
          String spl[] = line.split(";");
          esn = Integer.parseInt(spl[2].toString().trim());
          hexEsn = (Integer.toHexString(esn)).toUpperCase();
          temp= spl[0]+"|"+spl[1]+"|"+hexEsn+"\n";
          System.out.print(temp);
          fwr.write(temp);
        fwr.close();
      catch(Exception e){
        System.out.println("Exception: "+e);
      public static void main(String[] args) throws Exception {
        DecimalToHexConv dtc = new DecimalToHexConv();
    }output:
    4702181500|11800467|2FA42C8B
    4702825345|11704172|620A4CFC
    4703200000|11200000|52B53DB9
    4703200001|11200001|52156AC7
    Exception: java.lang.NumberFormatException: For input string: "2826111134"
    testin.txt:
    4702181500|11800467|799288459
    4702825345|11704172|1644842236
    4703200000|11200000|1387609529
    4703200001|11200001|1377135303
    4703200046|11200046|2826111134
    4703200000|11200000|1387609529
    4703200001|11200001|1377135303
    So after converting first 4 lines i got the exception. Please hep me out.. that what is wrong???
    Regards
    Sahrear

    But i'm getting this exception that,
    after reading few lines it gives such exception:
    java.lang.NumberFormatException: For input string:
    "2826111134"It's because the biggest number an int can hold is 2147483647. You can use long insted. It can hold bigger numbers but understand that it has an upper limit too.

  • Is there as easy way of batch converting RGB files to CMYK in OS Lion?

    Is there as easy way of batch converting RGB files to CMYK in OS Lion?
    I was using a photoshop droplet on my desktop but this no longer works due to the fact it requires rosetta support.
    Thx P

    From another forum after googling:
    Your computer came with everything you need, because ColorSync can do that and Apple provided AppleScripts for it. Go to your Applications folder and look for the AppleScript folder. Double click on the 'Example Scripts' alias and then open the ColorSync scripts. Drag and drop your images on the the 'Match to CMYK' script.
    You can open AppleScript Editor from Launchpad (it's in Utilities). Go to Help to Open Example Scripts Folder. In the ColorSync folder is a Match application. Double click to make it run.
    Now you know what it does you may need to change it for batch conversion.
    Go to AppleScript Editor and open what you've just found. And I'm sorry that's as far as my knowledge goes, hope some one can fill in the gaps.
    Or you may just want to look at something like Graphic Converter?
    Regards,
    Colin R.

  • JMS Correlation ID not converting to EBCDIC Hexa

    We are using the PI 7.1 system on a AIX platform.
    We use the JMS adapter to send messages to a MQ Queue manager on a AS400platform.
    WebSphereMQ transport protocol is in JMS adapter.
    We are generating custom dynamic correlation id using a UDF.
    Expectation is to receive the correlation id in Ebcdic format because the
    receiving end is a AS400 system.
    But what I receive there is a Ascii Hexa.
    For a example we are sending the correlation id as 0180000012. (ASCII)
    What MQ receive is 30313830303030303132 (ASCII HEX)
    Where what MQ should receive is F0F1F8F0F0F0F0F0F1F2 (EBCDIC HEX)
    I need help to find out why JMS adapter is converting the correlation id
    in to ASCII HEX without converting to EBCDIC HEX.
    Appreciate a lot if any one can provide some help on this.
    Thanks a lot,
    Tania.

    I am not sure if I have understand the issue correctly.
    Do you create an ASCII string and the ASCII characters are not converted into EBCDIC,
    or do you create a HEX String?
    Or does the JMS adapter converts your ASCII string to Hex?
    I have the impression that the behaviour is a design gap, which nobody has noticed before.
    A work around could be in converting the ASCII to EBCDIC inside the UDF,
    Report this to SAP

  • Convert RGB black to CMYK black

    PHOTOSHOP CS5
    I have a complex black-ink line drawing in large precentages of C, M, Y, & K. I'd like to somehow SELECT ALL PIXELS and zero out all but 100% K.
    I cannot figure out how to select all (nonbackground) pixels (no, Select>All does not accomplish) and then make them all 100%K, can you help?

    Yes, I need to end up CMYK. As you can see by my sample Photoshop converts RGB to crazy-high CMYK percentages. All I want these lines and text to be is 100% K.

  • Hi, cannot convert RGB to CMYK...

    I cannot find such an option in the Elements? Can anyone help how can I convert the files to CMYK from RGB using this tool...
    Thanks
    ansu

    Elements can't convert RGB to CMYK. You'd need the full Photoshop.
    Otherwise you can google 'RGB to CMYK' conversion to find online or software tools that can do that.
    The real question is why do you need CMYK. If it's a request from a printer shop, it's their job and responsibility to do the conversion, since such a conversion can only be properly done when you know the specificity of your printing tools, inks and papers.

  • How to convert signed ascii hex to float value

    Hi,
    I have a requirement to convert IEEE ascii hex to float value.
    Following code is working for +ve float value but it didn't work for -ve.
    public static float hexToFloat(String str){
              float floatVal= 0.0f;
              int decimalValue =Integer.parseInt(str,16);
              floatVal=Float.intBitsToFloat(decimalValue );
              return floatVal;
    for example "BE4CE1E6" should return -0.20 . (i verified in http://babbage.cs.qc.edu/IEEE-754/32bit.html )
    For the above string I am getting number format exception.
    pls help me.

    The problem is the parseInt method. It can only process numbers up to 2147483647 or 7FFFFFFF. Because that method expects a signed number.
    The solution is to use Long.parseLong() instead.
    public static float hexToFloat(String str){
    float floatVal= 0.0f;
    int decimalValue =(int)Long.parseLong(str,16);
    floatVal=Float.intBitsToFloat(decimalValue );
    return floatVal;
    }

  • Rich black when converting RGB to CMYK

    I'm working in an older version of PhotoShop (7) but any help on the topic would definitely help.
    My problem is that I am converting RGB native images to CMYK and my Key (Black) comes out rich, contains equal levels of CMY and K, instead of true black, only k.
    Currently my way around this is to do the standard convert to profile CMYK and with my path selected to the section I would like to be true black simply turn off all CM and Y channels and re-save the image but this is a little labor intensive.
    Is there a way that I can go straight from RGB to CMYK and achieve true black without alteration?

    Yes, there is. You can use a CMYK setup or ICC CMYK profile that uses Maximum black generation. Unfortunately, that will almost always hose anything photographic in your image.
    Is it typographical elements that are becoming four color? If so, then they should be done in a page layout program where they can be rasterized separately from the photographic image. If it is type you're worried about, is it large type or small? If you have to set large type in Ps, then it's probably fine to let it run four color.
    If it were me and I had to do everything in Ps, I would probably make two conversions of the file to CMYK - one with a standard black generation and one with Max K. I would then select the black you want from the max K version and paste into the K channel of the "normal" document, and then use that as a selection to delete from the other three channels.
    A third way is to do type in Ps and leave the type as a vector type layer, then save the file out as a Photoshop PDF, which is then placed in a layout app. or just sent to the printer through his RIP. That should work too, but there are too many places for things to wrong for my taste.

  • Script to convert RGB values to CMYK values

    I want a script that can help me convert RGB value to CMYK values.
    I've seen this thread which explains a script to round up and down:
    http://forums.adobe.com/thread/1079041
    but is there a script that i can actually define lets say the colour is yellow and in RGB it looks ok because its in RGB mode so you change it to CMYK and you have 6% - 9% cyan and you only want yellow
    is there a script out there that i can say
    if
    cyan = 6%
    yellow = 80%
    magenta = 0%
    black = 0%
    then change to
    cyan = 0%
    yellow = 80&
    mangenta = 0%
    black = 0%
    I don't mind writting the code for each colour that needs to be converted as it would only need defining once but how would i make this script?
    any clues?

    Hi Carlos,
    I've got a bit further with applescript as i've used it a little but i've got an error this is my code so far:
    tell application "Adobe Illustrator"
              if exists color is equal to "C=0 M=0 Y=0 K=90" then
                        set color to "C=0 M=0 Y=0 K=100"
              end if
    end tell
    The error i'm getting is "can't get color"
    the color is there however i believe i must not be using the correct variable any clues?

  • Converting RGB PDF to CMYK PDF

    I'm looking for a way to convert RGB PDF's to CMYK PDF for printing purposes. The RGB PDF is created by an online Flash application and I'm hoping to convert the file using Acrobat via Command line. I have tried a couple of programs e.g. PStill and PDFcreator but these just don't do the job. It's important to use the command line due to the fact that the conversion must be done automatically on a dedicated server.
    Important to know is that the PDF consists of texts and images and gradients. This is a RGB example which I would like to convert. This is the CMYK output I have created manually.
    Other solutions next to Acrobat are also welcome as long as they do the job

    In your original message you say "the conversion must be done automatically on a dedicated server" - this implies that Acrobat is being used outside the EULA, which strictly forbids installation as a server process. Acrobat is licensed for individual interactive desktop use by one person, no other deployments are allowed.
    You cannot access Acrobat's editing and batch-processing functions from the commandline at all. Adobe has server-based solutions for PDF generation  (LiveCycle ES3) but they are extremely expensive and would need work to get them to do what you're looking for. Realistically, your Flash developer needs to recode his app to output in CMYK or you will need third-party software on the server to re-fry the files. I don't know of any off-the-shelf commandline tools which can perform color conversion on existing PDFs.

  • Convert RGB to CMYK in AI

    Hi, my printing house said I sent him a RGB file and he needs CMYK for printing. 
    (1) How can I know the original file is RBG color mode?
    (2) How to convert RGB ai file to CMYK ai file?
    Thanks a lot!!!

    lhcheng,
    1) File>Document Color Mode.
    2) Tick CMYK instead of RGB.
    You should be aware that the RGB and CMYK colours are fundamentally different, so most likely you will have to create at least some colours anew, and you will have to accept certain inevitable changes.
    Many RGB colours will be changed to rather muddy and messy CMYK colours, as you can see in the Color palette when selecting CMYK.
    And many bright colours will become less so.

  • Converting BLOB to HEX and HEX to BLOB

    Hi!
    I have a table that stores pictures as BLOB. Due to some project rules, I need to be able to convert this image to a CLOB (represented as a HEX String) and, after that, I need to convert this HEX String back to BLOB.
    I already created the function that converts BLOB to HEX. See below:
    CREATE OR REPLACE FUNCTION blob_to_hex (blob_in IN BLOB)
    RETURN CLOB
    AS
        v_clob    CLOB;
        v_varchar VARCHAR2(32767);
        v_start   PLS_INTEGER := 1;
        v_buffer  PLS_INTEGER := 32767;
    BEGIN
        DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
        FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(blob_in) / v_buffer)
        LOOP
           v_varchar := DBMS_LOB.SUBSTR(blob_in, v_buffer, v_start);
           DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_varchar), v_varchar);
           v_start := v_start + v_buffer;
        END LOOP;
       RETURN v_clob;
    END blob_to_hex;But, I´am having some difficulties to convert the HEX CLOB back to BLOB.
    Does anybody know how could I do this?
    Thanks a lot!!!
    Regis

    try this procedure
    first create directory BLOB_DIR
    CREATE OR REPLACE DIRECTORY
    BLOB_DIR AS 'C:\temp';
    CREATE OR REPLACE PROCEDURE BLOB_LOAD(filename varchar2)
    AS
    lBlob BLOB;
    lFile BFILE := BFILENAME('BLOB_DIR', filename);
    BEGIN
    INSERT INTO O_CONTRACT_IMAGES
    (CONTRACT_NO,CONTRACT_Year,CONTRACT_blob)
    VALUES (1,2, empty_blob())
    RETURNING CONTRACT_blob INTO lBlob;
    DBMS_LOB.OPEN(lFile, DBMS_LOB.LOB_READONLY);
    DBMS_LOB.OPEN(lBlob, DBMS_LOB.LOB_READWRITE);
    DBMS_LOB.LOADFROMFILE(DEST_LOB => lBlob,
    SRC_LOB => lFile,
    AMOUNT => DBMS_LOB.GETLENGTH(lFile));
    DBMS_LOB.CLOSE(lFile);
    DBMS_LOB.CLOSE(lBlob);
    COMMIT;
    END;
    Edited by: Hossam Kasem on 20-Apr-2011 05:56

  • Colour grade with Kuler RGB or Hex values

    Is there a grading/colour correction effect in PPRO which allows you to map midtones/shadows/hilights to an RGB or Hex value such as one acquired through Adobe Kuler? If not that easily, how could one use the swatches (RGB values) from Kuler as a palate in grading in PPRO? Thanks :)

    I'm not the person to answer questions about color correction, but I did want to mention that PPro has many color correction capabilities. See
    these free tutorials to see what is possible.
    Cheers
    Eddie
    PremiereProPedia   (
    RSS feed)
    - Over 300 frequently answered questions
    - Over 250 free tutorials
    - Maintained by editors like
    you
    Forum FAQ

Maybe you are looking for

  • Problem with premiere elements 3.0 (titles when creating DVD)

    I am using version 3.0 and when you go to create DVD there should be the option to insert titles or menu page at the start of your DVD, well that has disappeared from my programme.  We had problems with the pc so had to reinstall alot of the programm

  • K7N2G-L restart problem

    Hi If I do a cold start my system will boot up ok,but if I have to do a "restart" after installing something it boots up and the gets to the part where it says "Searching for IDE devices" and it will hang.If I power off and then on again it will boot

  • Error message - Production order

    Hello, I have a problem with Production Order. I have created a Planned Order. While I type a Planned Order number and Order Type, SAP shows an error: "Text ... ID PLPO language not found". Is this a problem of language settings in material or someth

  • RAC setup for R12

    Hi, I read docs about EBS R12.1 RAC setup that said: The traditional and still widely-used configuration where the Concurrent (Parallel) Processing servers are located on the database tier. Unless there is a network constraint, the recommendation now

  • When i tried to upgrade, it deleted flash! please help!

    I tried to download Adobe Flash because a website said I did not have the latest version. The download said it was successful but now I have no Flash at all! I can't see certain websites or even watch Youtube videos. I tried uninstalling Adobe and th