We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › moving desktop
Page Index Toggle Pages: 1
moving desktop (Read 1635 times)
moving desktop
Mar 11th, 2009, 10:37pm
 
hi!

i'm working on a sketch, which let's you move or skew your desktop, to get you extended space for an app launcher, etc.

after days of searching how this might be working,(i'm new to processing/java..)
i now have a sketch that captures your desktop and moves it aside. awesome....but i think i'm on the wrong way. maybe you guys can help me answering these questions:

- is P2D the right renderer for transforming images?
with P3D the framerate gets only around 20...
opengl doesn't work with the frame....i don't know why..

- every time i start the sketch, the window get's white for half a second or so. the same things happens when i click the window to change the location of the frame. is there a way to get rid of this?

- can i change the focus of the window, so that the last window or program will be framed, if i click or start my sketch?

- in processing the sketch works fine, but if i export the sketch as windows file it doesn't. everytime i execute the exe, nothing happens. maybe someone knows the error....
i'm on a vista 64bit

here's the code:


import javax.imageio.ImageIO;
import java.awt.*;
import processing.opengl.*;

PImage img;
int blueTint = 0;
int imgY = 0;
int frameX = screen.width-10;
int frameY = 0;
int frameGo = 0;

float a = 0.0;
float inc = TWO_PI/25.0;

float n = 1;
float imgX = 0;
captureDesktop desk;

void setup(){
 frame.setLocation(frameX,frameY);
 size(screen.width,screen.height, P2D);
 background(254, 63, 82);
 frame.setAlwaysOnTop(true);
 frameRate(50);
 desk = new captureDesktop();
}

void draw(){
 if(frameGo==1){
   //blueTint = int(sin(a)*50.0);
   //a = a + inc;
   //tint(255, 200+blueTint,200-blueTint);
   background(222, 33, 22);
   if(imgX>-60){
     imgX = imgX - 5;
   }
   image(img, int(imgX), imgY);
 }
}

void mousePressed(){
   desk.main();
   frame.setLocation(0,0);
   frameGo=1;
}

public void init(){
 frame.removeNotify();
 frame.setUndecorated(true);
 frame.addNotify();
 super.init();
}


class captureDesktop{
 void main(){
   try{
     Robot robot = new Robot();
     BufferedImage bufferedImage = robot.createScreenCapture(new Rectangle(new Dimension(screen.width,screen.height)));
     File imageFile = new File("image.jpg");
     ImageIO.write(bufferedImage, "jpg", imageFile);
     img = loadImage("image.jpg");
   }
   catch (AWTException e) {
     e.printStackTrace();
   }
   catch (IOException IOerror){
     System.out.println("Whoops!!");
   }
 }
}




Re: moving desktop
Reply #1 - Mar 12th, 2009, 4:52pm
 
Huux wrote on Mar 11th, 2009, 10:37pm:
- is P2D the right renderer for transforming images
with P3D the framerate gets only around 20...
opengl doesn't work with the frame....i don't know why..
Unless you want to do fancy 3D transitions, I don't see the interest of using P3D, or even OpenGL (although the later might be hardware-acccelerated). Java2D can work fine too.

Quote:
- every time i start the sketch, the window get's white for half a second or so. the same things happens when i click the window to change the location of the frame. is there a way to get rid of this
You write a Jpeg on disk after capture then load it. It seems unnecessary and might add quite a lag, with you have a large screen... You can make a PImage out of a BufferedImage directly (there is a constructor for that).
Re: moving desktop
Reply #2 - Mar 13th, 2009, 12:50pm
 
thanks for the reply!

it would be great to change the color of the whole screen, and other stuff. if you mean that by fancy transitions than, yes. also, later i want beeing able to load and animate buttons on the right....but that's not the thing at the moment.

i now have switched to a texture thats placed on the screen. i think thats a better way transforming the image(skewing/translating). but it is still very slow. how can i get the image to be drawn faster?

and i have tried to make a pimage out of the bi, but it didn't work ( PImage img = new PImage(bufferedImage); )
it didn't show up.

also, i've solved the problem with the export. java somehow uses a main() function, so it caused problems when i named a function main(), so i renamed it to mainly().

but the most annoying problem is the flash of the backgroundcolor everytime i start the sketch or do a resize of the image.

might there be another way besides positioning the full monitor-resolution-sized window outside the visible desktop, and then repositioning it by some kind of action???


--------------
import javax.imageio.ImageIO;
import java.awt.*;

PImage img;
int imgY = 0;
int frameX = screen.width-10;
int frameY = 0;
int frameGo = 0;

captureDesktop desk;

void setup(){
 frame.setLocation(frameX,frameY);
 size(screen.width,screen.height/2, P3D);
 background(254, 63, 82);
 frame.setAlwaysOnTop(true);
 desk = new captureDesktop();
}
void draw(){
 if(mouseX >0 && frameGo!=1){
   desk.mainly();
   frame.setLocation(0,0);
   frameGo=1;
 }
 if(frameGo==1){
   background(14,166,255);
   beginShape();
   texture(img);
   vertex(0, 0, 0, 0);
   vertex(mouseX, 0, screen.width, 0);
   vertex(mouseX, screen.height/2, screen.width, screen.height);
   vertex(0, screen.height/2, 0, screen.height);
   endShape(CLOSE);
   
   println(mouseX+"  "+frameRate);
 }
}
public void init(){
 frame.removeNotify();
 frame.setUndecorated(true);
 frame.addNotify();
 super.init();
}
class captureDesktop{
 void mainly(){
   try{
     Robot robot = new Robot();
     BufferedImage bufferedImage = robot.createScreenCapture(new Rectangle(new Dimension(screen.width,screen.height/2)));
     File imageFile = new File("image.jpg");
     ImageIO.write(bufferedImage, "jpg", imageFile);
     img = loadImage("image.jpg");
   }
   catch (AWTException e) {
     e.printStackTrace();
   }
   catch (IOException IOerror){
     System.out.println("Whoops!!");
   }
 }
}
Re: moving desktop
Reply #3 - Mar 13th, 2009, 2:20pm
 
Huux wrote on Mar 13th, 2009, 12:50pm:
i have tried to make a pimage out of the bi, but it didn't work ( PImage img = new PImage(bufferedImage); )
it didn't show up.

Tried simple sketch:

size(300, 300);
try
{
Robot robot = new Robot();
BufferedImage bufferedImage = robot.createScreenCapture(
new Rectangle(new Dimension(screen.width, screen.height/2)));
PImage p = new PImage(bufferedImage);
image(p, 10, 10, 250, 250);
}
catch (AWTException e) {
e.printStackTrace();  
}

It works...
Re: moving desktop
Reply #4 - Mar 13th, 2009, 3:27pm
 
i replaced the code with yours, and it works, thanks!!!
but still slow, maybe i have to try opengl
Re: moving desktop
Reply #5 - Mar 16th, 2009, 1:56am
 
I have made some additions to your code and it is working quite nicely with Peasy cam.

I tried it with OPENGL but the framerate in Processing is slow but when transferred to video in realtime the resulting video is acceptable.

OPENGL does not warp the video when it is rotated using P3D but the framerate is slower than with P3D. With P3D the framerate is spot on.

I am running Windows 7 Beta and the effect is REALLY nice!

Also you can create a procedure to create a unique filename for the video, otherwise rename the video before running the sketch.

The rotational factor is good for having a LCD monitor flat on the table/desk or directly above your head parellel to your body. There is a lot of potential with processing.

NB. Turn on Mouse Trailing in Windows otherwise the mouse pointer will be hidden.

From here the image can be converted to pixels, wrapped as a texture around a sphere, pretty whatever you want to do with the image. I am going to try it with PATCHY's bezier texture as a realtime image on the floating cloth. I am able to do it with a video so with this a PIMAGE it should not be a problem.

I love PROCESSING!

Here is the code,

----------

import processing.opengl.*;
import processing.video.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;

public MovieMaker mm;
PeasyCam cam;
public PImage p;
public Robot robot;
void setup(){
frameRate(60);
cam = new PeasyCam(this,1000);
cam.pan(100,250);
//size(screen.width, screen.height,OPENGL);  //There is no warping with OPENGL but the framerate is not hight
size(screen.width, screen.height,P3D); //The frameRate is high with P3D but there is warping when the screen is rotated
try
{
//Robot robot = new Robot();  //Robot as public object but not mandatory
robot = new Robot();
BufferedImage bufferedImage = robot.createScreenCapture(
new Rectangle(new Dimension(screen.width, screen.height)));
//PImage p = new PImage(bufferedImage);  //using as public variable for ease of use but not mandatory
p = new PImage(bufferedImage);
image(p, 0, 0, screen.width, screen.height);
mm = new MovieMaker(this, width, height, "drawing.mov", 15, MovieMaker.ANIMATION, MovieMaker.HIGH);
}
catch (AWTException e) {
e.printStackTrace();  
}  
}
void draw() {
BufferedImage bufferedImage = robot.createScreenCapture(
new Rectangle(new Dimension(screen.width, screen.height)));
p = new PImage(bufferedImage);
//background(p); // alternative to image but there is no difference in framerate
background(120);
image(p, 0, 0, screen.width, screen.height);
rect(mouseX,mouseY,10,10); // to indicate where the mouse is
mm.addFrame();
}

void keyPressed(){
 if (key==' ') {
 mm.finish();
 }
}

----------------------
Re: moving desktop
Reply #6 - Apr 22nd, 2009, 8:12pm
 
I'm trying to do something very similar but the transparency is not being preserved.

The following block conserves transparency:
Code:
File imageFile = new File("image.png");
ImageIO.write(bufferedImage, "png", imageFile);
img = loadImage("image.png");


But it's lost if I use this format:
Code:
img = new PImage(bufferedImage); 



Anyone experiences this or have ideas for a workaround? Thanks.
Re: moving desktop
Reply #7 - Apr 23rd, 2009, 1:52am
 
There is no transparency in screenshots. No?
Page Index Toggle Pages: 1