java 在图片上画图_[原创]JAVA在已有图片上面画图的实例

--sunfruit

简介:JAVA在已有图片上面画图的实例,下面的程序在已有的图片上面画了一个蓝色的方块

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import java.io.FileInputStream;

import javax.imageio.ImageIO;

import javax.swing.ImageIcon;

import java.util.Random;

import java.io.IOException;

import java.io.File;

public class ImageTest {

public ImageTest() throws Exception {

String ext="png";

FileInputStream in = new FileInputStream("已有图片的路径");

byte[] bytes = new byte[in.available()];

in.read(bytes);

in.close();

Random random=new Random(System.currentTimeMillis());

ImageIcon imageIcon = new ImageIcon(bytes);

BufferedImage bufferedImage=new BufferedImage(imageIcon.getIconHeight()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Java 3D画图实例,它绘制了一个旋转的立方体: ```java import java.applet.Applet; import java.awt.BorderLayout; import java.awt.GraphicsConfiguration; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.SimpleUniverse; public class Java3DExample extends Applet { public Java3DExample() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas = new Canvas3D(config); add("Center", canvas); BranchGroup scene = createSceneGraph(); scene.compile(); SimpleUniverse simpleU = new SimpleUniverse(canvas); simpleU.getViewingPlatform().setNominalViewingTransform(); simpleU.addBranchGraph(scene); } public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); Transform3D tr = new Transform3D(); tr.setTranslation(new Vector3f(0.0f, 0.0f, -5.0f)); objRoot.addChild(new ColorCube(0.4)); Alpha rotationAlpha = new Alpha(-1, 4000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objRoot, tr, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objRoot.addChild(rotator); return objRoot; } public static void main(String[] args) { new MainFrame(new Java3DExample(), 640, 480); } } ``` 这个例子创建了一个Java 3D场景,其中包含一个旋转的彩色立方体。要运行这个例子,请将它保存到名为Java3DExample.java的文件中,并使用Java编译器编译它。然后,从命令行运行以下命令: ``` appletviewer Java3DExample.java ``` 这将在窗口中显示一个Java 3D场景,您可以在其中旋转和缩放立方体。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值