Поэтому я думаю, что ширина обоих моих изображений после их масштабирования с помощью этого метода AffineTransform должна составлять 1515 пикселей. исходная ширина первого — 1516, а второго — 1513. Я загружаю выходные изображения в редактор изображений и обрезаю черный цвет, чтобы проверить ширину содержимого и его 1514, а не 1515. И это происходит часто. в другом случае ширина должна была быть 1515, но когда я проверил ее, она была 1513.
что происходит??
кстати, холст буферизованного изображения намеренно большой при разрешении 2000x2000, поэтому вы можете увидеть, где на самом деле находится масштабированный контент.
вывод на консоль следующий:
average width is: 1514.5
original width 1 is: 1513
original width 2 is: 1516
scale-factor 1 is: 1.0009914077990747
scale-factor 2 is: 0.9990105540897097
WITHOUT rounding to nearest integer, new width of content1 should be: 1514.5
WITHOUT rounding to nearest integer,new width of content2 should be: 1514.5
when rounded to nearest integer, new width of content1 should be: 1515
when rounded to nearest integer,new width of content2 should be: 1515
а вот код
File f1 = new File("...");
File f2 = new File("...");
BufferedImage b1 = ImageIO.read(f1);
BufferedImage b2 = ImageIO.read(f2);
double average_width = (b1.getWidth()+b2.getWidth())/((double) 2);
double scale1 = average_width/b1.getWidth();
double scale2 = average_width/b2.getWidth();
System.out.println("average width is: "+average_width);
System.out.println("original width 1 is: "+b1.getWidth());
System.out.println("original width 2 is: "+b2.getWidth());
System.out.println("scale-factor 1 is: "+scale1);
System.out.println("scale-factor 2 is: "+scale2);
System.out.println("WITHOUT rounding to nearest integer, new width of content1 should be: "+(scale1 * b1.getWidth()));
System.out.println("WITHOUT rounding to nearest integer,new width of content2 should be: "+(scale2 * b2.getWidth()));
System.out.println("when rounded to nearest integer, new width of content1 should be: "+(Math.round(scale1 * b1.getWidth())));
System.out.println("when rounded to nearest integer,new width of content2 should be: "+(Math.round(scale2 * b2.getWidth())));
BufferedImage bo1 = new BufferedImage(2000, 2000, BufferedImage.TYPE_INT_RGB);
BufferedImage bo2 = new BufferedImage(2000, 2000, BufferedImage.TYPE_INT_RGB);
AffineTransform at = new AffineTransform();
at.scale(scale1, scale1);
AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
bo1 = atop.filter(b1, bo1);
File fo1 = new File("...");
ImageIO.write(bo1, "png", fo1);
Подробнее здесь: https://stackoverflow.com/questions/790 ... dimensions
Масштаб AffineTransform не дает правильных размеров? ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Кажется, что поворот оттенка -webkit-filter не дает правильных результатов в Chrome
Anonymous » » в форуме CSS - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-