📄 qtimage.java
字号:
/* QtImage.java -- Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.java.awt.peer.qt;import java.awt.Graphics;import java.awt.Color;import java.awt.Image;import java.awt.image.ColorModel;import java.awt.image.DirectColorModel;import java.awt.image.MemoryImageSource;import java.awt.image.ImageConsumer;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import java.io.File;import java.io.IOException;import java.io.ByteArrayOutputStream;import java.io.BufferedInputStream;import java.net.URL;import java.util.Hashtable;import java.util.WeakHashMap;import java.util.Vector;/** * QtImage - wraps a QImage * */public class QtImage extends Image{ int width = -1, height = -1; /** * Properties. */ Hashtable props; /** * Loaded or not flag, for asynchronous compatibility. */ boolean isLoaded; /** * Pointer to the QImage */ long nativeObject; /** * Observer queue. */ Vector observers; /** * Error flag for loading. */ boolean errorLoading; /** * Original source, if created from an ImageProducer. */ ImageProducer source; /* * The 32-bit AARRGGBB format the uses. */ static ColorModel nativeModel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); /** * HashMap of Graphics objects painting on this Image. */ WeakHashMap painters; /** * Flags if this image is to be destroyed. */ boolean killFlag; /** * Clears the image to RGBA 0 */ public native void clear(); /** * Returns a copy of the pixel data as a java array. */ private native int[] getPixels(); /** * Sets the pixel data from a java array. */ private native void setPixels(int[] pixels); /** * Loads an image */ private native boolean loadImage(String name); /** * Loads an image from data. */ private native boolean loadImageFromData(byte[] data); /** * Allocates a QImage */ private native void createImage(); /** * Frees the above. */ private synchronized native void freeImage(); /** * Sets the image to scaled copy of src image. hints are rendering hints. */ private native void createScaledImage(QtImage src, int hints); /** * Draws the image optionally composited. */ native void drawPixels (QtGraphics gc, int bg_red, int bg_green, int bg_blue, int x, int y, boolean composite); /** * Draws the image, optionally scaled and composited. */ private native void drawPixelsScaled (QtGraphics gc, int bg_red, int bg_green, int bg_blue, int x, int y, int width, int height, boolean composite); /** * Draws the image transformed. */ private native void drawPixelsTransformed (QtGraphics gc, QMatrix transform); /** * Draws the image scaled flipped and optionally composited. */ native void drawPixelsScaledFlipped (QtGraphics gc, int bg_red, int bg_green, int bg_blue, boolean flipX, boolean flipY, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight, boolean composite); /** * Creates the image from an ImageProducer. May result in an error image. */ public QtImage (ImageProducer producer) { killFlag = false; isLoaded = false; observers = new Vector(); source = producer; errorLoading = false; if( producer != null ) source.startProduction(new QtImageConsumer(this, source)); } /** * Creates the image from a URL. May result in an error image. */ public QtImage (URL url) { killFlag = false; isLoaded = false; observers = new Vector(); errorLoading = false; if( url == null) return; ByteArrayOutputStream baos = new ByteArrayOutputStream( 5000 ); try { BufferedInputStream bis = new BufferedInputStream(url.openStream()); byte[] buf = new byte[5000]; int n = 0; while ( (n = bis.read( buf )) != -1 ) baos.write(buf, 0, n); bis.close(); } catch(IOException e) { throw new IllegalArgumentException("Couldn't load image."); } if ( loadImageFromData( baos.toByteArray() ) != true ) throw new IllegalArgumentException("Couldn't load image."); isLoaded = true; observers = null; props = new Hashtable(); } /** * Constructs a QtImage by loading a given file. * * @throws IllegalArgumentException if the image could not be loaded. */ public QtImage (String filename) { killFlag = false; File f = new File(filename); observers = null; props = new Hashtable(); try { String fn = f.getCanonicalPath(); if (loadImage( fn ) != true) { errorLoading = true; isLoaded = false; return; } } catch(IOException e) { errorLoading = true; isLoaded = false; return; } errorLoading = false; isLoaded = true; } /** * Constructs a QtImage from a byte array of an image file. * * @throws IllegalArgumentException if the image could not be loaded. */ public QtImage (byte[] data) { if (loadImageFromData(data) != true) throw new IllegalArgumentException("Couldn't load image."); killFlag = false; isLoaded = true; observers = null; errorLoading = false; props = new Hashtable(); } /** * Constructs an empty QtImage. */ public QtImage (int width, int height) { this.width = width; this.height = height; props = new Hashtable(); isLoaded = true; killFlag = false; observers = null; errorLoading = false; createImage(); clear(); } /** * Constructs a scaled version of the src bitmap, using Qt */ private QtImage (QtImage src, int width, int height, int hints) { this.width = width; this.height = height; props = new Hashtable(); isLoaded = true; killFlag = false; observers = null; errorLoading = false; createScaledImage(src, hints); } /** * Callback from the image consumer. */ public void setImage(int width, int height, int[] pixels, Hashtable properties) { this.width = width;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -