⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mycanvas.java

📁 基于j2me的任意角度图片旋转
💻 JAVA
字号:
package com.midp;
import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


public class MyCanvas extends Canvas {
	Image img;
	
	Image imgRGB;
	int[] pixels;
	
	int width,height;
	
	int radius;
	long time;
	public MyCanvas() {
		setFullScreenMode(true);
		try {
			img = Image.createImage("/2.png");
			width = img.getWidth();
			height = img.getHeight();
			radius = (int)Math.sqrt(width*width + height*height);
			System.out.println("radius:"+radius);
			time = System.currentTimeMillis();
			pixels = pixelsProduce(img);
			pixels = Rotation2.rotate(pixels, width, height, 30);
			imgRGB = Image.createRGBImage(pixels, radius, radius, true);
			time = System.currentTimeMillis() - time;
			System.out.println(time);
			System.out.println("haha");
		} catch (IOException ie) {
			ie.printStackTrace();
		}
	}

	protected void paint(Graphics g) {
		g.setColor(0);
		g.fillRect(0, 0, getWidth(), getHeight());
//		draw(g,60,30);
		g.drawImage(img, getWidth()/2, getHeight()/2-80, g.HCENTER|g.VCENTER);
		g.drawImage(imgRGB, getWidth()/2, getHeight()/2+20, g.HCENTER|g.VCENTER);
//		g.drawImage(img, 80, 120, 0);
		g.setColor(255,255,255);
		g.drawString(""+time, 10, 10, 0);
	}
	
	private int[] pixelsProduce(Image src) {
		int w = src.getWidth();
		int h = src.getHeight();
		int[] _pixels = new int[w * h];
		src.getRGB(_pixels, 0, w, 0, 0, w, h);
		return _pixels;
	}
	
	private void draw(Graphics g,int x,int y)
	{
		g.drawRGB(pixels, 0, 104, x, y, 104, 104, true);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -