ghtjkl ghtjkl
关注数: 4 粉丝数: 16 发帖数: 1,847 关注贴吧数: 0
周末是谁要图片随鼠标旋转来着。。代码在这 public class Rota extends JFrame implements MouseMotionListener { //这里改图片位置 private static final String PATH = "D:\\11.png"; private static final int WIDTH = 500, HEIGHT = 500; private Images image; public Rota() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle("Rota"); this.setBounds(50, 50, WIDTH, HEIGHT); image = new Images(PATH); this.addMouseMotionListener(this); this.setVisible(true); image.draw(this.getGraphics()); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new Rota(); } @Override public void mouseDragged(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseMoved(MouseEvent e) { // TODO Auto-generated method stub int x = e.getX(); int y = e.getY(); image.set(x, y); image.draw(this.getGraphics()); } class Images { private Image image; private double degree = 0; private int width; private int height; private int x, y; private int lastX, lastY; public Images(String path) { image = new ImageIcon(path).getImage(); this.width = image.getWidth(null); this.height = image.getHeight(null); this.getCenter(); lastX = WIDTH / 2; lastY = HEIGHT / 2; } public void rotate(double d) { if (degree > 360) { degree -= 360; } if (degree < -360) { degree += 360; } this.degree += d; } public void getCenter() { x = WIDTH / 2 - width / 2; y = HEIGHT / 2 - height / 2; } public int getArea(int xp, int yp) { if (xp >= 0 && xp <= 250 && yp >= 0 && yp <= 250) { return 1; } else if (xp > 250 && xp <= 500 && yp >= 0 && yp <= 250) { return 2; } else if (xp >= 250 && xp <= 500 && yp > 250 && yp <= 500) { return 3; } else if(xp >= 0 && xp <= 250 && yp > 250 && yp <= 500) { return 4; } return 0; } public void set(int xp, int yp) { int key = this.getArea(xp, yp); switch (key) { case 1: if (xp < lastX) { this.rotate(-1); } else { this.rotate(1); } if (yp < lastY) { this.rotate(1); } else { this.rotate(-1); } break; case 2: if (xp < lastX) { this.rotate(-1); } else { this.rotate(1); } if (yp < lastY) { this.rotate(-1); } else { this.rotate(1); } break; case 3: if (xp < lastX) { this.rotate(1); } else { this.rotate(-1); } if (yp < lastY) { this.rotate(-1); } else { this.rotate(1); } break; case 4: if (xp < lastX) { this.rotate(1); } else { this.rotate(-1); } if (yp < lastY) { this.rotate(1); } else { this.rotate(-1); } break; } this.lastX = xp; this.lastY = yp; } public void draw(Graphics g) { Graphics2D g2d = (Graphics2D) g; //清理屏幕好闪我就注释了如果不怕闪可以开 // g2d.clearRect(0, 0, WIDTH, HEIGHT); g2d.rotate(Math.toRadians(degree), WIDTH / 2, HEIGHT / 2); g2d.drawImage(image, x, y, null); } } }
【HELP】图片旋转算法问题。。 现在图片旋转有2个方法 但都有点问题 大神们帮我看看 代码1 这个旋转之后两边有黑色填充的。。。 BufferedImage sour = toBufferedImage(image); int width = sour.getWidth(); int height = sour.getHeight(); BufferedImage dstImag = new BufferedImage(width,height, sour.getType()); Graphics2D tmpG = (Graphics2D)dstImag.getGraphics(); tmpG.translate(width/2, height/2); tmpG.setBackground(Color.WHITE); tmpG.rotate(angle*Math.PI/180); tmpG.translate(-width/2, -height/2); tmpG.drawImage(sour, 0, 0, width, height, 0, 0, width, height, null); return dstImag; 代码2 这个只要是90度的倍数就没问题 但是其他的度数就也有黑色填充,而且越转图片越小。。。 int src_width = image.getWidth(null); // int src_height = image.getHeight(null); // // calculate the new image size // Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension( // src_width, src_height)), (int)angle); // // BufferedImage res = null; // res = new BufferedImage(rect_des.width, rect_des.height, // BufferedImage.TYPE_INT_RGB); // Graphics2D g2 = res.createGraphics(); // // transform // g2.translate((rect_des.width - src_width) / 2, // (rect_des.height - src_height) / 2); // g2.rotate(Math.toRadians(angle), src_width / 2, src_height / 2); // // g2.drawImage(image, null, null); // return res; public static Rectangle CalcRotatedSize(Rectangle src, int angel) { // if angel is greater than 90 degree, we need to do some conversion if (angel >= 90) { if(angel / 90 % 2 == 1){ int temp = src.height; src.height = src.width; src.width = temp; } angel = angel % 90; } double r = Math.sqrt(src.height * src.height + src.width * src.width) / 2; double len = 2 * Math.sin(Math.toRadians(angel) / 2) * r; double angel_alpha = (Math.PI - Math.toRadians(angel)) / 2; double angel_dalta_width = Math.atan((double) src.height / src.width); double angel_dalta_height = Math.atan((double) src.width / src.height); int len_dalta_width = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_width)); int len_dalta_height = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_height)); int des_width = src.width + len_dalta_width * 2; int des_height = src.height + len_dalta_height * 2; return new java.awt.Rectangle(new Dimension(des_width, des_height)); } @windsun_ul @那十无忧
【转】男孩哄女孩上床。。。【非黄勿删啊。。】 生为了哄女孩上床,于是有了下面的一大段对话,不解释太多了,神文是要膜拜的,怎一个普通人才能写得出来啊~读到最后才是亮点啊,这神文你读懂之后别忘了分享给大家哦…… 男:你知道吗?我每天也在想没有你的日子我该怎么过。 女:要是你的心里没有我,我马上便会离开你。 男:不可能,我的心中一直也是这样期盼着。 女:若有其它少女勾引你,你能保持清醒?绝不搭上她们吗? 男:还用说,这是理所当然的。 女:我家里的家务都要由我一个人做吗? 男:不用怕,我会在外头找其它人来帮你干好这差事。 女:将来我要是不能成为你的完美情人怎么办? 男:即使如此,但你在我心中的形象也是不会改变的。 女:若我成为你的妻子,那我肯定有天会人老珠黄,变得很丑,但届时我必会相夫教子,考顺你的双亲。 男:亲爱的,这样的话太令我感动了,简直是梦寐以求。 女:但要是有一天我不在这个世界了,你还是再找一个爱你的人吧。 男:傻孩子,那样的话我情愿一辈子独身了。 女:那请你以后就只能爱我一个,不要再去看其它美女。 男:当然,那是不用多说的。 女:要是你的旧情人来找你,说她还是很挂念你,你会跟她旧情复始吗? 男:我才不管,这事与我何干 女:那我要是被别人欺负,你会怎样? 男:狠狠干掉他,我绝不能让这种事发生 女:如果我怀孕了,你会负责吗? 男:这绝对是男人应有的责任,也是该有的表现 女:你会把工资的一大部份都花在赌博上吗? 男:不会,这是不能原谅的,绝不能让那种事发生,那怕只是偶然一次 女:我要是做错事,你会原谅我吗? 男:那是肯定的,而且理应是要包容这种事 女:你会出轨,对我不忠吗? 男:这样的话最痛苦的肯定是我自己 女:我要你经常在早上都抱着我然后对我说「我爱你」 男:还用说?这种事最好每天至少发生一次 女:若你碰到死缠不休的女子疯狂追求你,那你会怎样? 男:那我会叫她早点放弃这念头,若她不愿收手,就只能找执法人员帮手了 女:若你对我不好,我母亲可是会代我惩治你的。 男:前者是不可能发生的,因此后者也不可能实现 女:将来我若嫁给你,你会愿意让我母亲也住到你家中吗? 男:当然可以,只要把她带到我们家中,更可以让你看到我和她相亲相爱。 女:我不许你在外面胡混,在其它女子家中过夜或勾三搭四的。 男:我绝不是会做这种事的男人。 女:我若跟你家人争吵,你会站在我这边保护我吗? 男:看情况吧,但一般情况下还是会的。 女:当你愤怒时,你会虐打你的情人吗? 男:不可能,那种事简直是一种犯罪。 女:你能不能让我掌管你的工资,当你的财政大臣? 男:当然了,有些话不用说得太明白 女:你爱我是为了性吗? 男:这种话令我很恶心,请不要再这样说了 女:你真好,我要永永远远也爱你 当男性与女性发生了关系后……. 便露出男性真面目了(请将文章由下往上重新读一遍 )你的支持是我们发帖的动力!请顺手顶个帖,谢谢!
1 下一页