×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    1

    how to get the RGBvalues of an image

    hi,
    I'm doing some ImageProcessing in j2me.
    In that i want to change the original image to Negative image .For doing that i want to get the RGb values from the original image.
    how to get the rgb values and also is it possible to use the method that's used in sun Emulator i.e.,
    javax.microedition.lcdui.* in that getRGB method is there to get the RGB values
    please help me with ex code(if possible)
    thanx a lot in advance

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    In MIDP 2.0 you have Image.getRGB(), Image.createRGBImage() and Graphics.drawRGB().

    In MIDP 1.0 there are no methods for accessing the pixel data, but many phones have proprietary APIs, like the DirectGraphics class for Nokia phones.

    shmoove

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    4
    hi friend,
    can u tell me how to draw an image using DirectGraphics in nokia mobile.
    i tried to draw an image in canvas using methods that i've used in sun emulator it's not working
    please help me
    thanx a lot

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    DirectGraphics is a Nokia only class (well, the newer Sony Ericssons also support it). It won't work on Sun's emulator, you need a Nokia emulator to use it.

    shmoove

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    4
    hi,
    i understadn how to draw images using Directgraphics.
    now i want to get the rgb values and subtract that value from 255,
    I use the getPixels() method to get the pixel values n the format the device supporting is ushort_444_rgb or ushort_4444_ARGB.
    if i conver t the values to int and and subtract it frm 255 the image redrawn using that pixels is nothing but a black rectangle but i want to repordouce the image as a -ve image.can anyone tell me how to do this using getPixels() method
    thanx a lot

  6. #6
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    You have to separate the channels using bit manipulation, and in 4444 format you subtract each channel from 15 instead of 255:
    Code:
    short somePixel; // let's assume this is one of the values you got from getPixels()
    
    // first we extract the channels
    short alphaChannel = (somePixel & 0xf000) >> 12;
    short redChannel = (somePixel & 0x0f00) >> 8;
    short greenChannel = (somePixel & 0x00f0) >> 4;
    short blueChannel = (somePixel & 0x000f);
    
    // now you do your manipulations on each channel
    
    // and then you recreate the pixel with the manipulated channels
    somePixel = (alphaChannel << 12) & (redChannel << 8) & (greenChannel << 4) & blueChannel;
    shmoove

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    4
    hi
    i tried to get the -ve image using ur code error occurred 4 me the error is

    C:\WTK22\apps\NokiaTest\src\NokiaImage.java:97: possible loss of precision
    found : int
    required: short
    alpha = 15-(rgb[i] & 0xf000) >> 12;
    for every line whereever i use the shift operation. here is my code:

    short rgb[]=new short[dukeImg.getWidth()*dukeImg.getHeight()];
    dg.getPixels(rgb,0,dukeImg.getWidth(),0,0,dukeImg.getWidth(),dukeImg.getHeight(),DirectGraphics.TYPE_USHORT_4444_ARGB);
    short alpha,red,green,blue;
    short newrgb1[]=new short[rgb.length];
    for(int i=0;i<rgb.length;i++)
    {
    alpha = 15-(rgb[i] & 0xf000) >> 12;
    red = 15-(rgb[i] & 0x0f00) >> 8;
    green = 15-(rgb[i] & 0x00f0) >> 4;
    blue =15- (rgb[i] & 0x000f);
    newrgb1[i] = (alpha<<12) & (red << 8) & (green << 4) & blue;
    }
    dg.drawPixels(newrgb1,true,0,dukeImg.getWidth(),20,0,dukeImg.getWidth(),dukeImg.getHeight(),0,444);
    is there anything wrong r anything i missed to declare can u tell me where i'm missing
    thanx a lot

  8. #8
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Literal numbers (like "15") are int by default. You can cast them to short, or cast the shorts to int so that everything is of the same type.

    And you probably want to leave the alpha channel as it is or you'll convert opaque pixels into transparent ones.

    shmoove

  9. #9
    Registered User
    Join Date
    Jul 2005
    Posts
    4
    hi,
    i tried with codings and idea but the error occurs. here i give u my procedure can u tell me what's wrong in that.igot the -ve image for only a small portion and all others r black
    1.get pixels values using getPixels() method n stored in a short array.
    2.then typecast that to int array.
    3.frm that int array i separate the red ,green and blue in a way IIIr to that i did using the sun emulator i.e.,
    red=0xff-(rgb[i] >>16) & 0xff; IIIr for green and blue
    4.reconstruct the rgb values to an int array.
    5.then again typecast the int to short array.
    6.Draw the image using drawPixels() method.
    The i obtain is not the exact -ve image only a small portion turned to -ve all others r black
    can u give me a suggestion
    thanx a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×