我正在尝试调整大小并将图片裁剪到Google App引擎中以创建缩略图
我希望能够创建任意大小的200x150拇指。
这是我目前使用的代码,现在我需要裁剪它,因此它不会超过200x150:
Image oldImage = ImagesServiceFactory.makeImage(picture);
//Create the Image Service Factory and the Resize Transform
ImagesService imagesService = ImagesServiceFactory.getImagesService();
int w = 0;
int h = 0;
if (oldImage.getWidth() > oldImage.getHeight()) {
w = 1000;
h = height;
} else {
h = 1000;
w = width;
}
Transform resize = ImagesServiceFactory.makeResize(w, h);
//Resize The Image using the transform created above
Image resizedImage = imagesService.applyTransform(resize, oldImage);
Transform crop = ImagesServiceFactory.makeCrop(0.0, 0.0, width / resizedImage.getHeight(), height / resizedImage.getHeight());
Image cropedImage = imagesService.applyTransform(crop, resizedImage);
//Serve the newly transformed image
return cropedImage.getImageData();
谢谢!
答案 0 :(得分:2)
这可以调整大小并裁剪只存储一张图像进行调整大小并动态裁剪。因为我对这个解决方案非常满意,所以我希望它也适合你。
答案 1 :(得分:0)
您的oldImage
宽度小于200px。