本文整理汇总了Java中com.google.appengine.api.images.Image.getImageData方法的典型用法代码示例。如果您正苦于以下问题:Java Image.getImageData方法的具体用法?Java Image.getImageData怎么用?Java Image.getImageData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.images.Image
的用法示例。
在下文中一共展示了Image.getImageData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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];
}
示例2: 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;
}
示例3: 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);
}
示例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();
}
}
示例5: convertFormatWithService
import com.google.appengine.api.images.Image; //导入方法依赖的package包/类
public static byte[] convertFormatWithService(ImagesService imagesService, byte[] inputImageBytes, OutputEncoding outputFormat) {
Transform identity = ImagesServiceFactory.makeRotate(0);
Image image = ImagesServiceFactory.makeImage(inputImageBytes);
Image outputImage = imagesService.applyTransform(identity, image, outputFormat);
return outputImage.getImageData();
}
示例6: uploadImagetoGcs
import com.google.appengine.api.images.Image; //导入方法依赖的package包/类
public static Boolean uploadImagetoGcs(BlobAccess blobAccess, Image image) throws IOException {
HttpURLConnection conn = null;
boolean succeeded;
try {
URL url = new URL(blobAccess.getShortLivedUrl());
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("PUT");
if (blobAccess != null && blobAccess.getMandatoryHeaders() != null) {
for (String headerKeyValuePair : blobAccess.getMandatoryHeaders().split("\n")) {
String[] keyValue = headerKeyValuePair.split(":");
conn.setRequestProperty(keyValue[0], keyValue[1]);
}
}
conn.connect();
BufferedOutputStream bos = new BufferedOutputStream(conn.getOutputStream());
InputStream bis = new BufferedInputStream(new ByteArrayInputStream(image.getImageData()));
byte[] buffer = new byte[BUFFER_SIZE_FOR_UPLOAD];
int bytesRead;
while ((bytesRead = bis.read(buffer)) > 0) {
bos.write(buffer, 0, bytesRead);
bos.flush();
}
bos.close();
InputStream resultStream;
int responseCode = conn.getResponseCode();
succeeded = responseCode >= HttpURLConnection.HTTP_OK && responseCode < HttpURLConnection.HTTP_MULT_CHOICE;
if (succeeded) {
resultStream = conn.getInputStream();
String resultMessage = getStringFromInputStream(resultStream);
logger.info(resultMessage);
} else {
resultStream = conn.getErrorStream();
String errorMessage = getStringFromInputStream(resultStream);
logger.severe(errorMessage);
}
} finally {
if (conn != null) {
conn.disconnect();
}
}
return succeeded;
}
示例7: doGet
import com.google.appengine.api.images.Image; //导入方法依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
BlobKey blobKey = new BlobKey(req.getParameter("key"));
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(MediaObject.class, "blob == blobParam");
query.declareImports("import " +
"com.google.appengine.api.blobstore.BlobKey");
query.declareParameters("BlobKey blobParam");
List<MediaObject> results = (List<MediaObject>) query.execute(blobKey);
if (results.isEmpty()) {
resp.sendRedirect("/?error=" +
URLEncoder.encode("BlobKey does not exist", "UTF-8"));
return;
}
MediaObject result = results.get(0);
if (!result.isPublic()) {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (!result.getOwner().equals(user)) {
resp.sendRedirect("/?error=" +
URLEncoder.encode("Not authorized to access", "UTF-8"));
return;
}
}
String rotation = req.getParameter("rotate");
if (rotation != null && !"".equals(rotation) && !"null".equals(rotation)) {
int degrees = Integer.parseInt(rotation);
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image image = ImagesServiceFactory.makeImageFromBlob(blobKey);
Transform rotate = ImagesServiceFactory.makeRotate(degrees);
Image newImage = imagesService.applyTransform(rotate, image);
byte[] imgbyte = newImage.getImageData();
resp.setContentType(result.getContentType());
resp.getOutputStream().write(imgbyte);
return;
}
blobstoreService.serve(blobKey, resp);
}