當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageReader.getWidth方法代碼示例

本文整理匯總了Java中javax.imageio.ImageReader.getWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageReader.getWidth方法的具體用法?Java ImageReader.getWidth怎麽用?Java ImageReader.getWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.imageio.ImageReader的用法示例。


在下文中一共展示了ImageReader.getWidth方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPictureSize

import javax.imageio.ImageReader; //導入方法依賴的package包/類
/**
 * Extracts the picture size of a given Image.
 *
 * @param path Path to the image
 * @return Image-size in pixel
 * @throws IOException Throws exception when file-access fails
 */
public static Dimension getPictureSize(final String path) throws IOException {
    try (ImageInputStream in = ImageIO.createImageInputStream(path)) {
        final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
        if (readers.hasNext()) {
            ImageReader reader = readers.next();
            try {
                reader.setInput(in);
                return new Dimension(reader.getWidth(0), reader.getHeight(0));
            } finally {
                reader.dispose();
            }
        }
        return null;
    }
}
 
開發者ID:ProjectIndoor,項目名稱:projectindoorweb,代碼行數:23,代碼來源:TransformationHelper.java

示例2: run

import javax.imageio.ImageReader; //導入方法依賴的package包/類
/**
 * Gets the size of an image.
 *
 * @param name the image name
 * @param in the input stream
 * @return the size of the image
 *
 * @throws BrokenImageException if the image is faulty
 * @throws UnrecognizedImageTypeException if the image type is unknown
 * @throws IOException if reading the image goes wrong
 */
