本文整理汇总了Java中org.robovm.apple.uikit.UIImage.getCGImage方法的典型用法代码示例。如果您正苦于以下问题:Java UIImage.getCGImage方法的具体用法?Java UIImage.getCGImage怎么用?Java UIImage.getCGImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.robovm.apple.uikit.UIImage
的用法示例。
在下文中一共展示了UIImage.getCGImage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAlpha
import org.robovm.apple.uikit.UIImage; //导入方法依赖的package包/类
/**
*
* @param image
* @return a copy of the given image, adding an alpha channel if it doesn't
* already have one
*/
public static UIImage addAlpha(UIImage image) {
if (hasAlpha(image)) {
return image;
}
CGImage i = image.getCGImage();
long width = i.getWidth();
long height = i.getHeight();
// The bitsPerComponent and bitmapInfo values are hard-coded to prevent
// an "unsupported parameter combination" error
CGBitmapContext offscreenContext = CGBitmapContext.create(width, height, 8, 0, i.getColorSpace(),
new CGBitmapInfo(CGBitmapInfo.ByteOrderDefault.value() | CGImageAlphaInfo.PremultipliedFirst.value())); // TODO
// could
// be
// improved
// Draw the image into the context and retrieve the new image, which
// will now have an alpha layer
offscreenContext.drawImage(new CGRect(0, 0, width, height), i);
CGImage ia = offscreenContext.toImage();
UIImage alphaImage = new UIImage(ia);
return alphaImage;
}
示例2: resize
import org.robovm.apple.uikit.UIImage; //导入方法依赖的package包/类
/**
*
* @param image
* @param newSize
* @param transform
* @param transpose
* @param quality
* @return a copy of the image that has been transformed using the given
* affine transform and scaled to the new size The new image's
* orientation will be UIImageOrientationUp, regardless of the
* current image's orientation If the new size is not integral, it
* will be rounded up
*/
private static UIImage resize(UIImage image, CGSize newSize, CGAffineTransform transform, boolean transpose,
CGInterpolationQuality quality) {
CGRect newRect = new CGRect(0, 0, newSize.getWidth(), newSize.getHeight()).integral();
CGRect transposedRect = new CGRect(0, 0, newRect.getSize().getHeight(), newRect.getSize().getWidth());
CGImage i = image.getCGImage();
// Build a context that's the same dimensions as the new size
CGBitmapContext bitmap = CGBitmapContext.create((long) newRect.getSize().getWidth(), (long) newRect.getSize()
.getHeight(), i.getBitsPerComponent(), 0, i.getColorSpace(), i.getBitmapInfo());
// Rotate and/or flip the image if required by its orientation
bitmap.concatCTM(transform);
// Set the quality level to use when rescaling
bitmap.setInterpolationQuality(quality);
// Draw into the context; this scales the image
bitmap.drawImage(transpose ? transposedRect : newRect, i);
// Get the resized image from the context and a UIImage
CGImage ni = bitmap.toImage();
UIImage newImage = new UIImage(ni);
return newImage;
}
示例3: addTransparentBorder
import org.robovm.apple.uikit.UIImage; //导入方法依赖的package包/类
/**
*
* @param image
* @param borderSize
* @return a copy of the image with a transparent border of the given size
* added around its edges. If the image has no alpha layer, one will
* be added to it.
*/
public static UIImage addTransparentBorder(UIImage image, int borderSize) {
// If the image does not have an alpha layer, add one
image = addAlpha(image);
CGRect newRect = new CGRect(0, 0, image.getSize().getWidth() + borderSize * 2, image.getSize().getHeight()
+ borderSize * 2);
CGImage i = image.getCGImage();
// Build a context that's the same dimensions as the new size
CGBitmapContext bitmap = CGBitmapContext.create((long) newRect.getSize().getWidth(), (long) newRect.getSize()
.getHeight(), i.getBitsPerComponent(), 0, i.getColorSpace(), i.getBitmapInfo());
// Draw the image in the center of the context, leaving a gap around the
// edges
CGRect imageLocation = new CGRect(borderSize, borderSize, image.getSize().getWidth(), image.getSize()
.getHeight());
bitmap.drawImage(imageLocation, i);
CGImage borderImage = bitmap.toImage();
// Create a mask to make the border transparent, and combine it with the
// image
CGImage maskImage = newBorderMask(borderSize, newRect.getSize());
CGImage tbi = CGImage.createWithMask(borderImage, maskImage);
UIImage transparentBorderImage = new UIImage(tbi);
return transparentBorderImage;
}
示例4: createRoundedCornerImage
import org.robovm.apple.uikit.UIImage; //导入方法依赖的package包/类
/**
* Creates a copy of this image with rounded corners If borderSize is
* non-zero, a transparent border of the given size will also be added
* Original author: Björn Sållarp. Used with permission. See:
* http://blog.sallarp.com/iphone-uiimage-round-corners/
*
* @param image
* @param cornerSize
* @param borderSize
* @return
*/
private static UIImage createRoundedCornerImage(UIImage image, int cornerSize, int borderSize) {
// If the image does not have an alpha layer, add one
image = addAlpha(image);
// Build a context that's the same dimensions as the new size
CGImage i = image.getCGImage();
CGBitmapContext context = CGBitmapContext.create((long) image.getSize().getWidth(), (long) image.getSize()
.getHeight(), i.getBitsPerComponent(), 0, i.getColorSpace(), i.getBitmapInfo());
// Create a clipping path with rounded corners
context.beginPath();
addRoundedRectToPath(new CGRect(borderSize, borderSize, image.getSize().getWidth() - borderSize * 2, image
.getSize().getHeight() - borderSize * 2)
, context, cornerSize, cornerSize);
context.closePath();
context.clip();
// Draw the image to the context; the clipping path will make anything
// outside the rounded rect transparent
context.drawImage(new CGRect(0, 0, image.getSize().getWidth(), image.getSize().getHeight()), i);
// Create a CGImage from the context
CGImage clippedImage = context.toImage();
// Create a UIImage from the CGImage
UIImage roundedImage = new UIImage(clippedImage);
return roundedImage;
}
示例5: toData
import org.robovm.apple.uikit.UIImage; //导入方法依赖的package包/类
private ImageImpl.Data toData (Scale scale, UIImage image) {
CGImage bitmap = image.getCGImage();
return new ImageImpl.Data(scale, bitmap, (int)bitmap.getWidth(), (int)bitmap.getHeight());
}
示例6: transform
import org.robovm.apple.uikit.UIImage; //导入方法依赖的package包/类
@Override public Image transform(BitmapTransformer xform) {
UIImage ximage = new UIImage(((RoboBitmapTransformer) xform).transform(cgImage()));
return new RoboImage(gfx, scale, ximage.getCGImage(), source);
}
示例7: getCGImage
import org.robovm.apple.uikit.UIImage; //导入方法依赖的package包/类
private static CGImage getCGImage (String name) {
int ix = name.lastIndexOf('/');
if (ix != -1) name = name.substring(ix);
UIImage uiImage = UIImage.getImage(name);
return uiImage.getCGImage();
}