[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: SWT and JAI?
|
- From: Yuri Magrisso <yumariso@xxxxxxxxxxx>
- Date: Tue, 15 Jul 2003 19:20:33 +0200
- Newsgroups: eclipse.platform.swt
- Organization: EclipseCorner
- User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312
Roland wrote:
Would a workaround me to hold the data in JAI objects but pass them to
SWT.Image objects which can then be displayed in an SWT.shell?
You can check http://www.holongate.org
Here is a snippet for converting a AWT image to SWT image:
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.FileInputStream;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import com.sun.image.codec.jpeg.JPEGCodec;
/**
*
*/
public class Awt2Swt {
public static void main(String[] args) {
try {
if ( args.length < 1 ) {
System.out.println("You must specify image path.");
return;
}
String file = args[0];
BufferedImage image = JPEGCodec.createJPEGDecoder(
new FileInputStream(file)).decodeAsBufferedImage();
Rectangle region = new Rectangle(0, 0, image.getWidth(),
image.getHeight());
PaletteData palette = new PaletteData(0x00FF0000, 0x0000FF00,
0x000000FF);
int[] data = ((DataBufferInt) image.getData().getDataBuffer()).getData();
ImageData imageData = new ImageData(region.width, region.height, 32,
palette);
imageData.setPixels(0, 0, data.length, data, 0);
Display display = new Display ();
final Image swtImage = new Image (display, imageData);
Color color = display.getSystemColor (SWT.COLOR_RED);
color.dispose ();
Shell shell = new Shell (display);
shell.setLayout (new FillLayout ());
shell.setBounds(region);
Group group = new Group (shell, SWT.NONE);
group.setLayout (new FillLayout ());
group.setText ("A Photo");
//group.setSize(region.width, region.height);
Canvas canvas = new Canvas (group, SWT.NONE);
canvas.addPaintListener (new PaintListener () {
public void paintControl (PaintEvent e) {
e.gc.drawImage(swtImage, 0, 0);
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
swtImage.dispose ();
display.dispose ();
}
catch ( Exception e ) {
System.out.println("Exception: " e.getMessage());
}
}
}