affinetransform

Draw an Image in arbitrary corners

核能气质少年 提交于 2019-12-02 03:57:46
So i have a normal image. I defined Click- and Drag-Listeners on each corner of the rectangular image. I want to freely transform each of the corners and paint it on the screen. The AffineTransform class provides transformation possibilities but i couldn't find a way to realize this. I have implemented the same function in android with the Matrix.setPolytoPoly method. However there is no equivalent in java swing. Thanks! Edit: I would like to illustrate this process with the following image: This should happen when i drag one corner to the upper left. Now the problem that i have is, that i don

JComponent JPanel Zoom, pan and Coordinates Question

不羁岁月 提交于 2019-12-02 03:57:21
I have a JPanel with an vector image that the user can zoom and pan on. Overlaying this image is a (transparent) JComponent , which I allow the user to annotate the underlying image. This works great at full scale, but If I zoom in, using AffineTransform , the overlaying coordinates are affected also. So, If a user draws a box on the image the box is scaled also. Any suggestions on how to decouple this behaviour? So that the JComponent is not affected by the JPanel 's AffineTransform ? trashgod Typically, you need both a forward and inverse transform to translate between the two co-ordinate

Image not at proper place after rotating (graphics)

 ̄綄美尐妖づ 提交于 2019-12-01 22:28:24
I am trying to display two rotating wheels with diameter 512untis at different rates but i am not able to remove the previous drawn image graphics and set the rotated graphics at the correct position. For now i am doing a rotation with arbitrary angle. I tried affineTransform and got the rotations but it was weird like all pixels spread away. Im using a while loop with thread.sleep(). The following is the code : //The drawSmallCircle and drawBigCircle return two images. class MyFramePart2 extends JFrame { String name; JPanel big_obj_panel,small_obj_panel; JLabel bigLabel,smallLabel

AffineTransform truncates image

眉间皱痕 提交于 2019-12-01 14:18:34
I have an image and I have to rotate it by 45, 90, 135, 180 degrees. What I am doing: try { BufferedImage src = ImageIO.read(new File("src.png")); double ang = Math.toRadians(90); AffineTransform t = new AffineTransform(); t.setToRotation(ang, src.getWidth() / 2, src.getHeight() / 2); AffineTransformOp op = new AffineTransformOp(t, null); BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), src.getType()); op.filter(src, dst); ImageIO.write(dst, "png", new File("output.png")); } catch(Exception ex) { ex.printStackTrace(); } The problem is that image changes its position and

Java rotate image turns part of background black

江枫思渺然 提交于 2019-12-01 14:13:47
When I try to rotate an image it appears that a part of the background turns black (my images are transparents) Background white Part of background turns black Here's the code that rotate the image : public BufferedImage rotate(int height, int width, BufferedImage originalImg, int angle) { BufferedImage rotateImage = null; try { rotateImage = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB); AffineTransform a90 = AffineTransform.getRotateInstance(Math.toRadians(angle), height / 2, width / 2); AffineTransformOp op90 = new AffineTransformOp(a90, AffineTransformOp.TYPE_BILINEAR); op90

Java rotate image turns part of background black

坚强是说给别人听的谎言 提交于 2019-12-01 12:21:58
问题 When I try to rotate an image it appears that a part of the background turns black (my images are transparents) Background white Part of background turns black Here's the code that rotate the image : public BufferedImage rotate(int height, int width, BufferedImage originalImg, int angle) { BufferedImage rotateImage = null; try { rotateImage = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB); AffineTransform a90 = AffineTransform.getRotateInstance(Math.toRadians(angle), height / 2,

AffineTransform: scaling a Shape from its center

北慕城南 提交于 2019-11-30 15:26:48
问题 I'm trying to scale a rectangle from its center using AffineTransform. I'm sure the solution is obvious but I cannot make it work ! Here is what I've tested so far... import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Test extends JPanel { Test() { super(null); setOpaque(true); setBackground(Color.WHITE);

AffineTransform: scaling a Shape from its center

不问归期 提交于 2019-11-30 14:33:29
I'm trying to scale a rectangle from its center using AffineTransform. I'm sure the solution is obvious but I cannot make it work ! Here is what I've tested so far... import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Test extends JPanel { Test() { super(null); setOpaque(true); setBackground(Color.WHITE); setPreferredSize(new Dimension(200,200)); } @Override protected void paintComponent(Graphics g1) {

Transform a triangle to another triangle

家住魔仙堡 提交于 2019-11-30 04:59:25
Hi i am trying to create the affine transform that will allow me to transform a triangle into another one. What i have are the coordinates for the 2 triangles. Can you help me? Following the answer by Adam Rosenfield i came up with this code in case anyone is bored to solve the equation himself : public static AffineTransform createTransform(ThreePointSystem source, ThreePointSystem dest) { double x11 = source.point1.getX(); double x12 = source.point1.getY(); double x21 = source.point2.getX(); double x22 = source.point2.getY(); double x31 = source.point3.getX(); double x32 = source.point3.getY

DICOM affine matrix transformation from image space to patient space in Matlab

痴心易碎 提交于 2019-11-30 04:05:38
From the nifti header its easy to get the affine matrix. However in the DICOM header there are lots of entries, but its unclear to me which entries describe the transformation of which parameter to which new space. I have found a tutorial which is quite detailed, but I cant find the entries they refer to. Also, that tutorial is written for Python, not Matlab. It lists these header entries: Entries needed: Image Position (0020,0032) Image Orientation (0020,0037) Pixel Spacing (0028,0030) I cant find these if I load the header with dicominfo() . Maybe they are vendor specific or maybe they are