Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Screen Blur

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Screen Blur

    I am working on a Java Applet.

    I have been trying to find a way to slightly blur the screen when an invalid action is preformed by the user.

    My idea is this: redrawing the current background image slightly skewing where the image gets drawn by a few pixels and adjusting alpha as necessary.

    example:

    public void paint(Graphics gfx){
         gfx.drawImage(buffer, xShake, yShake, this);
    }
     
    public void shake() {
    		fade.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    	    fade.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    //adjust xShake and yShake somewhere in here (maybe)
    		alpha += 0.10f;
    		if (alpha >= 1.0f) {
    			alpha = 0.0f;
    		}
    		else{
    			repaint();
    		}
    	}

    My question is now, how would you guys go about making the screen blur, the above attempt failed. If there is an existing java class that handles this, that would be great.

    The above is just my current idea on how I might be able to do it, I don't know why it isn't working.

    When I adjust xShake and yShake in the method, I have final image back in it's original position by the end of the method. When that's the case, no change happens on the applet. Otherwise, if I have xShake and yShake end at a spot other than the original, a mere fade occurs...

    Any help is always appreciated, thank you!


  2. #2
    Junior Member
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Screen Blur

    Update:

    In my paint method I've tried to implement a time delay like so:

    if(shakeActive == true){
    	delay = System.currentTimeMillis();
    	while(System.currentTimeMillis() < delay + 1000){
    		if(delay == System.currentTimeMillis()){
                            delay += 1000;
    			gfx.drawImage(imageToShake, xShake, yShake, this);
    		}
    	}
    }

    I haven't had any luck yet, but I'm still working at it.


    =============================================

    BAM PROBLEM SOLVED!!!! WOOT!
    Last edited by Ludicrous; April 1st, 2012 at 09:52 AM.

  3. #3
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,235
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Screen Blur

    In my paint method I've tried to implement a time delay like so:
    Do not invoke time delays from within paint. Swing is single threaded, and you will tie up that thread. Instead, you can blur an image using standard Image manipulations. See Java Image Processing - Blurring for Beginners I do not know exactly what your blur entails - if its just an image then you can blur. If its the whole GUI then you can paint the UI to an Image Graphics, blur the image, and overlay this using something like the Glass pane.

Similar Threads

  1. Replies: 9
    Last Post: December 31st, 2011, 12:22 AM
  2. Changing from a screen to another!
    By gargamel7 in forum Java Theory & Questions
    Replies: 23
    Last Post: October 10th, 2011, 06:27 AM
  3. Screen Resolution
    By bartonn in forum Member Introductions
    Replies: 2
    Last Post: December 16th, 2010, 05:49 AM
  4. Blur Image
    By psrkiran in forum Algorithms & Recursion
    Replies: 10
    Last Post: December 31st, 2009, 06:57 AM
  5. clear screen.
    By chronoz13 in forum Java Theory & Questions
    Replies: 10
    Last Post: December 5th, 2009, 06:27 AM