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


Java Image.getWidth方法代码示例

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


在下文中一共展示了Image.getWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: setGalleryAppImage

import com.google.appengine.api.images.Image; //导入方法依赖的package包/类
/**
 * when an app is published/updated, we need to move the image
 * that was temporarily uploaded into projects/projectid/image
 * into the gallery image
 * @param app gallery app
 */
private void setGalleryAppImage(GalleryApp app) {
  // best thing would be if GCS has a mv op, we can just do that.
  // don't think that is there, though, so for now read one and write to other
  // First, read the file from projects name
  boolean lockForRead = false;
  //String projectImageKey = app.getProjectImageKey();
  GallerySettings settings = loadGallerySettings();
  String projectImageKey = settings.getProjectImageKey(app.getProjectId());
  try {
    GcsService gcsService = GcsServiceFactory.createGcsService();
    //GcsFilename filename = new GcsFilename(GalleryApp.GALLERYBUCKET, projectImageKey);
    GcsFilename filename = new GcsFilename(settings.getBucket(), projectImageKey);
    GcsInputChannel readChannel = gcsService.openReadChannel(filename, 0);
    InputStream gcsis = Channels.newInputStream(readChannel);

    byte[] buffer = new byte[8000];
    int bytesRead = 0;
    ByteArrayOutputStream bao = new ByteArrayOutputStream();

    while ((bytesRead = gcsis.read(buffer)) != -1) {
      bao.write(buffer, 0, bytesRead);
    }
    // close the project image file
    readChannel.close();

    // if image is greater than 200 X 200, it will be scaled (200 X 200).
    // otherwise, it will be stored as origin.
    byte[] oldImageData = bao.toByteArray();
    byte[] newImageData;
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    Image oldImage = ImagesServiceFactory.makeImage(oldImageData);
    //if image size is too big, scale it to a smaller size.
    if(oldImage.getWidth() > 200 && oldImage.getHeight() > 200){
        Transform resize = ImagesServiceFactory.makeResize(200, 200);
        Image newImage = imagesService.applyTransform(resize, oldImage);
        newImageData = newImage.getImageData();
    }else{
        newImageData = oldImageData;
    }

    // set up the cloud file (options)
    // After publish, copy the /projects/projectId image into /apps/appId
    //String galleryKey = app.getImageKey();
    String galleryKey = settings.getImageKey(app.getGalleryAppId());

    //GcsFilename outfilename = new GcsFilename(GalleryApp.GALLERYBUCKET, galleryKey);
    GcsFilename outfilename = new GcsFilename(settings.getBucket(), galleryKey);
    GcsFileOptions options = new GcsFileOptions.Builder().mimeType("image/jpeg")
        .acl("public-read").cacheControl("no-cache").build();
    GcsOutputChannel writeChannel = gcsService.createOrReplace(outfilename, options);
    writeChannel.write(ByteBuffer.wrap(newImageData));

    // Now finalize
    writeChannel.close();

  } catch (IOException e) {
    // TODO Auto-generated catch block
    LOG.log(Level.INFO, "FAILED WRITING IMAGE TO GCS");
    e.printStackTrace();
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:68,代码来源:GalleryServiceImpl.java


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