本文整理汇总了C++中CGImageGetHeight函数的典型用法代码示例。如果您正苦于以下问题:C++ CGImageGetHeight函数的具体用法?C++ CGImageGetHeight怎么用?C++ CGImageGetHeight使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CGImageGetHeight函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copyImageData_color
static void copyImageData_color( CGImageRef imageRef, cv::Mat &image )
{
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
image = cv::Mat( cv::Size( width, height ), CV_8UC3 );
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = image.data;
size_t bytesPerPixel = 4;
size_t bytesPerRow = bytesPerPixel * width;
size_t bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
}
示例2: frameCount
void BitmapImage::drawFrameMatchingSourceSize(GraphicsContext* ctxt, const FloatRect& dstRect, const IntSize& srcSize, ColorSpace styleColorSpace, CompositeOperator compositeOp)
{
size_t frames = frameCount();
for (size_t i = 0; i < frames; ++i) {
CGImageRef image = frameAtIndex(i);
if (CGImageGetHeight(image) == static_cast<size_t>(srcSize.height()) && CGImageGetWidth(image) == static_cast<size_t>(srcSize.width())) {
size_t currentFrame = m_currentFrame;
m_currentFrame = i;
draw(ctxt, dstRect, FloatRect(0.0f, 0.0f, srcSize.width(), srcSize.height()), styleColorSpace, compositeOp);
m_currentFrame = currentFrame;
return;
}
}
// No image of the correct size was found, fallback to drawing the current frame
IntSize imageSize = BitmapImage::size();
draw(ctxt, dstRect, FloatRect(0.0f, 0.0f, imageSize.width(), imageSize.height()), styleColorSpace, compositeOp);
}
示例3: Image
BitmapImage::BitmapImage(CGImageRef cgImage, ImageObserver* observer)
: Image(observer)
, m_currentFrame(0)
, m_frames(0)
, m_repetitionCount(cAnimationNone)
, m_repetitionCountStatus(Unknown)
, m_repetitionsComplete(0)
, m_decodedSize(0)
, m_decodedPropertiesSize(0)
, m_frameCount(1)
, m_isSolidColor(false)
, m_checkedForSolidColor(false)
, m_animationFinished(true)
, m_allDataReceived(true)
, m_haveSize(true)
, m_sizeAvailable(true)
, m_haveFrameCount(true)
{
CGFloat width = CGImageGetWidth(cgImage);
CGFloat height = CGImageGetHeight(cgImage);
m_decodedSize = width * height * 4;
m_size = IntSize(width, height);
// Since we don't have a decoder, we can't figure out the image orientation.
// Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0.
m_sizeRespectingOrientation = IntSize(width, height);
#if PLATFORM(IOS)
m_originalSize = IntSize(width, height);
m_originalSizeRespectingOrientation = IntSize(width, height);
#endif
m_frames.grow(1);
m_frames[0].m_frame = CGImageRetain(cgImage);
m_frames[0].m_hasAlpha = true;
m_frames[0].m_haveMetadata = true;
#if PLATFORM(IOS)
m_frames[0].m_scale = 1;
#endif
checkForSolidColor();
}
示例4: CGImageCreateWithPNGDataProvider
CGImageRef nglImageCGCodec::ReadInfo(nglIStream* pIStream)
{
mpIStream = pIStream;
CGImageRef pCGImage = NULL;
const bool shouldInterpolate = true;
if (ProbePNG(pIStream))
{
pCGImage = CGImageCreateWithPNGDataProvider(mpCGProvider, NULL, shouldInterpolate, kCGRenderingIntentDefault);
}
else if (ProbeJPEG(pIStream))
{
pCGImage = CGImageCreateWithJPEGDataProvider(mpCGProvider, NULL, false, kCGRenderingIntentDefault);
}
if (pCGImage)
{
nglImageInfo info;
info.mWidth = CGImageGetWidth(pCGImage);
info.mHeight = CGImageGetHeight(pCGImage);
if (info.mWidth > 0 && info.mHeight > 0)
{
info.mBufferFormat = eImageFormatRaw;
info.mPixelFormat = eImagePixelRGBA;
info.mBytesPerPixel = 4;
info.mBitDepth = 8 * info.mBytesPerPixel;
info.mBytesPerLine = info.mWidth * info.mBytesPerPixel;
info.mPreMultAlpha = true;
info.mpBuffer = NULL;
if (!SendInfo(info))
{
CGImageRelease(pCGImage);
return NULL;
}
return pCGImage;
}
CGImageRelease(pCGImage);
}
return NULL;
}
示例5: checkForSolidColor
void BitmapImage::checkForSolidColor()
{
m_checkedForSolidColor = true;
m_isSolidColor = false;
if (frameCount() > 1)
return;
if (!haveFrameAtIndex(0)) {
IntSize size = m_source.frameSizeAtIndex(0, 0);
if (size.width() != 1 || size.height() != 1)
return;
if (!ensureFrameIsCached(0))
return;
}
CGImageRef image = nullptr;
if (m_frames.size())
image = m_frames[0].m_frame;
if (!image)
return;
// Currently we only check for solid color in the important special case of a 1x1 image.
if (CGImageGetWidth(image) == 1 && CGImageGetHeight(image) == 1) {
unsigned char pixel[4]; // RGBA
RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), deviceRGBColorSpaceRef(),
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
if (!bitmapContext)
return;
GraphicsContext(bitmapContext.get()).setCompositeOperation(CompositeCopy);
CGRect destinationRect = CGRectMake(0, 0, 1, 1);
CGContextDrawImage(bitmapContext.get(), destinationRect, image);
if (!pixel[3])
m_solidColor = Color(0, 0, 0, 0);
else
m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
m_isSolidColor = true;
}
}
示例6: frameAtIndex
void BitmapImage::checkForSolidColor()
{
m_checkedForSolidColor = true;
if (frameCount() > 1) {
m_isSolidColor = false;
return;
}
#if !PLATFORM(IOS)
CGImageRef image = frameAtIndex(0);
#else
// Note, checkForSolidColor() may be called from frameAtIndex(). On iOS frameAtIndex() gets passed a scaleHint
// argument which it uses to tell CG to create a scaled down image. Since we don't know the scaleHint here, if
// we call frameAtIndex() again, we would pass it the default scale of 1 and would end up recreating the image.
// So we do a quick check and call frameAtIndex(0) only if we haven't yet created an image.
CGImageRef image = nullptr;
if (m_frames.size())
image = m_frames[0].m_frame;
if (!image)
image = frameAtIndex(0);
#endif
// Currently we only check for solid color in the important special case of a 1x1 image.
if (image && CGImageGetWidth(image) == 1 && CGImageGetHeight(image) == 1) {
unsigned char pixel[4]; // RGBA
RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), deviceRGBColorSpaceRef(),
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
if (!bitmapContext)
return;
GraphicsContext(bitmapContext.get()).setCompositeOperation(CompositeCopy);
CGRect destinationRect = CGRectMake(0, 0, 1, 1);
CGContextDrawImage(bitmapContext.get(), destinationRect, image);
if (!pixel[3])
m_solidColor = Color(0, 0, 0, 0);
else
m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
m_isSolidColor = true;
}
}
示例7: CGContextRetain
CFX_QuartzDeviceDriver::CFX_QuartzDeviceDriver(CGContextRef context, FX_INT32 deviceClass)
{
m_saveCount = 0;
_context = context;
_deviceClass = deviceClass;
CGContextRetain(_context);
CGRect r = CGContextGetClipBoundingBox(context);
_width = FXSYS_round(r.size.width);
_height = FXSYS_round(r.size.height);
_renderCaps = FXRC_SOFT_CLIP | FXRC_BLEND_MODE |
FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE |
FXRC_BIT_MASK | FXRC_ALPHA_MASK;
if (_deviceClass != FXDC_DISPLAY) {
} else {
CGImageRef image = CGBitmapContextCreateImage(_context);
if (image) {
_renderCaps |= FXRC_GET_BITS;
_width = CGImageGetWidth(image);
_height = CGImageGetHeight(image);
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(image);
if (kCGImageAlphaPremultipliedFirst == alphaInfo ||
kCGImageAlphaPremultipliedLast == alphaInfo ||
kCGImageAlphaOnly == alphaInfo) {
_renderCaps |= FXRC_ALPHA_OUTPUT;
}
}
CGImageRelease(image);
}
CGAffineTransform ctm = CGContextGetCTM(_context);
CGContextSaveGState(_context);
m_saveCount++;
if (ctm.d >= 0) {
CGFloat offset_x, offset_y;
offset_x = ctm.tx;
offset_y = ctm.ty;
CGContextTranslateCTM(_context, -offset_x, -offset_y);
CGContextConcatCTM(_context, CGAffineTransformMake(1, 0, 0, -1, offset_x, _height + offset_y));
}
_foxitDevice2User = CGAffineTransformIdentity;
_user2FoxitDevice = CGAffineTransformInvert(_foxitDevice2User);
}
示例8: ASSERT
String ImageBuffer::toDataURL(const String& mimeType) const
{
ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(context()->platformContext()));
if (!image)
return "data:,";
size_t width = CGImageGetWidth(image.get());
size_t height = CGImageGetHeight(image.get());
OwnArrayPtr<uint32_t> imageData(new uint32_t[width * height]);
if (!imageData)
return "data:,";
RetainPtr<CGImageRef> transformedImage(AdoptCF, CGBitmapContextCreateImage(context()->platformContext()));
if (!transformedImage)
return "data:,";
RetainPtr<CFMutableDataRef> transformedImageData(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0));
if (!transformedImageData)
return "data:,";
RetainPtr<CGImageDestinationRef> imageDestination(AdoptCF, CGImageDestinationCreateWithData(transformedImageData.get(),
utiFromMIMEType(mimeType).get(), 1, 0));
if (!imageDestination)
return "data:,";
CGImageDestinationAddImage(imageDestination.get(), transformedImage.get(), 0);
CGImageDestinationFinalize(imageDestination.get());
Vector<char> in;
in.append(CFDataGetBytePtr(transformedImageData.get()), CFDataGetLength(transformedImageData.get()));
Vector<char> out;
base64Encode(in, out);
out.append('\0');
return String::format("data:%s;base64,%s", mimeType.utf8().data(), out.data());
}
示例9: beginCGContext
//-----------------------------------------------------------------------------
void CGDrawContext::fillRectWithBitmap (CBitmap* bitmap, const CRect& srcRect, const CRect& dstRect, float alpha)
{
if (bitmap == 0 || alpha == 0.f || srcRect.isEmpty () || dstRect.isEmpty ())
return;
if (!(srcRect.left == 0 && srcRect.right == 0 && srcRect.right == bitmap->getWidth () && srcRect.bottom == bitmap->getHeight ()))
{
// CGContextDrawTiledImage does not work with parts of a bitmap
CDrawContext::fillRectWithBitmap(bitmap, srcRect, dstRect, alpha);
return;
}
IPlatformBitmap* platformBitmap = bitmap->getBestPlatformBitmapForScaleFactor (scaleFactor);
CPoint bitmapSize = platformBitmap->getSize ();
if (srcRect.right > bitmapSize.x || srcRect.bottom > bitmapSize.y)
return;
CGBitmap* cgBitmap = platformBitmap ? dynamic_cast<CGBitmap*> (platformBitmap) : 0;
CGImageRef image = cgBitmap ? cgBitmap->getCGImage () : 0;
if (image)
{
CGContextRef context = beginCGContext (false, true);
if (context)
{
// TODO: Check if this works with retina images
CGRect clipRect = CGRectFromCRect (dstRect);
clipRect.origin.y = -(clipRect.origin.y) - clipRect.size.height;
clipRect = pixelAlligned (clipRect);
CGContextClipToRect (context, clipRect);
CGRect r = {};
r.size.width = CGImageGetWidth (image);
r.size.height = CGImageGetHeight (image);
CGContextDrawTiledImage (context, r, image);
releaseCGContext (context);
}
}
}
示例10: DrawSubCGImage
void DrawSubCGImage (CGContextRef ctx, CGImageRef image, CGRect src, CGRect dst)
{
float w = (float) CGImageGetWidth(image);
float h = (float) CGImageGetHeight(image);
CGRect drawRect = CGRectMake(0.0f, 0.0f, w, h);
if (!CGRectEqualToRect(src, dst))
{
float sx = CGRectGetWidth(dst) / CGRectGetWidth(src);
float sy = CGRectGetHeight(dst) / CGRectGetHeight(src);
float dx = CGRectGetMinX(dst) - (CGRectGetMinX(src) * sx);
float dy = CGRectGetMinY(dst) - (CGRectGetMinY(src) * sy);
drawRect = CGRectMake(dx, dy, w * sx, h * sy);
}
CGContextSaveGState(ctx);
CGContextClipToRect(ctx, dst);
CGContextDrawImage(ctx, drawRect, image);
CGContextRestoreGState(ctx);
}
示例11: CGImageGetWidth
cv::Mat &osx_cv::toMat(
const CGImageRef &image,
cv::Mat &out,
osx::disp::RGBType destType
) {
cv::Mat temp;
size_t w = CGImageGetWidth(image), h = CGImageGetHeight(image);
if (CGImageGetBitsPerPixel(image) != 32) {
throw invalid_argument("`image` must be 32 bits per pixel");
}
temp.create(int(h), int(w), CV_8UC4);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image);
CGContextRef context = CGBitmapContextCreate(
temp.data,
w,
h,
CGImageGetBitsPerComponent(image),
CGImageGetBytesPerRow(image),
colorSpace,
CGImageGetAlphaInfo(image)
);
CGContextDrawImage(
context,
CGRectMake(0, 0, (CGFloat)w, (CGFloat)h),
image
);
_cvtRGBColor(temp, out, CGImageGetAlphaInfo(image), destType);
CGContextRelease(context);
return out;
}
示例12: LockTarget
bool LockTarget(MCStackSurfaceTargetType p_type, void*& r_context)
{
if (p_type != kMCStackSurfaceTargetCoreGraphics)
return false;
CGImageRef t_mask;
t_mask = nil;
if (m_stack -> getwindowshape() != nil)
t_mask = (CGImageRef)m_stack -> getwindowshape() -> handle;
if (t_mask != nil)
{
MCRectangle t_card_rect;
t_card_rect = m_stack -> getcurcard() -> getrect();
MCRectangle t_rect;
t_rect = MCRegionGetBoundingBox(m_region);
CGContextClearRect(m_context, CGRectMake(t_rect . x, t_card_rect . height - (t_rect . y + t_rect . height), t_rect . width, t_rect . height));
// MW-2012-07-25: [[ Bug ]] Make sure we use signed arithmetic to
// compute the y-origin otherwise it wraps to 2^32!
int32_t t_mask_height, t_mask_width;
t_mask_width = (int32_t)CGImageGetWidth(t_mask);
t_mask_height = (int32_t)CGImageGetHeight(t_mask);
CGRect t_dst_rect;
t_dst_rect . origin . x = 0;
t_dst_rect . origin . y = ((int32_t)t_card_rect . height) - t_mask_height - m_stack -> getscroll();
t_dst_rect . size . width = t_mask_width;
t_dst_rect . size . height = t_mask_height;
CGContextClipToMask(m_context, t_dst_rect, t_mask);
}
CGContextSaveGState(m_context);
r_context = m_context;
return true;
}
示例13: SkStreamToCGImageSource
bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream);
if (NULL == imageSrc) {
return false;
}
SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc);
CGImageRef image = CGImageSourceCreateImageAtIndex(imageSrc, 0, NULL);
if (NULL == image) {
return false;
}
SkAutoTCallVProc<CGImage, CGImageRelease> arimage(image);
const int width = CGImageGetWidth(image);
const int height = CGImageGetHeight(image);
bm->setConfig(SkBitmap::kARGB_8888_Config, width, height);
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return true;
}
if (!this->allocPixelRef(bm, NULL)) {
return false;
}
bm->lockPixels();
bm->eraseColor(0);
// use the same colorspace, so we don't change the pixels at all
CGColorSpaceRef cs = CGImageGetColorSpace(image);
CGContextRef cg = CGBitmapContextCreate(bm->getPixels(), width, height,
8, bm->rowBytes(), cs, BITMAP_INFO);
CGContextDrawImage(cg, CGRectMake(0, 0, width, height), image);
CGContextRelease(cg);
bm->unlockPixels();
return true;
}
示例14: CGImageToMat
cv::Mat CGImageToMat(CGImageRef image) {
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image);
CGFloat cols = CGImageGetWidth(image);
CGFloat rows = CGImageGetHeight(image);
cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels (color channels + alpha)
CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to data
cols, // Width of bitmap
rows, // Height of bitmap
8, // Bits per component
cvMat.step[0], // Bytes per row
colorSpace, // Colorspace
kCGImageAlphaNoneSkipLast |
kCGBitmapByteOrderDefault); // Bitmap info flags
CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), image);
CGContextRelease(contextRef);
return cvMat;
}
示例15: CGImageMaskCreateWithImageRef
CGImageRef CGImageMaskCreateWithImageRef(CGImageRef imageRef) {
size_t maskWidth = CGImageGetWidth(imageRef);
size_t maskHeight = CGImageGetHeight(imageRef);
size_t bytesPerRow = maskWidth;
size_t bufferSize = maskWidth * maskHeight;
CFMutableDataRef dataBuffer = CFDataCreateMutable(kCFAllocatorDefault, 0);
CFDataSetLength(dataBuffer, bufferSize);
CGColorSpaceRef greyColorSpaceRef = CGColorSpaceCreateDeviceGray();
CGContextRef ctx = CGBitmapContextCreate(CFDataGetMutableBytePtr(dataBuffer),
maskWidth,
maskHeight,
8,
bytesPerRow,
greyColorSpaceRef,
kCGImageAlphaNone);
CGContextDrawImage(ctx, CGRectMake(0, 0, maskWidth, maskHeight), imageRef);
CGContextRelease(ctx);
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataBuffer);
CGImageRef maskImageRef = CGImageMaskCreate(maskWidth,
maskHeight,
8,
8,
bytesPerRow,
dataProvider,
NULL,
FALSE);
CGDataProviderRelease(dataProvider);
CGColorSpaceRelease(greyColorSpaceRef);
CFRelease(dataBuffer);
return maskImageRef;
}