当前位置: 首页>>代码示例>>Java>>正文


Java Image类代码示例

本文整理汇总了Java中com.google.appengine.api.images.Image的典型用法代码示例。如果您正苦于以下问题:Java Image类的具体用法?Java Image怎么用?Java Image使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Image类属于com.google.appengine.api.images包,在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: attemptGetImageMetadata

import com.google.appengine.api.images.Image; //导入依赖的package包/类
@Nullable private Image attemptGetImageMetadata(BlobstoreService blobstore, BlobInfo info) {
  if (info.getSize() == 0) {
    // Special case since it would lead to an IllegalArgumentException below.
    log.info("Empty attachment, can't get image metadata: " + info);
    return null;
  }
  final int readPortion = headerBytesUpperBound;
  BlobKey key = info.getBlobKey();
  byte[] data = blobstore.fetchData(key, 0, readPortion);
  try {
    Image img = ImagesServiceFactory.makeImage(data);
    // Force the image to be processed
    img.getWidth();
    img.getHeight();
    return img;
  } catch (RuntimeException e) {
    log.log(Level.SEVERE, "Problem getting image metadata; ignoring", e);
    return null;
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:21,代码来源:RawAttachmentService.java

示例2: convert

import com.google.appengine.api.images.Image; //导入依赖的package包/类
public byte[] convert(byte[] image, String destType, boolean reverse) {
	if (destType == null) {
		throw new IllegalArgumentException("dest type is null.");
	} else {
		destType = destType.toLowerCase();
	}

	ImagesService.OutputEncoding encoding = null;
	if ("png".equals(destType)) {
		encoding = OutputEncoding.PNG;
	} else if ("jpeg".equals(destType)) {
		encoding = OutputEncoding.JPEG;
	} else {
		throw new UnsupportedOperationException("unsupported image encoding: " + destType);
	}

	ImagesService imagesService = ImagesServiceFactory.getImagesService();
	Image bmp = ImagesServiceFactory.makeImage(image);

	Transform t = (reverse) ? ImagesServiceFactory.makeVerticalFlip() : ImagesServiceFactory.makeCompositeTransform();
	return imagesService.applyTransform(t, bmp, encoding).getImageData();
}
 
开发者ID:hidekatsu-izuno,项目名称:wmf2svg,代码行数:23,代码来源:ImageUtil.java

示例3: transformImage

import com.google.appengine.api.images.Image; //导入依赖的package包/类
private byte[] transformImage() {
    try {
        /*
         * This branch is covered in UiTests as the following method does
         * not behave the same in dev as in staging.
         * TODO: find a way to cover it in Action Tests.
         */
        Image newImage = getTransformedImage();
        return newImage.getImageData();
    } catch (RuntimeException re) {
        isError = true;
        statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_PROFILE_PICTURE_EDIT_FAILED,
                                           StatusMessageColor.DANGER));
        statusToAdmin = Const.ACTION_RESULT_FAILURE + " : Reading and transforming image failed."
                      + re.getMessage();
    }

    return new byte[0];
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:20,代码来源:StudentProfilePictureEditAction.java

示例4: testResizeAsync

import com.google.appengine.api.images.Image; //导入依赖的package包/类
@Test
public void testResizeAsync() throws IOException {
    InputSettings inputSettings = new InputSettings();
    OutputSettings outputSettings = new OutputSettings(OutputEncoding.PNG);

    Image originalImage = readImage(CAPEDWARF_PNG);
    Image resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(400, 286), originalImage));
    assertEquals(400, resizedImage.getWidth());
    assertEquals(286, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(300, 286), originalImage, outputSettings));
    assertEquals(300, resizedImage.getWidth());
    assertEquals(215, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(300, 286), originalImage, inputSettings, outputSettings));
    assertEquals(300, resizedImage.getWidth());
    assertEquals(215, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(300, 286), originalImage, OutputEncoding.JPEG));
    assertEquals(300, resizedImage.getWidth());
    assertEquals(215, resizedImage.getHeight());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:26,代码来源:TransformationsTest.java

