当前位置: 首页>>代码示例>>Java>>正文


Java Graphics2D.drawRenderedImage方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.drawRenderedImage方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.drawRenderedImage方法的具体用法?Java Graphics2D.drawRenderedImage怎么用?Java Graphics2D.drawRenderedImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


在下文中一共展示了Graphics2D.drawRenderedImage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: print

import java.awt.Graphics2D; //导入方法依赖的package包/类
final public int print(Graphics objPgraphics, PageFormat objPpageFormat, int intPpageIndex) {

		if (this.objGimageAL != null && intPpageIndex < this.objGimageAL.size()) {

			final RenderedImage imgLrendered = (RenderedImage) this.objGimageAL.get(intPpageIndex);

			if (imgLrendered != null) {
				final Graphics2D objLgraphics2D = (Graphics2D) objPgraphics;
				objLgraphics2D.translate(objPpageFormat.getImageableX(), objPpageFormat.getImageableY());

				final double dblLxRatio = objPpageFormat.getImageableWidth() / imgLrendered.getWidth();
				final double dblLyRatio = objPpageFormat.getImageableHeight() / imgLrendered.getHeight();

				objLgraphics2D.scale(dblLxRatio, dblLyRatio);

				final AffineTransform objLaffineTransform =
															AffineTransform.getTranslateInstance(	objPpageFormat.getImageableX(),
																									objPpageFormat.getImageableY());
				objLgraphics2D.drawRenderedImage(imgLrendered, objLaffineTransform);

				return Printable.PAGE_EXISTS;
			}
		}
		return Printable.NO_SUCH_PAGE;
	}
 
开发者ID:jugglemaster,项目名称:JuggleMasterPro,代码行数:26,代码来源:ImagesPrinter.java

