SWT and Image : Image « SWT JFace Eclipse « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » SWT JFace Eclipse » Image 




SWT and Image

/*
SWT/JFace in Action
GUI Design with Eclipse 3.0
Matthew Scarpino, Stephen Holder, Stanford Ng, and Laurent Mihalkovic

ISBN: 1932394273

Publisher: Manning
*/


import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;

public class Ch7_Images {

  public static void main(String[] args) {
    int numRows = 6, numCols = 11, pix = 20;
    PaletteData pd = new PaletteData(new RGB[] { new RGB(0x000x000x00),
        new RGB(0x800x800x80)new RGB(0xFF0xFF0xFF) });

    ImageData[] flagArray = new ImageData[3];
    for (int frame = 0; frame < flagArray.length; frame++) {
      flagArray[framenew ImageData(pix * numCols, pix * numRows, 4,
          pd);
      flagArray[frame].delayTime = 10;
      for (int x = 0; x < pix * numCols; x++) {
        for (int y = 0; y < pix * numRows; y++) {
          int value = (((x / pix3(((y / pix3)) + frame3;
          flagArray[frame].setPixel(x, y, value);
        }
      }
    }

    ImageLoader gifloader = new ImageLoader();
    ByteArrayOutputStream flagByte[] new ByteArrayOutputStream[3];
    byte[][] gifarray = new byte[3][];
    gifloader.data = flagArray;

    for (int i = 0; i < 3; i++) {
      flagByte[inew ByteArrayOutputStream();
      flagArray[0= flagArray[i];
      gifloader.save(flagByte[i], SWT.IMAGE_GIF);
      gifarray[i= flagByte[i].toByteArray();
    }

    byte[] gif = new byte[4628];
    System.arraycopy(gifarray[0]0, gif, 061);
    System.arraycopy(new byte[] { 33(byte25511 }0, gif, 613);
    System.arraycopy("NETSCAPE2.0".getBytes()0, gif, 6411);
    System.arraycopy(new byte[] { 31, -243033, -74, -24 }0,
        gif, 759);
    System.arraycopy(gifarray[0]65, gif, 841512);

    for (int i = 1; i < 3; i++) {
      System.arraycopy(gifarray[i]61, gif, 1516 * i + 803);
      gif[1516 * i + 83(byte-24;
      System.arraycopy(gifarray[i]65, gif, 1516 * i + 841512);
    }

    try {
      DataOutputStream in = new DataOutputStream(
          new BufferedOutputStream(new FileOutputStream(new File(
              "FlagGIF.gif"))));
      in.write(gif, 0, gif.length);
    catch (FileNotFoundException e) {
      e.printStackTrace();
    catch (IOException e) {
      e.printStackTrace();
    }
  }
}



           
       














Related examples in the same category
1.Image Analyzer in SWTImage Analyzer in SWT
2.Set icons with different resolutionsSet icons with different resolutions
3.Capture a widget image with a GCCapture a widget image with a GC
4.Create an icon (in memory)Create an icon (in memory)
5.Display an animated GIFDisplay an animated GIF
6.Rotate and flip an imageRotate and flip an image
7.Display an image in a groupDisplay an image in a group
8.Draw Images ExampleDraw Images Example
9.Clip ImageClip Image
10.Double BufferDouble Buffer
11.Image BasicsImage Basics
12.File Icon Util
13.Demonstrates how to draw imagesDemonstrates how to draw images
14.scroll an image (flicker free, no double buffering)scroll an image (flicker free, no double buffering)
15.Transfer type to transfer SWT ImageData objects.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.