本篇文章给大家谈谈java图片的切换和渐变,以及如何把图片变成渐变对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
1、在一个界面中要实现图片切换,用java要怎么实现??2、在线等:java图片怎样使之渐变消失3、Java里面的GUI设计中怎么实现颜色的渐变(各个部分的RGB值不同)?4、android 如何实现背景图片渐变切换
在一个界面中要实现图片切换,用java要怎么实现??
如果是普通切换的话,直接定义一个int值,根据int值的不同 来画不同的东西就可以了\x0d\x0aint index;\x0d\x0aswitch(index){\x0d\x0a case 0:\x0d\x0a g.drawImage(a,0,0,20); \x0d\x0a break;\x0d\x0a case 1:\x0d\x0a g,drawImage(b,0,0,20);\x0d\x0a break;\x0d\x0a ……………………………\x0d\x0a}\x0d\x0a \x0d\x0a如果用渐变效果的话,创建一个数组记录下一张要话的图片的所有RGB值,初始设置所有像素点的透明度为100%,即完全透明,然后一点点的把透明度降低,直到为0,这样就把第二章图片用渐变的方法绘制出来了,这时就可以不用画第一张图片了。
在线等:java图片怎样使之渐变消失
使用js定时器setTimeout()方法,定时三秒将要修改的图片的display设为none.
script type=”text/javascript”
setTimeout(function(){//定时器
$(“img”).css(“display”,”none”);//将图片的display属性设置为none
},
3000);//设置三千毫秒即3秒
/script
你要是非要用java实现,可以试验下
public class Splash extends Canvas implements Runnable {
/**
* 声明变量
*/
public ScrawlMidlet midlet = null;
public ScreenControl scontrol;
private volatile Thread splashThread = null;
private long startTime;
private long endTime;
private int FRAME_TIME = 80;
private int width;
private int height;
private int alpha = 0;
private Image splashImage = null;
private int argb[];
private boolean isIn;
/**
* 构造函数
*/
public Splash(ScrawlMidlet midlet) {
this.midlet = midlet;
setFullScreenMode(true);
this.width = this.getWidth();
this.height = this.getHeight();
try {
splashImage = Image.createImage(“/Image/lostz1.png”);
} catch (java.io.IOException ex) {
System.out.println(“闪屏中图片加载错误!”);
}
argb = new int[splashImage.getWidth() * splashImage.getHeight()];
splashImage.getRGB(argb, 0, splashImage.getWidth(), 0, 0, splashImage.getWidth(), splashImage.getHeight());
isIn = true;
start();
}
public void start() {
splashThread = new Thread(this);
splashThread.start();
scontrol = new ScreenControl(midlet);
}
public void stop() {
splashImage = null;
splashThread = null;
System.gc();
Thread.yield();
}
public void paint(Graphics g) {
System.gc();
Thread.yield();
g.setColor(255, 255, 255);
g.fillRect(0, 0, width, height);
if (isIn) {
if (alpha 255) {
for (int i = 0; i argb.length; i++) {
argb[i] = (alpha 24) | (argb[i] 0x00FFFFFF);
}
g.drawRGB(argb, 0, splashImage.getWidth(), (width – splashImage.getWidth()) / 2,
(height – splashImage.getHeight()) / 2, splashImage.getWidth(), splashImage.getHeight(), true);
alpha += 15;
} else {
isIn = false;
g.drawImage(splashImage, width / 2, height / 2, Graphics.VCENTER | Graphics.HCENTER);
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
} else {
if (alpha = 0) {
for (int i = 0; i argb.length; i++) {
argb[i] = (alpha 24) | (argb[i] 0x00FFFFFF);
}
g.drawRGB(argb, 0, splashImage.getWidth(), (width – splashImage.getWidth()) / 2,
(height – splashImage.getHeight()) / 2, splashImage.getWidth(), splashImage.getHeight(), true);
alpha -= 15;
} else {
finish();
}
}
}
public void run() {
try {
Thread currentThread = Thread.currentThread();
while (currentThread == splashThread) {
startTime = System.currentTimeMillis();
repaint(0, 0, width, height);
serviceRepaints();
endTime = System.currentTimeMillis();
if (endTime – startTime FRAME_TIME) {
Thread.sleep(FRAME_TIME – (endTime – startTime));
}
}
} catch (InterruptedException ie) {
System.out.println(ie.toString());
}
}
private void finish() {
stop();
if (scontrol == null) {
scontrol = new ScreenControl(midlet);
} else {
scontrol.show();
}
}
}
Java里面的GUI设计中怎么实现颜色的渐变(各个部分的RGB值不同)?
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class RGB extends JFrame implements ActionListener{
JTextField t1,t2,t3;
JLabel b1,b2,b3;
JButton jb;
JPanel jp;
public RGB(){
super(“RGB”);
jp=new JPanel();
b1=new JLabel(“R”);
b2=new JLabel(“G”);
b3=new JLabel(“B”);
t1=new JTextField(3);
t2=new JTextField(3);
t3=new JTextField(3);
jb=new JButton(“确定”);
jb.addActionListener(this);
jp.add(b1);
jp.add(t1);
jp.add(b2);
jp.add(t2);
jp.add(b3);
jp.add(t3);
jp.add(jb);
jp.setLayout(new FlowLayout());
add(jp,BorderLayout.CENTER);
setSize(200,200);
setResizable(false);
setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource().getClass().getSimpleName().equals(“JButton”)){
int r=Integer.parseInt(t1.getText());
int g=Integer.parseInt(t2.getText());
int b=Integer.parseInt(t3.getText());
if(r=0 r=255 g=0 g=255 b=0 b=255){
Color c=new Color(r,g,b);
jp.setBackground(c);
}else{
System.out.println(“请输入(0-255)的整数!”);
}
}
}
public static void main(String[] args) {
new RGB();
}
}
android 如何实现背景图片渐变切换
解决方案1:
其他的和线性渐变相同。为了演 示图像渐变效果。
一, float radius, float x1。
SweepGradient(float cx。
LinearGradient(float x0,所以建议使用下面的重载方法,他们的基类为android、RadialGradient镜像渐变
有了上面的基础. If positions is NULL,代码如下,他们的不同之处为参数中第一种方法可以用颜色数组, int color1, float radius;/,然后通过载入的颜色来平均的渐变渲染, the drawing may produce unexpected results, int[] colors.RED,p).TileMode tile)
使用实例如下.TileMode, float[] positions; /, int color0,最后参数为平铺方式, Shader,100, float y0. If the values are not monotonic.graphics, float y1,这里设置为镜像
刚才已经讲到Gradient是基于Shader类,前两个参数为中心点.TileMode tile)
LinearGradient(float x0.drawCicle(0;
canvas.Shader,参数三和四分辨对应渐变终点.TileMode tile)
三, int color0,所以我们通过Paint的setShader方法来设置这个渐变,200,则渐变将会逐一处理。
二, float[] positions,径向渐变第三个参数是半径, int[] colors在android, beginning with 0 and ending with 1,本方法一般为NULL即可.、SweepGradient角度渐变
对于一些3D立体效果的渐变可以尝试用角度渐变来完成一个圆锥形, float cy. The relative position of each corresponding color in the colors array.setShader(lg),和位置来实现更细腻的过渡效果, 比如颜 色采样int[] colors数组中存放20种颜色, float x1,Shader。
RadialGradient(float x, float[] positions) /。而第二种方法参数仅为起初颜色color0和最终颜色color1, Shader。和上面参数唯一不同的是, then the colors are automatically spaced evenly,0, float y,了解这些对打好Android游戏开发的基础很有好处;对于最后一个参数SDK上的描述为May be NULL.graphics中提供了有关Gradient字样的类, Shader。
SweepGradient(float cx;参数3为画圆的半径;
LinearGradient lg=new LinearGradient(0,希望大家对图像特效处理有了一定的认识,0,参数二为y轴位置,我们一起来了解下径向渐变;/,类型为float型,相对来说比上面更简单,Color; /, int color1)
到此,100,Color.TileMode tile)
RadialGradient(float x.MIRROR).BLUE, float y0, int color0,例如LinearGradient线性渐变:
p, int color1、LinearGradient线性渐变
在android平台中提供了两种重载方式来实例化该类分别为,下面给出一个简单的实例, int[] colors, float cy, Shader, float y1;参数一为渐变起初点坐标x位置:
Paint p=new Paint(), float y.0、 RadialGradient径向渐变和SweepGradient角度渐变三种。
关于java图片的切换和渐变和如何把图片变成渐变的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。