Results 1 to 4 of 4
  1. #1
    audinue is offline Member
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Question Making an Image transparent?

    Hi, this is my first post!
    Java Code:
    class JustSayHello {
      public static void main(String[] args) {
        System.out.println("Hello world!");
      }
    }
    :)

    I have a little problem here by drawing Image on a Graphics.

    I just noticed that the new Image created by java.awt.Component.createImage(width, height) is not transparent.

    How to make it transparent anyway?

    I have a plan to do something like this:
    1. Create back-buffer (Image) backBuffer1. Draw something with expensive calculation here using thread.
    2. Create back-buffer backBuffer2. Draw something here.
    3. Create back-buffer backBuffeX and then draw something here.
    4. Combine by invoking:
    Java Code:
    Graphics g;
    g.drawImage(backBuffer1, 0, 0, null);
    g.drawImage(backBuffer2, 0, 0, null);
    g.drawImage(backBufferX, 0, 0, null);
    But the result is backBufferX overwriting all previous backBuffer. :confused:

    Anyone please?

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Lightbulb Alpha channel....

    Java Code:
    //
    Graphics2D gaphos = (Graphics2D) createGraphics();
    Color aColor = new Color( (float) 0.68169f, (float) 0.68169f, (float) 0.68169f, (float) 0.68169f)
    gaphos.setColor(aColor);
    gaphos.setFont(new java.awt.Font("Arial", Font.BOLD, 128 ) );
    gaphos.drawString ( aString, 100, 220 );
    gaphos.dispose();
    ImageIO.write( ....  , "JPEG",new java.io.File("NiftyImage.jpeg"));
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    audinue is offline Member
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Default

    0.68169f what is this magic number?

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Cool alpha channel -

    That's just some float value I came up with, I was doing a splash scree to write a ROT-13 of a failed pasword across a screen caputure using a an alpha-blended text write of the pw attempted across the screen at the time of the attempt.

    Not much as passwords go, but really handy for saying " we don't play games" to casual curiosity seekers.

    Had a pleasing appearance, after some font twiddling.

    The value there is ... is ... the alpha channel, you get an alpha-blending with whatever the target of the write is.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. Java SWT Transparent Buttons
    By ynnorj in forum AWT / Swing
    Replies: 7
    Last Post: 11-25-2009, 05:48 AM
  2. SWT Transparent button
    By ynnorj in forum SWT / JFace
    Replies: 2
    Last Post: 03-04-2009, 06:33 AM
  3. Text effect: rotation and transparent
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 08:49 PM
  4. Replies: 1
    Last Post: 07-17-2007, 04:10 AM
  5. Transparent JTextPane
    By Ada in forum AWT / Swing
    Replies: 1
    Last Post: 05-31-2007, 09:50 PM

Posting Permissions

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