Fit Image to Screen

I am using this code to make a screen saver that fades an image in then fades to another image. I would like to be able to set those images to full screen in case they are to large or to small for the current screen resolution. Any suggestions?
Thanks
class ScreenSaver {
public static void main(String[] args){
Saver s = new Saver();
s.sleepy();
class Saver extends JWindow implements MouseListener
Image i1;
Image i2;
Image i3;
Image i4;
Image i5;
Vector images = new Vector();
boolean first;
JPanel panel;
private static Thread t;
static float j = 1.0f;
BufferedImage bi;
Image img;
BufferedImage dest;
int i = 0;
int b = 1;
Saver(){
panel = new JPanel();
panel.addMouseListener(this);
getContentPane().add(panel);
setSize(getToolkit().getScreenSize());
ImageIcon ii1 =
new ImageIcon("1.jpg");
ImageIcon ii2 =
new ImageIcon("3.jpg");
ImageIcon ii3 =
new ImageIcon("4.jpg");
ImageIcon ii4 =
new ImageIcon("5.jpg");
ImageIcon ii5 =
new ImageIcon("6.jpg");
i1 = ii1.getImage();
i2 = ii2.getImage();
i3 = ii3.getImage();
i4 = ii4.getImage();
i5 = ii5.getImage();
images.addElement(i1);
images.addElement(i2);
images.addElement(i3);
images.addElement(i4);
images.addElement(i5);
dest = new BufferedImage(1000, 1000, BufferedImage.TYPE_INT_ARGB);
setVisible(true);
public void mouseClicked(MouseEvent e) {System.exit(0);}
public void mouseExited(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
Graphics2D destG = dest.createGraphics();
destG.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, j));
destG.drawImage((Image)images.get(i),0,0,panel);
destG.setComposite(AlphaComposite.getInstance(AlphaComposite.XOR, 1.0f-j));
destG.drawImage((Image)images.get(b),0,0,panel);
g2d.drawImage(dest,0,0,panel);
public void sleepy() {
TimerTask task = new TimerTask() {
public void run() {
j = j - 0.01f;
if(j<0.02f) {
i++;
b++;
j=1.0f;
if(b>4) { b=0; }
if(i>4) { i=0; }
repaint();
Timer timer = new Timer();
timer.schedule(task, 0 , 4);

Basically what the last reply said. You have to add a couple 'getHeight' and 'getWidth' methods too. Also, to create your images, use a "factory method" (see 'createImage').
//code
import javax.swing.*;
import java.util.Vector;
import java.util.TimerTask;
import java.util.Timer;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class Saver extends JWindow implements MouseListener {
     Image i1;
     Image i2;
     Image i3;
     Image i4;
     Image i5;
     Vector images = new Vector();
     boolean first;
     JPanel panel;
     private static Thread t;
     static float j = 1.0f;
     BufferedImage bi;
     Image img;
     BufferedImage dest;
     int i = 0;
     int b = 1;
     Saver() {
          panel = new JPanel();
          panel.addMouseListener(this);
          getContentPane().add(panel);
          setSize(getToolkit().getScreenSize());
          i1 = createImage("1.jpg");
          i2 = createImage("2.jpg");
          i3 = createImage("3.jpg");
          i4 = createImage("4.jpg");
          i5 = createImage("5.jpg");
          images.addElement(i1);
          images.addElement(i2);
          images.addElement(i3);
          images.addElement(i4);
          images.addElement(i5);
          dest = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
          setVisible(true);
     private Image createImage(String name) {
          return new ImageIcon(name).getImage().getScaledInstance(getWidth(), getHeight(), Image.SCALE_DEFAULT);
     public void mouseClicked(MouseEvent e) {System.exit(0);}
     public void mouseExited(MouseEvent e) {}
     public void mouseEntered(MouseEvent e) {}
     public void mouseReleased(MouseEvent e) {}
     public void mousePressed(MouseEvent e) {}
     public void paint(Graphics g) {
          Graphics2D g2d = (Graphics2D)g;
          Graphics2D destG = dest.createGraphics();
          destG.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, j));
          destG.drawImage((Image)images.get(i),0,0,panel);
          destG.setComposite(AlphaComposite.getInstance(AlphaComposite.XOR, 1.0f-j));
          destG.drawImage((Image)images.get(b),0,0,panel);
          g2d.drawImage(dest,0,0,panel);
     public void sleepy() {
          TimerTask task = new TimerTask() {
               public void run() {
                    j = j - 0.01f;
                    if(j<0.02f) {
                         i++;
                         b++;
                         j=1.0f;
                         if(b>4) { b=0; }
                         if(i>4) { i=0; }
                    repaint();
          Timer timer = new Timer();
          timer.schedule(task, 0 , 4);
     public static void main(String[] args){
          Saver s = new Saver();
          s.sleepy();
}

Similar Messages

  • PSE 9; Fitting image to screen, does not fit image to screen

    Hi,
    I have some problems since last upgrade of Photoshop Elements 9.
    Suddenly, when I am using the editor, when I want to resize the image to fit the screen, it does not do that anymore.
    The image does change size, but it is considerably smaller than the screen, (or rather the available area in the editor workspace).
    For example, with an image in portrait mode, Fit to screen makes it as 11%, with considerable space above and under the image.
    If I zoom this image manually, entering a number 16% fits the screen.
    This used to work before.
    How can I make it work?
    I am sure there is some settiing, but I cannot find it.
    And, it seems, that it ceased to work after the last upgrade, a couple of weeks ago. It is now PSE 9.0.3.
    Of cause, it might have been something I did that made it cease working.
    I don't care. But where is the setting that makes this work?
    /Anna

      Try dragging out the tab containing the image; so that it floats.
    Then drag the triangle corner at the bottom right - you can cover a big part of the screen real estate whilst still keeping the tools pallet and menu bar visible.
    You can also click Edit à Preference à General
    Then check the item Zoom With Scroll Wheel
    That will let you fill or reduce the window contents quite quickly.
     

  • New iOS7 Photos app will not fit images to screen?

    Since upgrading to the latest ios7, what used to be a rather pleasant and relaxing experience, now is rather tedious and has actually forced me to put down my iPad.  I download a lot of graphic novels and before iOS7, I could read a whole page without having to tap the screen, etc.  Now, the pages are off the screen, so having to resize the image is an added step.  Why?!?!?!?  If it was a 1-10 pages, I think there wouldn't be a problem, but these files have 210 pages in average.  Any suggestions out there?...  I'm not looking to use any of these files as background or wallpapers, which most people have been complaining about.

    I have important photos on iPhoto and will only transfer photos from 2012 to Photos. Can you help me?
    How are you migrating from iPhoto to Photos?  And what exactly happens?
    When you first launch Photos, it will automatically open the default iPhoto Library in your Pictures folder.  If your main iPhoto Library is somewhere else, drag it to the Photos icon in the Dock to migrate that library to Photos.
    Where is your main iPhoto Library? Is it on an external drive - if yes, how is this drive connected?

  • Why does images in preview are in a different position and resolution than in design view? In design view I have to place the images of screen to fit in preview.

    Why does images in preview are in a different position and resolution than in design view? In design view I have to place the images of screen to fit in preview.

    Already changed in different settings. Here is a screenshot when set to "Original Size".

  • How to fit image to the screen of an Android device?

    Required to load the image from the gallery (CameraRoll) and fit to the screen entirely.
    Tried a lot of ways - completely unable to fit. Always cut off the edge of the image.

    You won't be able to write LabVIEW code that runs on the phone to return the data. What you would need to do is look to see if there is an Android App that can publish the data of the phone's internal sensors over TCP/UDP/bluetooth(?) and you can then write your LabVIEW VI to read that data using an appropriate method (e.g. TCP).
    I don't know of such an App - maybe you would have to write one which will be non-trivial. I tried a quick search of "sensor data tcp" and "sensor data" and there are some data loggers etc. for the phone sensors so maybe one of those will point you in the right direction.
    There is a little bit of information here http://stackoverflow.com/questions/18107148/real-time-wireless-sensor-data-transfer-wifi-or-bluetoot... and here http://onlinepresent.org/proceedings/vol4_2012/50.pdf
    Certified LabVIEW Architect, Certified TestStand Developer
    NI Days (and A&DF): 2010, 2011, 2013, 2014
    NI Week: 2012, 2014
    Knowledgeable in all things Giant Tetris and WebSockets

  • How to make pages fit to any screen size

    Is there a way to make the pages stretch or condense so that it fits any size screen? I've found where I can adjust the px size of the individual pages but I get white borders at the left/right and bottom edges of the screen that vary depending on the monitor size that I am viewing the page on. Is there a fix for this? Thanks.

    Welcome to the Apple Discussions. By screen size do you mean browser window size? If so you can get rid of the white around the body of the page by using a solid color or tiled image for the browser background which is set in the Inspector/Page/Layout pane.
    Or, if you want the page background to be the same as the browser background do the following;
    1 - set the browser background to what you have the page set to.
    2 - set the page content background to transparent.
    Now the page background will fill the browser's window no matter what size it is. That's how I have my tutorial site setup: http://toadstutorials.info.
    Click to view full size
    OT

  • How to make keynote images full screen?

    Question:  how to make keynote images full screen?  I just noticed. after many successful full screen shows with Keynote 09  5.1.1 that I am no longer seeing the show full screen, at 1280, but only using the center part of my macbook pro 13 inch screen (which will mirror just like that on the projection screen, as far as I know).  Did I hit a setting I do not know about to keep the images so small?
      Thanks

    Keynote  >  Preferences  >  Slideshow:    Scale slides to fit display

  • Photoshop elements 11 toolbar does not fit on my screen

    I'm trying to use Photoshop elements 11 on my notebook computer, but the toolbar is too big to fit on the screen, and some of the icons are not accessible.  Is there any way to reduce the size or shape of the toolbar, or to scroll to the icons I can't see using the keyboard so I can still access them.  My computer is already set to the highest screen resolution.  Thanks for your help.

    I'm having the same problem, but on a laptop. PSE11 has been really badly laid out by the designers: I suspect they've been designing on their own large screens where there is plenty of screen area and completely forgotten the "portable" side of the market. IMO the toolbar on the left, dialogue box at the bottom and menu bars take up far too much real estate. I have a 15.6" widescreen laptop and the window for the image is unacceptably small. The "Quick/ Guided/ Expert" bar is ridulously large, and annoyingly mostly unpopulated which renders it pretty pointless!
    So as much as I want PSE11, I won't be buying it. Sorry Adobe, but dumbing down this software and poor screen layout has lost you a sale (and PS is too expensive, so I won't be buying that either). I liked PSE10. I downloaded a copy a week before PSE11 came out. Unfortunately I missed out on being able to buy PSE10 as it was too late by the time I decided to buy it.
    Oh well, let's see what happens with PSE12- that's out in about a year's time isn't it?

  • How the DVD image on screen varies in size .....

    So I have my project on DVD and am pleased, in fact amazed at how good the quality is but there's one little frustrating niggle!
    In order to keep text on some of my graphic images on screen, in the timeline I've had to reduce the size of the overall image. Once converted to DVD, there will be a black border around the image on a Sony TV. Play it on a different TV (LG perhaps) and that gap is filled so it fits very smartly on the 16:9 screen. In fact the text is very close to the edge. And if I stuck strictly to the title safe boundaries, on the Sony TV the black border would be even wider. Gosh I hope this is making sense!
    Video footage is of course fine because no-one is gonna notice what's missing around the perimeters, unless of course some text appears there too but it would never go all the way to the edge.
    Ideally it would be perfect if the graphic designers designed the image so the text wasn't so close to the edge of the graphic but there's nothing I can do about that now.
    So a whole lot of these DVDs are going out to various places here and there and on various screens and in many cases the screen will be filled but in some cases it won't and will look a bit average.
    By the way the screens are on the same settings, 16:9, Full screen.
    Is there a simple solution to this? Thanks for stayin' with me.
    Peter

    Ideally it would be perfect if the graphic designers designed the image so the text wasn't so close to the edge of the graphic but there's nothing I can do about that now.
    Inform your designers that Photoshop includes templates that conform to TV & Video specifications.
    They even have the Action and Title Safe guides switched on by default.
    Look in the File > New menu bar item then click the Preset button to find the templates.
    For stuff like titles and logos that need to be composited, they should deliver .TIFF files with a transparent background.

  • Need background to fit on all screen sizes

    Hi
    I have got one of websites live digital-colours.co.uk but the background looks different on different screen sizes, I am just looking to see if any of you have an idea how I can make it fit on all screens.
    Thanks
    Faye

    Hi Faye,
    you could have a look here: http://johnpatrickgiven.com/jquery/background-resize/ (You have to wait a little bit until the image is completely built.) On the other hand you should have a view to your site in a global way with critical eyes with "Google labs - Browser Size":
    http://browsersize.googlelabs.com/
    Hans-Guenter

  • Window does not fit on my screen, see screen shot.

    In Photoshop CC when I open up a file I am unable grab the bottom of the window and adjust it, so when I make the image fit on the screen the bottom part of the image is cropped.  How do I resolve this?  See screen shot below.

    Hi,
    If you click on the Green Maximize button, does that work?

  • Converting from widescreen to fit whole itouch screen

    hey does anyone know if its possible to convert from a widescreen format movie to a
    viewing capability that fits the entire ipod touch screen. if you do can u post the links of free and not free software? Note: i already have the movie in mp4 format

    While you are playing a video tap the screen.
    You will see the following tools pop up:
    http://www.coolest-gadgets.com/wp-content/uploads/touch-playing-video.jpg
    Click on the button with the two arrows on the upper right and the image should zoom in to fit the whole screen.

  • My picture is not fitting on the screen

    When I use the hdmi input on my pavilion 27xi the picture does not fit on the screen. I have tried other devices and different hdmi cables to check that none of them were faulty but they werent. On the monitors image control settings there is fill to screen or fill to aspect ratio which cant be sellected. Is there any soloution??

    stevblair97
    Welcome to the HP Community Forum.
    There is a solution in Windows and Linux; there may be a solution in OSX if you can get to the graphics controller on your Operating System and adjust the Aspect Ratio within the graphics controller software.
    For example, NVidia and Intel provides software within Windows and / or Linux that allows one to adjust the monitor Aspect Ratio for primary and secondary monitors.
    For Example:
    In Windows, assuming one is running an Intel Driver, one need only Right-Click on the Desktop to gain access to the Intel Graphics Properties.  While obviously different in OSX; it should be reliatively as easy to find the Graphics software, assuming you have access to it at all.
    I am sorry I do not speak Mac else I could be of more direct help in the matter.
    I hope this helps in some way.
    Click the Kudos Thumbs-Up to show you appreciate the help.
    I am pleased to provide assistance on behalf of HP. I do not work for HP. 
    Click Accept as Solution when the Answer provides a Fix or Workaround!
    Kind Regards,
    Dragon-Fur

  • A script to increase the minimum canvas size? (Like Fit Image, but with just my canvas)

    For starters to be clear, I'm looking to manipulate canvas size. Not image size.
    I want to create a script to automatically increase the width and height of my canvas in Photoshop to a specific size when necessary. I only want this to happen if my canvas is less than that specified size. For example: Let's say my canvas size is 300x250. I want the canvas to be at LEAST 600x600. If I run my action it will increase the canvas size to 600x600 for me. If I run this same script on an image where the canvas size is already 700x700, it won't do anything at all to it because both the width and height are equal to or greater than my target size.
    It would also need to work with the height and width on an individual basis. If my image is 400x800, the action would increase my width from 400 to 600, but it would leave the height of 800 alone. So the final canvas size will end up being 600x800.
    It's kind of like the "Fit Image" option in Photoshop, but I only want to manipulate my canvas size, NOT my image size.

    It is possible.
    But if you hope that the dialog remembers the last settings that would require storing those values (which could be done with a txt-file at some pre-defined location), but it would make the Script a bit more complicated.
    // resize canvas in either direction if it is below a defined minimum;
    // 2011; use it at your own risk;
    #target photoshop
    if (app.documents.length > 0) {
    // dialog;
    var dlg = new Window("dialog", "increase width and height if under", [500,300,750,380]);
    // filter for checking if entry is numeric, thanks to xbytor;
    numberKeystrokeFilter = function() {
              if (this.text.match(/[^\-\.\d]/)) {
                        this.text = this.text.replace(/[^\d]/g, "")
              if (Number(this.text <= 0)) {this.text = 5};
              this.text = Math.round(Number(this.text));
    // fields for entry;
    dlg.hor = dlg.add("edittext", [14,15,88,35], "600", {multiline:false});
    dlg.hor.onChange = numberKeystrokeFilter;
    dlg.horText = dlg.add("statictext", [93,15,118,35], "px", {multiline:false});
    dlg.ver = dlg.add("edittext", [129,15,210,35], "600", {multiline:false});
    dlg.ver.onChange = numberKeystrokeFilter;
    dlg.verText = dlg.add("statictext", [215,15,240,35], "px", {multiline:false});
    dlg.hor.active = true;
    // ok- and cancel-button;
    dlg.buildBtn = dlg.add("button", [13,45,118,68], "OK", {name:"ok"});
    dlg.cancelBtn = dlg.add("button", [128,45,240,68], "Cancel", {name:"cancel"});
    // show dialog;
    dlg.center();
    // show dialog;
    var myReturn = dlg.show ();
    // proceed if ok-ed;
    if (myReturn == 1) {
    var myDocument = app.activeDocument;
    // set to pixels;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    // set the minimum values;
    var minWidth = Number(dlg.hor.text);
    var minHeight = Number(dlg.ver.text);
    // get current ones;
    var theWidth = myDocument.width;
    var theHeight = myDocument.height;
    // resize canvas;
    myDocument.resizeCanvas(Math.max(minWidth, theWidth), Math.max(minHeight, theHeight), AnchorPosition.MIDDLECENTER);
    // reset;
    app.preferences.rulerUnits = originalRulerUnits;

  • How can I get my desktop to fit in my screen?, How can I get my desktop to fit in my screen?

    My windows and desktop (everything I see) is too big to fit in the screen.  I have to touch my mouse arrow to one side to see an entire window or to access my desktop.  I can't figure how to make it all back to normal size.  Any suggestions? 

    Turn off Zoom from the Universal Access and Keyboard & Mouse panes of System Preferences.
    (73801)

Maybe you are looking for

  • I want to buy an Iphone 5s in the UK to use in Panama, any idea how to check which model I am buyin online? HELP!!!

    Hi, I want to buy an Iphone 5s from the uk apple store online and I will be using it in Panama. I have contacted my carrier (Movistar Panama) and they have given me a list of the Iphone 5s models that will work with their network: Model A1533 (GSM)*:

  • Adapter Engine Error

    Hi,   i am working on MQ-XI-BW Scenario.i have configured JMS Adapter in Plain J2SE Adapter Engine.But the status is red with a message "javax.jms.JMSException: MQJMS2005: failed to create MQQueueManager for 'BWXI:TEST.QMGR'      at com.ibm.mq.jms.se

  • Sound out on 5 hd channels

    charter hd box , second box, sound out or get one word then out and one word out etc , only on 5 hd channels. tried optical and coaxle does the same on both. sound does work played through tv on hdmi.  is it charter or my denon reciever  causing the

  • IMovie - Poor Video Quality when exporting to "Projects"

    Hi - I'm using iMovie 11' and once I move my video (HD) from "Events" to "Projects" my video quality becomes very poor and the video is cropped. I have changed my setting to have it "fit frame" but the problem still exists. Thoughts?

  • Applescript "Finder" scripts in Mountain Lion?

    So... back in the old days (Leopard, maybe?) there was a category of "Finder" scripts that included things like "Add to item name" and "Replace text in item name"... But those seem to be gone in Mountain Lion. I've seen a comment that suggested findi