public Dimension run(String name, InputStream in) throws IOException {
  final ImageInputStream stream = new MemoryCacheImageInputStream(in);

  final Iterator<ImageReader> i = ImageIO.getImageReaders(stream);
  if (!i.hasNext()) throw new UnrecognizedImageTypeException(name);

  final ImageReader reader = i.next();
  try {
    reader.setInput(stream);
    return new Dimension(reader.getWidth(0), reader.getHeight(0));
  }
  finally {
    reader.dispose();
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:27,代碼來源:ImageIOImageLoader.java

示例3: cut

import javax.imageio.ImageReader; //導入方法依賴的package包/類
public static BufferedImage cut(String format, InputStream src, int x, int y, int w, int h) throws IOException {
	Iterator<ImageReader> iterator = ImageIO.getImageReadersByFormatName(format);
	ImageReader reader = (ImageReader) iterator.next();
	ImageInputStream iis = ImageIO.createImageInputStream(src);
	reader.setInput(iis, true);
	ImageReadParam param = reader.getDefaultReadParam();
	int imgWidth = reader.getWidth(0);
	int imgHeight = reader.getHeight(0);
	if (x + w > imgWidth) {
		w = imgWidth - x;
	}
	if (y + h > imgHeight) {
		h = imgHeight - y;
	}
	Rectangle rect = new Rectangle(x, y, w, h);
	param.setSourceRegion(rect);
	BufferedImage bi = reader.read(0, param);
	return bi;
}
 
開發者ID:szsucok,項目名稱:sucok-framework,代碼行數:20,代碼來源:ImageSizeUtils.java

示例4: getImageDimensions

import javax.imageio.ImageReader; //導入方法依賴的package包/類
/**
 * getImageDimensions.
 *
 * @param resourceFile File
 * @return Dimension
 */
static Dimension getImageDimensions(final File resourceFile) {
    registerAllServicesProviders();

    try (ImageInputStream in = createImageInputStream(resourceFile)) {
        final Iterator<ImageReader> readers = getImageReaders(in);
        if (readers.hasNext()) {
            final ImageReader reader = readers.next();
            try {
                reader.setInput(in);
                return new Dimension(reader.getWidth(0), reader.getHeight(0));
            } finally {
                reader.dispose();
            }
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:ubleipzig,項目名稱:iiif-producer,代碼行數:26,代碼來源:JAI.java

示例5: getSize

import javax.imageio.ImageReader; //導入方法依賴的package包/類
/**
 * 獲取圖片的尺寸
 * 
 * @param extName
 *            後綴名
 * @param imgContent
 *            圖片內容
 * @return 數組:[寬,高]
 */
public int[] getSize(String extName, byte[] imgContent) {
	if (imgContent == null || WakaUtils.string.isEmpty(extName)) {
		throw new ZhhrUtilException("獲取文件大小失敗!入參為空");
	}
	// 字節轉圖片流
	try (ImageInputStream imgInputStream = byteArrayStreamToImageInputStream(imgContent)) {
		// 取得圖片讀取器
		ImageReader imgReader = getImageReader(extName);

		// 把文件流加載到圖片讀取器中
		imgReader.setInput(imgInputStream, true);

		return new int[] { imgReader.getWidth(0), imgReader.getHeight(0) };
	} catch (IOException e) {
		throw new ZhhrUtilException(e.getMessage(), e);
	}
}
 
開發者ID:wooui,項目名稱:springboot-training,代碼行數:27,代碼來源:ImageUtil.java

示例6: testUpdateIcon

import javax.imageio.ImageReader; //導入方法依賴的package包/類
@Test
public void testUpdateIcon() throws IOException {
    final LinkedMultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
    multipartData.add("icon", new InputStreamResource(getClass().getResourceAsStream("test-image.png")));

    final ResponseEntity<Connector> updated = post("/api/v1/connectors/twitter/icon",
        multipartData, Connector.class, tokenRule.validToken(), HttpStatus.OK,
        multipartHeaders());

    assertThat(updated.getBody().getId()).isPresent();
    assertThat(updated.getBody().getIcon()).isNotBlank().startsWith("db:");

    final ResponseEntity<ByteArrayResource> got = get("/api/v1/connectors/twitter/icon", ByteArrayResource.class);
    assertThat(got.getHeaders().getFirst("Content-Type")).isEqualTo("image/png");

    try (ImageInputStream iis = ImageIO.createImageInputStream(got.getBody().getInputStream());) {
        final Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
        if (readers.hasNext()) {
            final ImageReader reader = readers.next();
            try {
                reader.setInput(iis);
                final Dimension dimensions = new Dimension(reader.getWidth(0), reader.getHeight(0));
                assertThat(dimensions.getHeight()).isEqualTo(106d).as("Wrong image height");
                assertThat(dimensions.getWidth()).isEqualTo(106d).as("Wrong image width");
            } finally {
                reader.dispose();
            }
        }
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:31,代碼來源:ConnectorsITCase.java

示例7: connectorIconShouldHaveCorrectContentType

import javax.imageio.ImageReader; //導入方法依賴的package包/類
@Test
public void connectorIconShouldHaveCorrectContentType() throws IOException {
    try (MockWebServer mockWebServer = new MockWebServer(); final Buffer resultBuffer = new Buffer()) {
        mockWebServer.start();

        resultBuffer.writeAll(Okio.source(getClass().getResourceAsStream("test-image.png")));

        mockWebServer.enqueue(new MockResponse().setHeader(CONTENT_TYPE, "image/png").setBody(resultBuffer));

        final Connector connector = new Connector.Builder().id("connector-id").icon(mockWebServer.url("/u/23079786").toString())
            .build();
        when(dataManager.fetch(Connector.class, "connector-id")).thenReturn(connector);
        when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(Collections.emptyList()));

        final Response response = handler.getConnectorIcon("connector-id").get();

        assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK).as("Wrong status code");
        assertThat(response.getHeaderString(CONTENT_TYPE)).isEqualTo("image/png").as("Wrong content type");
        assertThat(response.getHeaderString(CONTENT_LENGTH)).isEqualTo("2018").as("Wrong content length");

        final StreamingOutput so = (StreamingOutput) response.getEntity();
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try (BufferedSink sink = Okio.buffer(Okio.sink(bos)); BufferedSource source = new Buffer();
            ImageInputStream iis = ImageIO.createImageInputStream(source.inputStream());) {
            so.write(sink.outputStream());
            source.readAll(sink);
            final Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
            if (readers.hasNext()) {
                final ImageReader reader = readers.next();
                try {
                    reader.setInput(iis);
                    final Dimension dimensions = new Dimension(reader.getWidth(0), reader.getHeight(0));
                    assertThat(dimensions.getHeight()).isEqualTo(106d).as("Wrong image height");
                    assertThat(dimensions.getWidth()).isEqualTo(106d).as("Wrong image width");
                } finally {
                    reader.dispose();
                }
            }
        }
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:42,代碼來源:ConnectorHandlerTest.java

示例8: testUpdateConnectorAndIconViaMultipart

import javax.imageio.ImageReader; //導入方法依賴的package包/類
@Test
public void testUpdateConnectorAndIconViaMultipart() throws IOException {
    final Connector initialConnector = dataManager.fetch(Connector.class, "twitter");

    assertThat(initialConnector.getIcon()).isNotBlank().doesNotStartWith("db:");

    final Connector connectorWithNewdescription = new Connector.Builder().createFrom(initialConnector)
        .description("Updated!").build();

    final LinkedMultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
    multipartData.add("connector", connectorWithNewdescription);
    multipartData.add("icon", new InputStreamResource(getClass().getResourceAsStream("test-image.png")));

    final ResponseEntity<Void> updated = put("/api/v1/connectors/twitter",
        multipartData, Void.class, tokenRule.validToken(), HttpStatus.NO_CONTENT,
        multipartHeaders());

    final ResponseEntity<Connector> updatedConnector = get("/api/v1/connectors/twitter", Connector.class);

    assertThat(updatedConnector.getBody().getId()).isPresent();
    assertThat(updatedConnector.getBody().getIcon()).isNotBlank().startsWith("db:");
    assertThat(updatedConnector.getBody().getDescription()).isNotBlank().isEqualTo("Updated!");

    final ResponseEntity<ByteArrayResource> got = get("/api/v1/connectors/twitter/icon", ByteArrayResource.class);
    assertThat(got.getHeaders().getFirst("Content-Type")).isEqualTo("image/png");

    try (ImageInputStream iis = ImageIO.createImageInputStream(got.getBody().getInputStream());) {
        final Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
        if (readers.hasNext()) {
            final ImageReader reader = readers.next();
            try {
                reader.setInput(iis);
                final Dimension dimensions = new Dimension(reader.getWidth(0), reader.getHeight(0));
                assertThat(dimensions.getHeight()).isEqualTo(106d).as("Wrong image height");
                assertThat(dimensions.getWidth()).isEqualTo(106d).as("Wrong image width");
            } finally {
                reader.dispose();
            }
        }
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:42,代碼來源:ConnectorsITCase.java

示例9: mosaic

import javax.imageio.ImageReader; //導入方法依賴的package包/類
public static BufferedImage mosaic(String input, int width, int height) throws IOException {

		// ��ȡͼƬ��ʽ
		final String formatname = GetPostfix.fromFilepath(input);

		// ͼƬ�������
		final ImageReader reader = File2ImageReader.F2IR(input);
		final int oriwidth = reader.getWidth(0);
		final int oriheight = reader.getHeight(0);

		return null;

	}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:14,代碼來源:ScaleScaler.java


注:本文中的javax.imageio.ImageReader.getWidth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。