图片数组的用法??我老是画不出图形来。

jspxnet 2002-01-31 04:28:45
private Image pImg[] = null;
pImg[1] = createImage(300, 300);
pImg[1] = image; //image是有图的
g.drawImage(pImg[1], 0, 0, this);
...全文
185 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jspxnet 2002-01-31
  • 打赏
  • 举报
回复
Image pImg[]; 图片数组
如:
pImg[1] = image1;
pImg[2] = image2;
pImg[3] = image3;

repus 2002-01-31
  • 打赏
  • 举报
回复
没给数组分配空间,不过这样应该出异常的啊。
jspxnet 2002-01-31
  • 打赏
  • 举报
回复
你没有错,我也没有错。
byte[] pixels = new byte[width * height]; //图片点阵数组

Image pImg[]; 图片数组

skyyoung 2002-01-31
  • 打赏
  • 举报
回复
是否用错了
abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
Draws as much of the specified image as is currently available.
abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)
Draws as much of the specified image as is currently available.
abstract boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
abstract boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
jspxnet 2002-01-31
  • 打赏
  • 举报
回复
我想知道的是
Image pImg[];

的用法。
skyyoung 2002-01-31
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.image.*;

public class jwmem2 extends java.applet.Applet
{
Image i;
int width = 200;
int height = 200;
public void init()
{
byte[] pixels = new byte[width * height];
int arraySize = 3;
Color colorArray[] = new Color[arraySize];
colorArray[0] = Color.green;
for(int i = 1; i < arraySize; i ++ )
colorArray[i] = colorArray[i - 1].darker();
byte reds[] = new byte[arraySize];
byte greens[] = new byte[arraySize];
byte blues[] = new byte[arraySize];
for(int i = 0; i < arraySize; i ++ )
{
reds[i] = (byte)colorArray[i].getRed();
greens[i] = (byte)colorArray[i].getGreen();
blues[i] = (byte)colorArray[i].getBlue();
}
for(int index = 0, y = 0; y < height; y ++ )
for(int x = 0; x < width; x ++ )
pixels[index++] = (byte)(x % arraySize);
i = createImage(new MemoryImageSource(width, height, new IndexColorModel(8, arraySize, reds, greens, blues), pixels, 0, width));
setFont(new Font("TimesRoman", Font.BOLD | Font.ITALIC, 32));
}
public void paint(Graphics g)
{
g.drawImage(i, 0, 0, this);
g.drawString("JavaWorld", 30, 80);
}
}

skyyoung 2002-01-31
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.image.*;

public class jwmem extends java.applet.Applet
{
Image i;
int width = 200;
int height = 200;
public void init()
{
int[] pixels = new int[width * height];
int c;
double radianConversion = Math.PI / 180.0;
for(int index = 0, y = 0; y < height; y ++ )
{
c = ((0xff) & (byte)(Math.abs(Math.sin((y + height) * radianConversion)) * 255));
for(int x = 0; x < width; x ++ )
{
pixels[index++] = ((0xff << 24) | (c << 16) | (c << 8) | c);
}
}
i = createImage(new MemoryImageSource(width, height, pixels, 0, width));
setFont(new Font("TimesRoman", Font.BOLD | Font.ITALIC, 32));
}
public void paint(Graphics g)
{
g.drawImage(i, 0, 0, this);
g.drawString("JavaWorld", 30, 80);
}
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