- Timestamp:
- 01/06/14 11:21:12 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Picture.java
r643 r653 12 12 import java.awt.Stroke; 13 13 import java.awt.Toolkit; 14 import java.awt.geom.AffineTransform; 14 15 import java.awt.geom.Point2D; 16 import java.awt.image.BufferedImage; 15 17 import java.awt.image.CropImageFilter; 16 18 import java.awt.image.FilteredImageSource; … … 67 69 68 70 private Point _end = new Point(0, 0); 71 72 private double _rotate = 0; 69 73 70 74 private boolean _flipX = false; … … 139 143 _end.setLocation(_image.getWidth(null), _image.getHeight(null)); 140 144 size = size.trim(); 145 String sizeLower = size.toLowerCase(); 141 146 String[] values = size.split("\\s+"); 142 147 // Now get the cropping values if there are any … … 156 161 } 157 162 158 if(size .toLowerCase().contains("flipx")) {163 if(sizeLower.contains("flipx")) { 159 164 _flipX = true; 160 165 } 161 166 162 if(size .toLowerCase().contains("flipy")) {167 if(sizeLower.contains("flipy")) { 163 168 _flipY = true; 169 } 170 171 int index = sizeLower.indexOf("rotation="); 172 if(index != -1) { 173 int tmp = sizeLower.indexOf(" ", index); 174 String rotation; 175 if(tmp == -1) { 176 rotation = sizeLower.substring(index + "rotation=".length()); 177 } else { 178 rotation = sizeLower.substring(index + "rotation=".length(), index + tmp); 179 } 180 _rotate = Double.parseDouble(rotation); 164 181 } 165 182 … … 252 269 parseSize(); 253 270 } 254 _poly = new Polygon(); 271 272 Point[] ori = new Point[4]; 273 Point2D[] rot = new Point2D[4]; 274 Point centre = new Point(); 255 275 256 276 if (_cropStart == null || _cropEnd == null) { 257 277 int width = getWidth(); 258 278 int height = getHeight(); 279 280 centre.x = _source.getX() + width / 2; 281 centre.y = _source.getY() + height / 2; 259 282 260 283 int xdiff = -MARGIN_RIGHT; // -getLeftMargin(); 261 284 262 285 // extra pixel around the image so the highlighting is visible 263 _poly.addPoint(_source.getX() + 1 + xdiff, _source.getY() - 1); 264 _poly.addPoint(_source.getX() + width, _source.getY() - 1); 265 _poly.addPoint(_source.getX() + width, _source.getY() + height); 266 _poly.addPoint(_source.getX() + 1 + xdiff, _source.getY() + height); 286 // _poly.addPoint(_source.getX() + 1 + xdiff, _source.getY() - 1); 287 // _poly.addPoint(_source.getX() + width, _source.getY() - 1); 288 // _poly.addPoint(_source.getX() + width, _source.getY() + height); 289 // _poly.addPoint(_source.getX() + 1 + xdiff, _source.getY() + height); 290 291 ori[0] = new Point(_source.getX() + 1 + xdiff, _source.getY() - 1); 292 ori[1] = new Point(_source.getX() + width, _source.getY() - 1); 293 ori[2] = new Point(_source.getX() + width, _source.getY() + height); 294 ori[3] = new Point(_source.getX() + 1 + xdiff, _source.getY() + height); 295 267 296 } else { 268 297 Point topLeft = getTopLeftCrop(); 269 298 Point bottomRight = getBottomRightCrop(); 299 300 centre.x = _source.getX() + (bottomRight.x - topLeft.x) / 2; 301 centre.y = _source.getY() + (bottomRight.y - topLeft.y) / 2; 302 270 303 Rectangle clip = new Rectangle(topLeft.x + _source.getX(), 271 304 topLeft.y + _source.getY(), bottomRight.x - topLeft.x, 272 305 bottomRight.y - topLeft.y).getBounds(); 273 _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMinY() - 1); 274 _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMaxY()); 275 _poly.addPoint((int) clip.getMaxX(), (int) clip.getMaxY()); 276 _poly.addPoint((int) clip.getMaxX(), (int) clip.getMinY() - 1); 277 306 // _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMinY() - 1); 307 // _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMaxY()); 308 // _poly.addPoint((int) clip.getMaxX(), (int) clip.getMaxY()); 309 // _poly.addPoint((int) clip.getMaxX(), (int) clip.getMinY() - 1); 310 311 ori[0] = new Point((int) clip.getMinX() - 1, (int) clip.getMinY() - 1); 312 ori[1] = new Point((int) clip.getMinX() - 1, (int) clip.getMaxY()); 313 ori[2] = new Point((int) clip.getMaxX(), (int) clip.getMaxY()); 314 ori[3] = new Point((int) clip.getMaxX(), (int) clip.getMinY() - 1); 315 316 } 317 318 AffineTransform.getRotateInstance(_rotate, centre.x, centre.y).transform(ori, 0, rot, 0, 4); 319 320 _poly = new Polygon(); 321 for(Point2D p : rot) { 322 _poly.addPoint((int)p.getX(), (int)p.getY()); 278 323 } 279 324 } … … 339 384 int dY2 = _source.getY() + getHeight(); 340 385 386 BufferedImage tmp = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); 387 Graphics2D g2d = tmp.createGraphics(); 388 int offX = (tmp.getWidth() - getWidth()) / 2; 389 int offY = (tmp.getHeight() - getHeight()) / 2; 390 391 // g2d.rotate(rotate, tmp.getWidth() / 2, tmp.getHeight() / 2); 341 392 342 393 int cropStartX = _start.x; … … 368 419 } 369 420 370 System.out.println(_flipX + " " + _flipY);371 372 421 int sx = _flipX ? cropEndX : cropStartX; 373 422 int ex = _flipX ? cropStartX : cropEndX; 374 423 int sy = _flipY ? cropEndY : cropStartY; 375 424 int ey = _flipY ? cropStartY : cropEndY; 376 g .drawImage(_image, x, y, endX, endY, sx, sy, ex, ey, _imageObserver);425 g2d.drawImage(_image, x - dX1 + offX, y - dY1 + offY, endX - dX1 + offX, endY - dY1 + offY, sx, sy, ex, ey, null); 377 426 378 427 cropStartY = 0; … … 387 436 x = endX; 388 437 } 438 439 AffineTransform at = new AffineTransform(); 440 at.translate(dX1, dY1); 441 at.rotate(_rotate, tmp.getWidth() / 2, tmp.getHeight() / 2); 442 g.drawImage(tmp, at, _imageObserver); 443 // g.drawImage(tmp, dX1, dY1, dX2, dY2, 0, 0, tmp.getWidth(), tmp.getHeight(), _imageObserver); 389 444 } 390 445 … … 724 779 newText.append(" flipY"); 725 780 } 781 if(Double.compare(_rotate, 0) != 0) { 782 newText.append(" rotation=" + _rotate); 783 } 726 784 727 785 _source.setText(newText.toString()); … … 776 834 return _flipY; 777 835 } 836 837 public void setRotate(double rotate) { 838 _rotate = rotate; 839 updateSource(); 840 updatePolygon(); 841 } 842 843 public double getRotate() { 844 return _rotate; 845 } 778 846 779 847 }
Note:
See TracChangeset
for help on using the changeset viewer.