示例5: testResizeWithCrop

import com.google.appengine.api.images.Image; //导入依赖的package包/类
@Test
public void testResizeWithCrop() throws IOException {
    int resizedWidth = 300;
    int resizedHeight = 200;
    Image originalImage = readImage(CAPEDWARF_PNG);
    Transform resize = ImagesServiceFactory.makeResize(resizedWidth, resizedHeight, 0.5f, 0.5f);
    Image resizedImage = imagesService.applyTransform(resize, originalImage);
    assertEquals(resizedWidth, resizedImage.getWidth());
    assertEquals(resizedHeight, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resize = ImagesServiceFactory.makeResize(resizedWidth, resizedHeight, 0.5, 0.5);
    resizedImage = imagesService.applyTransform(resize, originalImage);
    assertEquals(resizedWidth, resizedImage.getWidth());
    assertEquals(resizedHeight, resizedImage.getHeight());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:17,代码来源:TransformationsTest.java

示例6: applyAndVerify

import com.google.appengine.api.images.Image; //导入依赖的package包/类
private void applyAndVerify(String fname, Transform transform, ChkType chkType, OutputEncoding outType) throws IOException {
    int expectedWidth = -1;
    int expectedHeight = -1;

    Image image = readImage(fname);
    if (chkType == ChkType.FLIP) {
        expectedWidth = image.getWidth();
        expectedHeight = image.getHeight();
    } else if (chkType == ChkType.ROTATE) {
        expectedWidth = image.getHeight();
        expectedHeight = image.getWidth();
    } else if (chkType == ChkType.CROP) {
        expectedWidth = image.getWidth() / 2;
        expectedHeight = image.getHeight() / 2;
    }
    Image transImg = imagesService.applyTransform(transform, image, outType);
    assertEquals(expectedWidth, transImg.getWidth());
    assertEquals(expectedHeight, transImg.getHeight());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:20,代码来源:ImagesServiceTest.java

示例7: computeMetadata

import com.google.appengine.api.images.Image; //导入依赖的package包/类
private AttachmentMetadata computeMetadata(AttachmentId id, BlobKey blobKey) {
  try {
    BlobInfo info = blobInfoFactory.loadBlobInfo(blobKey);
    if (info != null) {
      JSONObject data = new JSONObject();
      data.put("size", info.getSize());
      String mimeType = info.getContentType();
      data.put("mimeType", mimeType);
      data.put("filename", info.getFilename());
      if (mimeType.startsWith("image/")) {
        Image img = attemptGetImageMetadata(blobstoreService, info);
        if (img != null) {
          JSONObject imgData = new JSONObject();
          imgData.put("width", img.getWidth());
          imgData.put("height", img.getHeight());
          data.put("image", imgData);

          JSONObject thumbData = new JSONObject();
          double ratio = resizeRatio(img);
          thumbData.put("width", ratio * img.getWidth());
          thumbData.put("height", ratio * img.getHeight());
          data.put("thumbnail", thumbData);
        }
      } else {
        // TODO(danilatos): Thumbnails for non-images
        log.info("Unimplemented: Thumbnails for non-images");
      }
      return new AttachmentMetadata(id, blobKey, data);
    }
    return null;
  } catch (JSONException e) {
    throw new Error(e);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:35,代码来源:RawAttachmentService.java

示例8: getResizedImageBytes

import com.google.appengine.api.images.Image; //导入依赖的package包/类
public byte[] getResizedImageBytes(BlobKey id, int width, int height) {
  log.info("Resizing " + id + " to " + width + "x" + height);
  // emptyImage is just a wrapper around the id.
  Image emptyImage = ImagesServiceFactory.makeImageFromBlob(id);
  Transform resize = ImagesServiceFactory.makeResize(width, height);
  return imagesService.applyTransform(resize, emptyImage).getImageData();
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:8,代码来源:RawAttachmentService.java

示例9: resizeRatio

import com.google.appengine.api.images.Image; //导入依赖的package包/类
private double resizeRatio(Image img) {
  double width = img.getWidth();
  double height = img.getHeight();
  double cmpRatio = (double) MAX_THUMB_WIDTH_PX / MAX_THUMB_HEIGHT_PX;
  double ratio = width / height;
  if (ratio > cmpRatio) {
    return Math.min(1, MAX_THUMB_WIDTH_PX / width);
  } else {
    return Math.min(1, MAX_THUMB_HEIGHT_PX / height);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:12,代码来源:RawAttachmentService.java

示例10: resizeImage

import com.google.appengine.api.images.Image; //导入依赖的package包/类
@Override
public byte[] resizeImage(byte[] imageBlob, int width, int height) {
  ImagesService imagesService = ImagesServiceFactory.getImagesService();
  Transform resize = ImagesServiceFactory.makeResize(width, height);

  Image oldImage = ImagesServiceFactory.makeImage(imageBlob);
  Image newImage = imagesService.applyTransform(resize, oldImage);

  imageBlob = newImage.getImageData();
  return imageBlob;
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:12,代码来源:ImageUtilImpl.java

示例11: read

import com.google.appengine.api.images.Image; //导入依赖的package包/类
public BufferedImage read(byte[] imageBytes) throws IOException {
	Image image = ImagesServiceFactory.makeImage(imageBytes);
	Transform identity = ImagesServiceFactory.makeRotate(0);
	OutputEncoding intermediateFormat = OutputEncoding.PNG;
	Image intermediateImage = imagesService.applyTransform(identity, image, intermediateFormat);
	byte[] intermediateBytes = intermediateImage.getImageData();
	return SANSELAN.getIO(imagesService).read(intermediateBytes);
}
 
开发者ID:mike10004,项目名称:appengine-imaging,代码行数:9,代码来源:ServiceImageIO.java

示例12: getTransformedImage

import com.google.appengine.api.images.Image; //导入依赖的package包/类
private Image getTransformedImage() {
    Assumption.assertNotNull(blobKey);

    Image oldImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
    CompositeTransform finalTransform = getCompositeTransformToApply();
    OutputSettings settings = new OutputSettings(ImagesService.OutputEncoding.PNG);

    return ImagesServiceFactory.getImagesService().applyTransform(finalTransform, oldImage, settings);
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:10,代码来源:StudentProfilePictureEditAction.java

示例13: testHorizontalFlip

import com.google.appengine.api.images.Image; //导入依赖的package包/类
@Test
public void testHorizontalFlip() throws IOException {
    Image image = readImage("capedwarf.png");
    Transform horizontalFlip = ImagesServiceFactory.makeHorizontalFlip();

    Image flippedImage = imagesService.applyTransform(horizontalFlip, image);

    assertNotNull(flippedImage);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:10,代码来源:IntegrationTest.java

示例14: assertTransformation

import com.google.appengine.api.images.Image; //导入依赖的package包/类
private void assertTransformation(Transform transform, String transformType) throws IOException {
    String expectedImage = "beach" + transformType + ".";
    for (OutputEncoding outType : OUTPUT_ENCODE) {
        String expectImageFile = expectedImage + outType.toString().toLowerCase();
        Image expected = readImage(expectImageFile);
        Image image = readImage(BEACH_TIF);
        Image transImg = imagesService.applyTransform(transform, image, outType);

        assertImages(transform, expected, transImg);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:12,代码来源:TifImageTest.java

示例15: testDefault

import com.google.appengine.api.images.Image; //导入依赖的package包/类
@Test
public void testDefault() throws IOException {
    // w - 200, h - 143
    Image originalImage = readImage(CAPEDWARF_PNG);
    Composite c1 = ImagesServiceFactory.makeComposite(originalImage, 0, 0, 1, Composite.Anchor.BOTTOM_LEFT);
    Image ci = imagesService.composite(newArrayList(c1), 200, 143, 0);
    assertImages(null, originalImage, ci);

}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:10,代码来源:CompositeTest.java


注:本文中的com.google.appengine.api.images.Image类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。