本文整理汇总了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;
}
}
示例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();
}
示例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];
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}