示例2: renderTest

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void renderTest(Graphics2D g2d, int w, int h) {
    g2d.setColor(Color.yellow);
    g2d.fillRect(0, 0, w, h);

    BufferedImage image = getTestImage();
    // draw original image
    g2d.drawRenderedImage(image, null);

    // draw image with custom composite
    g2d.translate(175, 25);
    Composite currentComposite = g2d.getComposite();
    g2d.setComposite(new TestComposite());
    g2d.drawRenderedImage(image, null);
    g2d.setComposite(currentComposite);

    // draw image with XOR
    g2d.translate(175, 25);
    g2d.setXORMode(Color.red);
    g2d.drawRenderedImage(image, null);


    System.out.println("Painting is done...");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:CustomCompositeTest.java

示例3: rotate

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage rotate(BufferedImage img, double angle)
{
	double sin = Math.abs(Math.sin(Math.toRadians(angle))),
			cos = Math.abs(Math.cos(Math.toRadians(angle)));

	int w = img.getWidth(null), h = img.getHeight(null);

	int neww = (int) Math.floor(w*cos + h*sin),
			newh = (int) Math.floor(h*cos + w*sin);

	BufferedImage bimg = new BufferedImage(neww, newh, BufferedImage.TYPE_3BYTE_BGR);
	Graphics2D g = bimg.createGraphics();

	g.translate((neww-w)/2, (newh-h)/2);
	g.rotate(Math.toRadians(angle), w/2, h/2);
	g.drawRenderedImage(img, null);
	g.dispose();

	return bimg;
}
 
开发者ID:ForOhForError,项目名称:MTG-Card-Recognizer,代码行数:21,代码来源:ImageUtil.java

示例4: convertType

import java.awt.Graphics2D; //导入方法依赖的package包/类
BufferedImage convertType(BufferedImage src, int targetType) {
	if (src.getType() == targetType) {
		return src;
	}
	BufferedImage tgt = new BufferedImage(src.getWidth(), src.getHeight(), targetType);
	Graphics2D g = tgt.createGraphics();
	g.drawRenderedImage(src, null);
	g.dispose();
	return tgt;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:11,代码来源:EnlargeQQPlot.java

示例5: rotate

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void rotate( Point2D center, double angle ) {
	BufferedImage im = new BufferedImage( width, height, image.TYPE_INT_RGB);
	Graphics2D g = im.createGraphics();
	AffineTransform at = new AffineTransform();
	at.rotate( -angle, center.getX(), center.getY() );
	g.drawRenderedImage( image, at);
	image = im;
	repaint();
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:10,代码来源:ImageComponent.java

示例6: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw( Graphics2D g ) {
	if( image==null )return;
	AffineTransform at = g.getTransform();
	g.translate( x0, y0 );
	g.scale( scale, scale );
	g.drawRenderedImage(image, new AffineTransform() );
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:8,代码来源:MapImage.java

示例7: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics2D g, AffineTransform aTrans, Rectangle2D bounds) {
	AffineTransform at0 = g.getTransform();
	g.transform( aTrans );
	g.translate( x, y );
	g.scale( scale, scale );
	g.drawRenderedImage( image, new AffineTransform() );
	g.setTransform( at0 );
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:9,代码来源:ImageLayer.java

示例8: transcode

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
    protected void transcode(Document document,
                             String uri,
                             TranscoderOutput output)
                             throws TranscoderException {
      if (SystemUtils.IS_OS_MAC_OSX) {
        final Element g = document.createElementNS(
          SVGDOMImplementation.SVG_NAMESPACE_URI, "g"
        );
        g.setAttributeNS(null, "transform", "rotate(0.000001)");
      
        // interpose this <g> element between <svg> and its children
        final Element svg = document.getDocumentElement();
        Node n = null;
        while ((n = svg.getFirstChild()) != null) {
          g.appendChild(n);
        }

        svg.appendChild(g);
      }

      // Sets up root, curTxf & curAoi
      super.transcode(document, uri, output);

       // prepare the image to be painted
      int w = (int)(width+0.5);
      int h = (int)(height+0.5);

      // paint the SVG document using the bridge package
      // create the appropriate renderer
      ImageRenderer renderer = rendFactory.createStaticImageRenderer();
      renderer.updateOffScreen(w, h);
      if (xform != null) curTxf.concatenate(xform);
      renderer.setTransform(curTxf);
      renderer.setTree(this.root);
      this.root = null; // We're done with it...

      // now we are sure that the aoi is the image size
      final Shape raoi = new Rectangle2D.Float(0, 0, width, height);
      // Warning: the renderer's AOI must be in user space
      try {
        renderer.repaint(curTxf.createInverse().
                         createTransformedShape(raoi));
      }
      catch (NoninvertibleTransformException e) {
        throw new TranscoderException(e);
      }

// FIXME: is this the image we want to use?
      BufferedImage rend = renderer.getOffScreen();
      renderer = null; // We're done with it...

      // produce an opaque image if our background color is set
      final BufferedImage dest = ImageUtils.createCompatibleImage(
        w, h, !hints.containsKey(KEY_BACKGROUND_COLOR)
      );

      final Graphics2D g2d = GraphicsUtil.createGraphics(dest);
      if (hints.containsKey(KEY_BACKGROUND_COLOR)) {
        final Paint bgcolor = (Paint) hints.get(KEY_BACKGROUND_COLOR);
        g2d.setComposite(AlphaComposite.SrcOver);
        g2d.setPaint(bgcolor);
        g2d.fillRect(0, 0, w, h);
      }

      if (rend != null) { // might be null if the svg document is empty
        g2d.drawRenderedImage(rend, new AffineTransform());
      }
      g2d.dispose();
      rend = null; // We're done with it...

      writeImage(dest, output);
    }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:74,代码来源:SVGRenderer.java

示例9: getHighRes

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static boolean getHighRes(double[] wesn, int width, int height, BufferedImage image) {
	getImage(wesn, width, height, image);
	Graphics2D g = image.createGraphics();
	Rectangle rect = new Rectangle(0, 0, width, height);
	double scale = (wesn[1] - wesn[0]) / (double)width;
	double r = 1/scale;
	if(r < (double)res[0]) return false;
	int ires = 0;
	while( r < (double)highRes[ires] && ires<highRes.length-1) ires++;
	if(ires == highRes.length-1) ires--;
	double gridScale = 600 / (double) highRes[ires];

	int x1 = (int) Math.floor( wesn[0] / gridScale);
	int x2 = (int) Math.ceil( wesn[1] / gridScale);
	int xmax = (int) Math.ceil( 360 / gridScale);

	int y1 = (int) Math.ceil( wesn[3] / gridScale);
	int y2 = (int) Math.floor( wesn[2] / gridScale);
	Rectangle clipRect = new Rectangle(8, 8, 600, 600);

	int xgrid, ygrid;
	String name;
	File file;
	double x0, y0;
	double west;
	double north;
	double offset;
	double pad = 8 / (double) highRes[ires];
	BufferedImage im = null;
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
		RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	AffineTransform at = new AffineTransform();
	boolean returnVal = false;
	for( int x=x1 ; x<x2 ; x++ ) {
		xgrid = x;
		offset = -pad;
		while(xgrid < 0) {
			xgrid += xmax;
			offset -= 360;
		}
		while(xgrid >= xmax) {
			xgrid -= xmax;
			offset += 360;
		}
		west = (double) xgrid * gridScale + offset;
		x0 = (west - wesn[0]) / scale;
		for( int y=y1 ; y>y2 ; y--) {

			north = (double)y *gridScale + pad;
			if( y>0 ) {
				name = "g" + highRes[ires] + "_" + xgrid + "_N" + y +".jpg";
			} else {
				ygrid = -y;
				name = "g" + highRes[ires] + "_" + xgrid + "_S" + ygrid +".jpg";
			}
			String url = haxby.map.MapApp.TEMP_BASE_URL + "tiles/g"+highRes[ires]+"/" + name;
			im = null;
			try { 
				BufferedInputStream in = new BufferedInputStream(
					(URLFactory.url(url)).openStream());
				//JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
				//im = decoder.decodeAsBufferedImage();
				im = ImageIO.read(in);
				in.close();
			} catch ( Exception ioe) {
				continue;
			}
			g.setTransform(at);
			g.setClip(rect);
			y0 = (wesn[3] - north) / scale ;
			g.translate(x0, y0);
			double scl = 1 / ((double) highRes[ires] * scale);
			g.scale(scl, scl);
			g.clip(clipRect);
			returnVal = true;
			g.drawRenderedImage(im, at);
		}
	}
	return returnVal;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:81,代码来源:MapServerA.java

示例10: getHighRes

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static boolean getHighRes(double[] wesn, int width, int height, BufferedImage image) {
	getImage(wesn, width, height, image);
	Graphics2D g = image.createGraphics();
	Rectangle rect = new Rectangle(0, 0, width, height);
	double scale = (wesn[1] - wesn[0]) / (double)width;
	double r = 1/scale;
	if(r < (double)res[0]) return false;
	int ires = 0;
	while( r < (double)highRes[ires] && ires<highRes.length-1) ires++;
	if(ires == highRes.length-1) ires--;
	double gridScale = 600 / (double) highRes[ires];
	
	int x1 = (int) Math.floor( wesn[0] / gridScale);
	int x2 = (int) Math.ceil( wesn[1] / gridScale);
	int xmax = (int) Math.ceil( 360 / gridScale);

	int y1 = (int) Math.ceil( wesn[3] / gridScale);
	int y2 = (int) Math.floor( wesn[2] / gridScale);
	Rectangle clipRect = new Rectangle(8, 8, 600, 600);

	int xgrid, ygrid;
	String name;
	File file;
	double x0, y0;
	double west;
	double north;
	double offset;
	double pad = 8 / (double) highRes[ires];
	BufferedImage im = null;
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
		RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	AffineTransform at = new AffineTransform();
	boolean returnVal = false;
	for( int x=x1 ; x<x2 ; x++ ) {
		xgrid = x;
		offset = -pad;
		while(xgrid < 0) {
			xgrid += xmax;
			offset -= 360;
		}
		while(xgrid >= xmax) {
			xgrid -= xmax;
			offset += 360;
		}
		west = (double) xgrid * gridScale + offset;
		x0 = (west - wesn[0]) / scale;
		for( int y=y1 ; y>y2 ; y--) {
			
			north = (double)y *gridScale + pad;
			if( y>0 ) {
				name = "g" + highRes[ires] + "_" + xgrid + "_N" + y +".jpg";
			} else {
				ygrid = -y;
				name = "g" + highRes[ires] + "_" + xgrid + "_S" + ygrid +".jpg";
			}
			String url = "file:/usr/local/seabeam/kn166-14/copy/science/tiles/g"+highRes[ires]+"/" + name;
			im = null;
			try { 
				BufferedInputStream in = new BufferedInputStream(
					(URLFactory.url(url)).openStream());
				//JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
				//im = decoder.decodeAsBufferedImage();
				im = ImageIO.read(in);
				in.close();
			} catch ( Exception ioe) {
				continue;
			}
			g.setTransform(at);
			g.setClip(rect);
			y0 = (wesn[3] - north) / scale ;
			g.translate(x0, y0);
			double scl = 1 / ((double) highRes[ires] * scale);
			g.scale(scl, scl);
			g.clip(clipRect);
			returnVal = true;
			g.drawRenderedImage(im, at);
		}
	}
	return returnVal;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:81,代码来源:MapServerB.java


注:本文中的java.awt.Graphics2D.drawRenderedImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。