Alpha value to RGB

int rgb;
int alpha
rgb |= ((alpha & 0xFF) << 24);Shouldn't this append the alpha bits correctly into the RGB value? because it doesnt seem to work.

import java.awt.Color;
public class Test {
    public static void main(String[] args) {
        int rgb = new Color(100, 175, 200, 190).getRGB();
        unpack("1", rgb);
        // Clear alpha bits [24 - 31] in rgb.
        rgb <<= 8;
        unpack("2", rgb);
        rgb >>= 8;
        unpack("3", rgb);
        // Reset alpha.
        int alpha = 175;
        rgb |= ((alpha & 0xff) << 24);
        System.out.printf("alpha = %3d  rgb = %11d  retrieve alpha: %3d%n",
                           alpha, rgb, (rgb >> 24) & 0xff);
        unpack("4", rgb);
        rgb = clearAlpha(rgb);
        alpha = 200;
        rgb |= ((alpha & 0xff) << 24);
        System.out.printf("alpha = %3d  rgb = %11d  retrieve alpha: %3d%n",
                           alpha, rgb, (rgb >> 24) & 0xff);
        unpack("5", rgb);
        rgb = clearByte(8, rgb);
        int g = 225;
        rgb |= ((g & 0xff) << 8);
        System.out.printf("g = %3d  rgb = %11d  retrieve g: %3d%n",
                           g, rgb, (rgb >> 8) & 0xff);
        unpack("6", rgb);
    private static int clearAlpha(int n) {
        n <<= 8;
        n >>= 8;
        return n;
    private static int clearByte(int start, int n) {
        if(start + 8 <= 32) {
            for(int j = start; j < start+8; j++) {
                int bit = (n & (1 << j)) >> j;
                if(bit == 1) {
                    int mask = getMask(j);
                    //System.out.printf("mask  = %s%n",
                    //                   Integer.toBinaryString(mask));
                    n &= mask;
                    //System.out.printf("n[%2d] = %s%n",
                    //                   j, Integer.toBinaryString(n));
        return n;
    private static int getMask(int n) {
        int mask = 0;
        for(int j = 0; j < 32; j++)
            mask |= ((1 << j) | 1);
        mask ^= (1 << n);
        return mask;
    private static void unpack(String s, int n) {
        int a = (n >> 24) & 0xff;
        int r = (n >> 16) & 0xff;
        int g = (n >>  8) & 0xff;
        int b = (n >>  0) & 0xff;
        System.out.printf("%s unpack %11d: a = %3d  r = %3d  g = %3d  b = %3d%n",
                           s, n, a, r, g, b);
}

Similar Messages

  • How to change alpha value in pixel

    I am trying to alter the alpha values in a pixel array. I can change the RGB values, but changing the alpha seems to have no effect. Hope you can help. Thanks.
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import com.sun.image.codec.jpeg.*;
    import java.util.Random;
    import java.awt.Toolkit;
    public class alterImage extends Component {
    public FileOutputStream fos = null;
    public File fc = null;
    private static Frame window;
    public void paint (Graphics g){
      Toolkit theKit = window.getToolkit();
      Image img = theKit.getImage("originalImage.jpeg");
      img = img.getScaledInstance(100,100,1);
      MediaTracker mtracker =  new MediaTracker(this);
      mtracker.addImage(img, 0);
      try {
      mtracker.waitForID(0);
      } catch (Exception e) {}
      int w = img.getWidth(this);
      int h = img.getHeight(this);
      int[] pixels = new int[w * h];
      PixelGrabber pixs = new PixelGrabber(img, 0, 0, w, h, pixels, 0, w);
         try {
         pixs.grabPixels();
         if (pixs.getColorModel().hasAlpha())
         System.out.println("hasAlpha");
              } catch (InterruptedException e) {
                System.err.println("interrupted waiting for pixels!");
                return;
    // alter pixel values
    for(int i = 0; i < pixels.length; i++){
         int alpha = (pixels[i] >> 24) & 0xff;
         //System.out.println("alpha " + alpha);
         int red   = (pixels[i] >> 16) & 0xff;
         //System.out.println("red" + red);
         int green = (pixels[i] >>  8) & 0xff;
         //System.out.println("green" + green);
         int blue  = (pixels[i]      ) & 0xff;
         //System.out.println("blue" + blue);
         green /= 2;   // green is effected
         alpha /= 2;   // alpha is not effected
         pixels[i] = (alpha << 24) | (red << 16) | (green << 8) | blue;
    // create new image with altered pixel data
    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    image.setRGB(0, 0, w, h, pixels, 0, w);
    // write new image to file
    try {
    fc = new File("newImage.jpeg");
    fc.createNewFile();
    fos = new FileOutputStream(fc);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
    encoder.encode(image);
    fos.flush();
    fos.close();
    // show image in window
    Image img2 = theKit.getImage("newImage.jpeg");
    g.drawImage(img2, 0, 0, 100, 100, this);
    } catch(IOException e) {}
    // end paint
    public static void main (String arg[]){
         window = new Frame ("Alter Image");
         window.add(new alterImage());
         window.pack();
         window.setSize(100,100);
         window.show();
    // end class
    }

    It only makes sense to apply transparency in respect of another image that this one is to appear 'on top of'; this is done by performing a comparison on the pixel value for each of the two images, altering in favour of the 'on top' image if transparency for that pixel is low, or for the 'underneath' image if transparency for that pixel is high.
    Although tricky (for me at least, perhaps not for you!), using the WritableRaster from BufferedImage's GetWritableRaster() method lets you accomplish this. Look here for more:
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/WritableRaster.html
    Once you have created a composite image of the two source images, that can then be saved as a separate JPG, GIF or whatever. Look here too:
    http://java.sun.com/docs/books/tutorial/2d/display/compositing.html
    Good luck!
    Chris.

  • How to blend texture alpha values (RGBA) with vertex alpha values (COLOR_4)

    Hello,
    I want to draw a transparent texture (a cloude texture that is square and reapeating) with soft edges (the cloud shape is defined through the geometry not the texture). For this I've created a geometry with a alpha value of 0.0f at the edges and 1.0f in the inner vertices.
    But I'm only able to get it rendered with either the vertex alpha (if I I create the texture with RGB format - no alpha) or with only the texture alpha (when I declare the texture with RGBA format). I've tried many combinations of TextureAttributes (BLEND, DECAL, COMBINE with COMBINE_BLEND, COMBINE_ADD, COMBINE_MODULATE, etc..) but I can't figure it out.
    Ciao Matthias Mann

    I've found a transparency tutorial at http://www.j3d.org/tutorials/quick_fix/transparency.html

  • Changing images' alpha value

    hi !
    let's say I got those two images
    Image img1,img2;I assign a different .gif file to both of them, and I paint them
    goes like...
    g.drawImage(img1,10,10,this);
    g.drawimage(img2,10,10,this);easy enough ?
    now what I'd like to do is to draw both image, but have img2
    semi-transparent, so that we could see img1 (drawn right under it)
    is there some kind of way to change an image's alpha value (I assume it's the way I should do it) using java programmation ?

    You can use a BufferedImage and read it using ImageIO. Create the image in TYPE_INT_ARGB format. Then you can actually access each pixel of the image and change its value. See the Java2D Tutorial (there's a Tutorials link on the left sidebar of this page).

  • How to convert YUV(4:2:2) values to RGB values

    What are the methods available to convert YUV values to RGB values?

    Hi,
    You have to run all DB upgrade and data migration scripts available in 5.2 release to make your 4.2 DB compatible with ME 5.2. These scripts should contain all the DB structure and data changes. The scripts should be available in Clients installation. For detailed process check ME 5.2 Upgrade guide that should be available on SMP.
    Regards,
    Konstantin

  • Can Alpha value change between two Keyframes ?

    Hi
    Flash CS5.
    I have a MovieClip Spatter set to Alpha 21% in one keyframe and a few secs later along its layer on the timeline another KF with it set to 1%
    I run movie and it stays at 21% until it gets to the second KF when it suddenly becomes 1%
    I right click between the two KFs and choose Classic Tween, still no difference.
    Undo that and try for a Motion Tween, ok the con to symbols prompt. still no joy.
    Try for Classic Tween again with...
    I see a Blending option so alter that to Alpha for both MCs at the KFs,. no better,
    How do I get the alpha value to change continually and progressivly from 21% to 1% across lets say 3 secs, so that after 1 sec its 14% then after two secs its 7% etc.
    The MC itself is a 5 frame duration, each frame is a KF with whiteSpatter on a transparent base as a .png the size of which gets larger with each KF. So a growing spatter effect.
    I need to fade this over a period of say 3 secs in my scene1 movie. I am successful in moving it at a steady single alpha value 21% across my scene, but I need the alpha to change during the move to become 1%.
    Envirographics

    Hi,
    I have just tried some experiments.
    1) Create a white box for 1st KF, make it an MC, create a second KF  3 secs later, make this one alpha 1% then make 1st KF's MC alpha 100%. Create a classic tween by right clicking between the two, scrub the timeline slider and hey presto fade of alpha :-)
    2) Ditto but this time use one of the white spatter png's instead of the white box, scrub and bingo png fades.
    Now lets look at my MC that I am wishing to fade from 21% to 1%.
    Double click it in the Lib and we see it is 5 frames long, each is a KF and each KF has a different png file allocated to it (drag drop from lib to MC stage). Each png is white pixels in a spatter pattern sitting on a transparent base. Each png is a larger spatter than the last, thats 5 separate png files with unique names created in photoshop. So the spatter gets larger as the MovieClip plays, it plays spatter1.png then  next frame spatter2.png then spatter3.png etc, very quickly in fact and it loops (no stop command), I could have gone 1 2 3 4 5 4 3 2 so the growth developed then shrank but it looks ok for my purposes with 1 2 3 4 5 as its so fast.
    It is one of those png's that was used in experiment 2. It worked there, so alpha applied to png works.
    When we have five of them in the MC that we are fading, or trying to, we have failure.
    ...update...sussed it !
    I had placed the MC in 1st KF, copy pasted it in place and moved it upwards to get two of them sitting parallel, then created the next KF 3 secs later, made the first two in 1st KF 21%, made the last two 1%, classic tweened and got failure.
    Now trying only 1 per Classic Tween and using two layers, one for the lower, the other for the upper, it works.
    Lesson learnt, you cannot have two MC's on one layer if tweening in this way. Its got to be one MC tween per layer.
    Envirographics

  • Can I get Alpha values in openGL that are not premultiplied?

    I'm making a game that uses lots of alpha values. We have alpha values in the texture map then on top of that we use a color with varying alpha values to dynamically fade things in and out. In order to dynamically fade things in and out I need to pass glBlendFunc GLSRCALPHA & GLONE_MINUS_SRCALPHA. But since the alpha values in the texture map are premultiplied they display wrong unless I've passed glBlendFunc GL_ONE & GLONE_MINUS_SRCALPHA.
    How can I disable my texture maps alpha values being premultiplied?
    Thanks

    You need to be in the US and have a payment method valid in the US.
    (63323)

  • Print or export runtime created vector graphics with alpha values intact

    I want to be able to save the dynamically generated state of a swf as a vector image. I know I can right click on the swf and print to a pdf via the Adobe pdf print driver. This works well but all alpha values are lost. Does anyone know how to print to a pdf or any other vector format and retain the alpha values? The pdf format clearly supports it as I can save objects with alpha values from Illustrator as a pdf no problem.
    Any alternative solution that achives this result would be welcome e.g. save runtime swf via actionscript to swf or Illustrator format etc.
    thanks

    Hi All,
    Flash Pro CC 2014 (v14.0.0.110) is now available for download via the Creative Cloud App and Adobe website.
    We have added SVG Export feature to Flash Pro with this new release. You will now be able to export out vector content from the selected frame as an SVG image that can be opened directly in a Browser and even imported in Adobe Illustrator.
    SVG Export option can be accessed via the Publish Settings as well as via File Menu > Export > Export Image option.
    Along with this, we have added several new features with this release. Complete list is available at these links:
    Overview:         https://www.adobe.com/in/products/flash.html
    Whats new:      https://helpx.adobe.com/flash/using/whats-new.html
    Release Notes: https://helpx.adobe.com/flash/release-note/flash-professional-cc-2014.html
    Thanks,
    Nipun

  • Alpha value for image

    the alpha value of all pixels of many images(jpg,gif) is coming out to be same(ie 255).why is it so? does alpha value really represents intensity?

    What colour model are you thinking of? Perhaps you'd find the Color.RGBtoHSB method helpful?

  • Color Matrix Alpha values and drawing images.

    Hi All,
    I am experimenting with using a color matrix to change images and have brightness, R, G, B changing but the alpha does not seem to do anything. I have a scrollbar for the alpha value in the matrix in the example. It seems it should change the image in some
    way but it does not.
    In this example I put 1 for red in the matrix thinking as I moved the scroll bar the alpha transparency would change the image in some way but it does not? It does not matter what colors or image I use nothing seems to happen with alpha? Is it
    only for drawing lines and such or does it do something to images? If so what?
    Imports System.Drawing.Imaging
    Public Class Form3
    Private rustybmp As New Bitmap("c:\bitmaps\rusty.jpg")
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.DoubleBuffered = True
    VScrollBar1.Maximum = 100
    VScrollBar1.Minimum = 0
    VScrollBar1.Value = 50
    End Sub
    Private Sub Form3_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
    {New Single() {1, 0.0, 0.0, 0.0, 0.0}, _
    New Single() {0.0, 1, 0.0, 0.0, 0.0}, _
    New Single() {0.0, 0.0, 1, 0.0, 0.0}, _
    New Single() {0.0, 0.0, 0.0, 1.0, 0.0}, _
    New Single() {1, 0, 0, VScrollBar1.Value / 100, 1}})
    Dim image_attr As New ImageAttributes
    image_attr.SetColorMatrix(cm)
    e.Graphics.DrawImage(rustybmp, Me.ClientRectangle, 0, 0, rustybmp.Width, rustybmp.Height, GraphicsUnit.Pixel, image_attr)
    End Sub
    Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles VScrollBar1.Scroll
    Me.Refresh()
    End Sub
    End Class

    I didn't try this.
    How to: Use a Color Matrix to Set Alpha Values in Images
    La vida loca
    Oh, ok, in your link example the alpha is the 4 row 4 col.
    I was using the 5th row 4th col because I thought that was R, G, B A across the 5th row. Maybe that is for a solid brush or something.
    This works as I expected that way. Still looking....
    Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
    {New Single() {1, 0.0, 0.0, 0.0, 0.0}, _
    New Single() {0.0, 1, 0.0, 0.0, 0.0}, _
    New Single() {0.0, 0.0, 1, 0.0, 0.0}, _
    New Single() {0.0, 0.0, 0.0, VScrollBar1.Value / 100, 0.0}, _
    New Single() {0, 0, 0, 0, 1}})
    Cool!
    Now if you could just get that working with HoloLens..... :)
    La vida loca

  • RGB value VS RGB Percentages?who know?

    Hi everyone, i have a question that what is the algorithm from "RGB value"to "RGB Percentages" ?(e.g.from "RGB=BCBCBC" to "r = 50000 : g = 50000 : b = 50000") I want to kown the conversion algorithm. THANKS!

    duplicate post

  • Adobe Media Encoder CC 2014 not recognising opacity/alpha values from After Effects

    Hello, I'm importing AE compositions directly into Media Encoder to output as 'Match Source - Medium Bitrate H.264' files. However Media Encoder is not recognising the opacity values of the layers in AE and the background images are coming out as opaque rather than partially transparent.
    How can I resolve this? If I render the movie from AE as a .mov then use Media Encoder it works fine, but that takes a lot more time.

    Can you post screenshots of your comp in After Effects and the result you are getting from AME?
    One issue you may be hitting is that AME is not aware of the composition background color. This is a limitation of Dynamic Link; because a primary use case of Dynamic Link is placing an After Effects composition, such as lower-thirds titles, into a Premiere Pro sequence, Dynamic Link ignores the background color of the composition and treats any the background pixels as alpha. In AME, since there is no compositing happening, black is used to fill in the alpha area.
    To work around this limitation, place a solid at the bottom of your composition layer stack that is the color of your background.
    You're welcome to submit this problem as a feature request: http://adobe.ly/feature_request

  • Determining in and out Gamut values for RGB profiles

    Hi all,
    I am looking into how to check if a swatch value falls within my .icc profile gamut.
    If I have a color value for example L=74 a=12 b=-37 and I want to see if it falls within my .icc profile I can select Edit>Convert to Profile and choose my profile
    I then can select the swatch and see if there's a gamut warning there.
    With the above swatch if my color profile is "Photoshop 5 Default CMYK" I will get the warning, if I change the profile to "US Newsprint (SNAP 2007)" I won't get it.
    This works great for CMYK profile.
    My question is how to check if the color falls inside an RGB profile?
    I have tried changing the document intent to Web and Digital Publishing and changing the RGB profile but only changing the CMYK profile affects the out of gamut warning.
    Does any one know of a solution to this? The same issue would appear to be in photoshop.
    Thanks in advance.
    Trevor

    Timo,
    actually he wants to set the attribute mapping dynamic, reading the field to map the return value to from a custom property.
    1D10T,
    If this could be done then in the Def object of a view object (which means its not per user session but use). Investigate into the View Object Def object for the view object that defines the list of value (not the one that you use as the LOV list source)
    Frank

  • Feature request for lightroom "K" value with RGB

    Before lightroom I set my info box to show K - grayscale value along with the RGB reading in Photoshop.  This was the most consistant way to keep density accurate between photographs. Within Lightroom it's a little more tricky to keep the the density as consistant. Can the engineers add a "K" value next to the RGB in the upper Right corner of the develop module of lightroom?

    You can get something even better right now: Lightroom can show Lab values if you right-click on the histogram and check "show Lab values". The L is what you want:
    (The K in Photoshop refers to whatever is set as gray working space - what the value would be if you converted the file to it. The actual readout varies according to what that working space is).

  • Why do the relative values of RGB and CMYK change when switching between Photoshop and InDesign?

    I'm trying to put together a Colour Guide for my company's brand guidelines.
    I initially worked from InDesign and wrote down all the H, RGB, and CMYK values that I got when I eye-dropped my original colour palette.
    However when I put the same RGB values into Photoshop- I am given a (slightly) different set of CMYK numbers from those that I had originally documented in InDesign.
    Why is this???

    Jamie,
    in Photoshop go to Edit > Color Settings and choose your  parameters:
    For RGB: sRGB or AdobeRGB (1998)
    For CMYK: the process as recommended by your printer (person, company)
    For offset printing this is here ISOCoated-v2-eci and elsewhere for instance SWOP.
    For digital printing you should ask the company as well.
    For Grayscale: Gray Gamma 2.2
    For Spot: probably irrelevant in the moment. Dot Gain 20%
    Everything as shown here:
    For your application I've modified my settings a little, therefore we can see top left 'unsynchronized'.
    In InDesign do practically the same, but there are no settings for Grayscale.
    You'll find for any topic explanations if you move to by mouse (position the pointer over ...).
    The field 'Settings' shows not 'Custom' but the file name of a configuration which had been previously saved
    and then loaded (buttons top right).
    Further explanations on request. It would be quite useless to explain everything now at the same time.
    The colors will be wrong if the settings are not synchronized. Above they are explicitly synchronized.
    Because Bridge was not used, the system considers them as 'not synchronized', which doesn't matter.
    Best regards --Gernot Hoffmann

Maybe you are looking for

  • Playing clips continuously

    I just dragged a bunch of clips into my video and when I start at the beginning to play all the clips together, it doesn't work. It plays each clip and then stops? How do Imake them play altogether? I don't want transitions in them. Any help would be

  • Duplicate Check in OEDQ

    Hi All, In OEDQ, when we use Duplicate audit tool, it will filter both actual as well as duplicated record, Is there any way in OEDQ through which we can retain the original record Any help will be really appreciated. Thanks, VT

  • How can Cash security deposit become "real" in billing?

    Hi gurus, I am searching for a solution that let cash security deposit become "real" after billing. I use FI-CA event R401 in which I set field XGUMB_401 =  'X' on FI-CA document relative to cash security deposit. This item is statistic (DFKKOP-STAKZ

  • ERROR EXECUTE DBMS_CRYPTO_TOOLKIT

    Hello, I installed Oracle Crypographic Toolkit. This package has procedures that i need like SignDetached and VerifyDetached. the installation was successful and and no invalid packages I have one certificate intall in oracle Wallet which i need to v

  • I want to Update to Lion from Mountain Lion. How many extra GB's will this require to upgrade?

    Or, like a previous upgrade, will this result in a smaller size?