j2me中如何改变图片的大小合透明度

在手机应用程序开发的过程中一定会接触图形界面的开发。请编写一个函数/方法来实现对PNG格式的像素图进行编辑操作。编辑内容如下:1.对图片进行缩放:输入参数为图片的指针/引... 在手机应用程序开发的过程中一定会接触图形界面的开发。请编写一个函数/方法来实现对PNG格式的像素图进行编辑操作。编辑内容如下:
1. 对图片进行缩放:输入参数为图片的指针/引用、缩放后的宽,高;
2. 修改图片透明度:输入参数为图片的指针/引用、透明度(百分比);
代码要求:答案分为两部分一部分为代码,一部分为语言描述的编写思路;可以定义全局变量/类变量。答案还可以对编辑内容进行选择,可选择其中任意的一种,也可以全部选择。

谢谢..急..
展开
 我来答
daay1986
2009-03-05 · TA获得超过6018个赞
知道大有可为答主
回答量:2208
采纳率:0%
帮助的人:1452万
展开全部
图片大小
/** A demonstration of anti-aliasing */
public class AntiAlias extends JPanel {

static final int WIDTH = 650, HEIGHT = 350; // Size of our example

public String getName() {
return "AntiAliasing";
}

public int getWidth() {
return WIDTH;
}

public int getHeight() {
return HEIGHT;
}

/** Draw the example */
public void paint(Graphics g1) {
Graphics2D g = (Graphics2D) g1;
BufferedImage image = // Create an off-screen image
new BufferedImage(65, 35, BufferedImage.TYPE_INT_RGB);
Graphics2D ig = image.createGraphics(); // Get its Graphics for drawing

// Set the background to a gradient fill. The varying color of
// the background helps to demonstrate the anti-aliasing effect
ig.setPaint(new GradientPaint(0, 0, Color.black, 65, 35, Color.white));
ig.fillRect(0, 0, 65, 35);

// Set drawing attributes for the foreground.
// Most importantly, turn on anti-aliasing.
ig.setStroke(new BasicStroke(2.0f)); // 2-pixel lines
ig.setFont(new Font("Serif", Font.BOLD, 18)); // 18-point font
ig.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
RenderingHints.VALUE_ANTIALIAS_ON);

// Now draw pure blue text and a pure red oval
ig.setColor(Color.blue);
ig.drawString("Java", 9, 22);
ig.setColor(Color.red);
ig.drawOval(1, 1, 62, 32);

// Finally, scale the image by a factor of 10 and display it
// in the window. This will allow us to see the anti-aliased pixels
g.drawImage(image, AffineTransform.getScaleInstance(10, 10), this);

// Draw the image one more time at its original size, for comparison
g.drawImage(image, 0, 0, this);
}

public static void main(String[] a) {
JFrame f = new JFrame();
f.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setContentPane(new AntiAlias());
f.setSize(400, 400);
f.setVisible(true);
}
}

透明度:

public class MyCanvas extends JComponent {

private static Color m_tRed = new Color(255, 0, 0, 150);
private static Color m_tGreen = new Color(0, 255, 0, 150);
private static Color m_tBlue = new Color(0, 0, 255, 150);
private static Font monoFont = new Font("Monospaced", Font.BOLD | Font.ITALIC, 36);
private static Font sanSerifFont = new Font("SanSerif", Font.PLAIN, 12);
private static Font serifFont = new Font("Serif", Font.BOLD, 24);
private static ImageIcon java2sLogo = new ImageIcon("java2s.gif");

public void paintComponent(Graphics g) {
super.paintComponent(g);

// draw entire component white
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());

// yellow circle
g.setColor(Color.yellow);
g.fillOval(0, 0, 240, 240);

// magenta circle
g.setColor(Color.magenta);
g.fillOval(160, 160, 240, 240);

// paint the icon below blue sqaure
int w = java2sLogo.getIconWidth();
int h = java2sLogo.getIconHeight();
java2sLogo.paintIcon(this, g, 280 - (w / 2), 120 - (h / 2));

// paint the icon below red sqaure
java2sLogo.paintIcon(this, g, 120 - (w / 2), 280 - (h / 2));

// transparent red square
g.setColor(m_tRed);
g.fillRect(60, 220, 120, 120);

// transparent green circle
g.setColor(m_tGreen);
g.fillOval(140, 140, 120, 120);

// transparent blue square
g.setColor(m_tBlue);
g.fillRect(220, 60, 120, 120);

g.setColor(Color.black);

g.setFont(monoFont);
FontMetrics fm = g.getFontMetrics();
w = fm.stringWidth("Java Source");
h = fm.getAscent();
g.drawString("Java Source", 120 - (w / 2), 120 + (h / 4));

g.setFont(sanSerifFont);
fm = g.getFontMetrics();
w = fm.stringWidth("and");
h = fm.getAscent();
g.drawString("and", 200 - (w / 2), 200 + (h / 4));

g.setFont(serifFont);
fm = g.getFontMetrics();
w = fm.stringWidth("Support.");
h = fm.getAscent();
g.drawString("Support.", 280 - (w / 2), 280 + (h / 4));
}

public Dimension getPreferredSize() {
return new Dimension(400, 400);
}

public Dimension getMinimumSize() {
return getPreferredSize();
}

public static void main(String args[]) {
JFrame mainFrame = new JFrame("Graphics demo");
mainFrame.getContentPane().add(new MyCanvas());
mainFrame.pack();
mainFrame.setVisible(true);
}
}
百度网友f3f73e840
2009-03-05
知道答主
回答量:40
采纳率:0%
帮助的人:0
展开全部
太专业了~ 无能为力
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2009-03-05
展开全部
是雷象的笔试题。。。。。。。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式