本文整理匯總了C++中CGContextDrawImage函數的典型用法代碼示例。如果您正苦於以下問題:C++ CGContextDrawImage函數的具體用法?C++ CGContextDrawImage怎麽用?C++ CGContextDrawImage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CGContextDrawImage函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: scaleDragImage
DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
{
// FIXME: due to the way drag images are done on windows we need
// to preprocess the alpha channel <rdar://problem/5015946>
if (!image)
return 0;
CGContextRef targetContext;
CGContextRef srcContext;
CGImageRef srcImage;
IntSize srcSize = dragImageSize(image);
IntSize dstSize(static_cast<int>(srcSize.width() * scale.width()), static_cast<int>(srcSize.height() * scale.height()));
HBITMAP hbmp = 0;
HWndDC dc(0);
HDC dstDC = CreateCompatibleDC(dc);
if (!dstDC)
goto exit;
hbmp = allocImage(dstDC, dstSize, &targetContext);
if (!hbmp)
goto exit;
srcContext = createCgContextFromBitmap(image);
srcImage = CGBitmapContextCreateImage(srcContext);
CGRect rect;
rect.origin.x = 0;
rect.origin.y = 0;
rect.size = dstSize;
CGContextDrawImage(targetContext, rect, srcImage);
CGImageRelease(srcImage);
CGContextRelease(srcContext);
CGContextRelease(targetContext);
::DeleteObject(image);
image = 0;
exit:
if (!hbmp)
hbmp = image;
if (dstDC)
DeleteDC(dstDC);
return hbmp;
}
示例2: ASSERT
String ImageBuffer::toDataURL(const String& mimeType, const double* quality, CoordinateSystem) const
{
ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
if (context().isAcceleratedContext())
flushContext();
RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType);
ASSERT(uti);
RefPtr<Uint8ClampedArray> premultipliedData;
RetainPtr<CGImageRef> image;
if (CFEqual(uti.get(), jpegUTI())) {
// JPEGs don't have an alpha channel, so we have to manually composite on top of black.
premultipliedData = getPremultipliedImageData(IntRect(IntPoint(0, 0), logicalSize()));
if (!premultipliedData)
return "data:,";
RetainPtr<CGDataProviderRef> dataProvider;
dataProvider = adoptCF(CGDataProviderCreateWithData(0, premultipliedData->data(), 4 * logicalSize().width() * logicalSize().height(), 0));
if (!dataProvider)
return "data:,";
image = adoptCF(CGImageCreate(logicalSize().width(), logicalSize().height(), 8, 32, 4 * logicalSize().width(),
deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast,
dataProvider.get(), 0, false, kCGRenderingIntentDefault));
} else if (m_resolutionScale == 1) {
image = copyNativeImage(CopyBackingStore);
image = createCroppedImageIfNecessary(image.get(), internalSize());
} else {
image = copyNativeImage(DontCopyBackingStore);
RetainPtr<CGContextRef> context = adoptCF(CGBitmapContextCreate(0, logicalSize().width(), logicalSize().height(), 8, 4 * logicalSize().width(), deviceRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast));
CGContextSetBlendMode(context.get(), kCGBlendModeCopy);
CGContextClipToRect(context.get(), CGRectMake(0, 0, logicalSize().width(), logicalSize().height()));
FloatSize imageSizeInUserSpace = scaleSizeToUserSpace(logicalSize(), m_data.backingStoreSize, internalSize());
CGContextDrawImage(context.get(), CGRectMake(0, 0, imageSizeInUserSpace.width(), imageSizeInUserSpace.height()), image.get());
image = adoptCF(CGBitmapContextCreateImage(context.get()));
}
return CGImageToDataURL(image.get(), mimeType, quality);
}
示例3: adoptCF
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;
}
}
示例4: GeneratePreviewForURL
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url);
if (!dataProvider) return -1;
CFDataRef data = CGDataProviderCopyData(dataProvider);
CGDataProviderRelease(dataProvider);
if (!data) return -1;
int width, height, channels;
unsigned char* rgbadata = SOIL_load_image_from_memory(CFDataGetBytePtr(data), CFDataGetLength(data), &width, &height, &channels, SOIL_LOAD_RGBA);
CFStringRef format=CFStringCreateWithBytes(NULL, CFDataGetBytePtr(data) + 0x54, 4, kCFStringEncodingASCII, false);
CFRelease(data);
if (!rgbadata) return -1;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(rgbadata, width, height, 8, width * 4, rgb, kCGImageAlphaPremultipliedLast);
SOIL_free_image_data(rgbadata);
CGColorSpaceRelease(rgb);
if (!context) return -1;
CGImageRef image = CGBitmapContextCreateImage(context);
CGContextRelease(context);
if (!image) return -1;
/* Add basic metadata to title */
CFStringRef name = CFURLCopyLastPathComponent(url);
CFTypeRef keys[1] = {kQLPreviewPropertyDisplayNameKey};
CFTypeRef values[1] = {CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%dx%d %@)"), name, width, height, format)};
CFDictionaryRef properties = CFDictionaryCreate(NULL, (const void**)keys, (const void**)values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFRelease(name);
context = QLPreviewRequestCreateContext(preview, CGSizeMake(width, height), true, properties);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
QLPreviewRequestFlushContext(preview, context);
CGContextRelease(context);
CFRelease(format);
CFRelease(properties);
return noErr;
}
示例5: 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;
}
}
示例6: DoGetAsBitmap
static wxBitmap DoGetAsBitmap(const wxRect *subrect)
{
CGRect cgbounds = CGDisplayBounds(CGMainDisplayID());
wxRect rect = subrect ? *subrect : wxRect(0, 0, cgbounds.size.width, cgbounds.size.height);
wxBitmap bmp(rect.GetSize().GetWidth(), rect.GetSize().GetHeight(), 32);
CGDisplayCreateImageFunc createImage =
(CGDisplayCreateImageFunc) dlsym(RTLD_NEXT, "CGDisplayCreateImage");
if (createImage == NULL)
{
return bmp;
}
CGRect srcRect = CGRectMake(rect.x, rect.y, rect.width, rect.height);
CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
CGContextSaveGState(context);
CGContextTranslateCTM( context, 0, cgbounds.size.height );
CGContextScaleCTM( context, 1, -1 );
if ( subrect )
srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ;
CGImageRef image = NULL;
image = createImage(kCGDirectMainDisplay);
wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot."));
CGContextDrawImage(context, srcRect, image);
CGImageRelease(image);
CGContextRestoreGState(context);
return bmp;
}
示例7: copyNativeImage
RefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBehavior scaleBehavior) const
{
RetainPtr<CGImageRef> image;
if (m_resolutionScale == 1 || scaleBehavior == Unscaled) {
image = copyNativeImage(copyBehavior);
image = createCroppedImageIfNecessary(image.get(), internalSize());
} else {
image = copyNativeImage(DontCopyBackingStore);
RetainPtr<CGContextRef> context = adoptCF(CGBitmapContextCreate(0, logicalSize().width(), logicalSize().height(), 8, 4 * logicalSize().width(), deviceRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast));
CGContextSetBlendMode(context.get(), kCGBlendModeCopy);
CGContextClipToRect(context.get(), FloatRect(FloatPoint::zero(), logicalSize()));
FloatSize imageSizeInUserSpace = scaleSizeToUserSpace(logicalSize(), m_data.backingStoreSize, internalSize());
CGContextDrawImage(context.get(), FloatRect(FloatPoint::zero(), imageSizeInUserSpace), image.get());
image = adoptCF(CGBitmapContextCreateImage(context.get()));
}
if (!image)
return nullptr;
return BitmapImage::create(image.get());
}
示例8: CGAffineTransformMake
bool GiCanvasIos::drawImage(CGImageRef image, const Box2d& rectM)
{
CGContextRef context = m_draw->getContext();
bool ret = false;
if (context && image) {
Point2d ptD = rectM.center() * m_draw->xf().modelToDisplay();
Box2d rect = rectM * m_draw->xf().modelToDisplay();
CGAffineTransform af = CGAffineTransformMake(1, 0, 0, -1, 0, m_draw->height());
af = CGAffineTransformTranslate(af, ptD.x - rect.width() * 0.5f,
m_draw->height() - (ptD.y + rect.height() * 0.5f));
CGContextConcatCTM(context, af);
CGContextDrawImage(context, CGRectMake(0, 0, rect.width(), rect.height()), image);
CGContextConcatCTM(context, CGAffineTransformInvert(af));
ret = true;
}
return ret;
}
示例9: CGimageResize
CGImageRef CGimageResize(CGImageRef image, CGSize maxSize)
{
// calcualte size
CGFloat ratio = MAX(CGImageGetWidth(image)/maxSize.width,CGImageGetHeight(image)/maxSize.height);
size_t width = CGImageGetWidth(image)/ratio;
size_t height = CGImageGetHeight(image)/ratio;
// resize
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, width, height,
8, width*4, colorspace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorspace);
if(context == NULL) return nil;
// draw image to context (resizing it)
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
// extract resulting image from context
CGImageRef imgRef = CGBitmapContextCreateImage(context);
CGContextRelease(context);
return imgRef;
}
示例10: 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;
}
示例11: 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);
}
示例12: ReadInfo
bool nglImageCGCodec::Feed(nglIStream* pIStream)
{
if (!mpCGImage)
{
mpCGImage = ReadInfo(pIStream); ///< shall allocate the buffer
}
if (!mpCGImage)
return false;
mpIStream = pIStream;
// Use the generic RGB color space.
CGColorSpaceRef pCGColors = CGColorSpaceCreateDeviceRGB();
if (pCGColors == NULL)
{
NGL_OUT(_T("nglImageCGCodec::Feed Error allocating color space\n"));
return false;
}
nglImageInfo info;
mpImage->GetInfo(info);
NGL_ASSERT(info.mpBuffer);
// Create the bitmap context.
// The image will be converted to the format specified here by CGBitmapContextCreate.
CGContextRef pCGContext =
CGBitmapContextCreate(info.mpBuffer, info.mWidth, info.mHeight,
info.mBitDepth/4, info.mBytesPerLine,
pCGColors, kCGImageAlphaPremultipliedLast);//kCGImageAlphaPremultipliedFirst);
CGColorSpaceRelease(pCGColors);
CGRect rect = { {0,0}, {info.mWidth, info.mHeight} };
CGContextClearRect(pCGContext, rect);
CGContextDrawImage(pCGContext, rect, mpCGImage);
CGContextRelease(pCGContext);
SendData(1.0f);
return (pIStream->GetState()==eStreamWait) || (pIStream->GetState()==eStreamReady);;
}
示例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: createDragImageFromImage
DragImageRef createDragImageFromImage(Image* img)
{
HBITMAP hbmp = 0;
HDC dc = GetDC(0);
HDC workingDC = CreateCompatibleDC(dc);
CGContextRef drawContext = 0;
if (!workingDC)
goto exit;
hbmp = allocImage(workingDC, img->size(), &drawContext);
if (!hbmp)
goto exit;
if (!drawContext) {
::DeleteObject(hbmp);
hbmp = 0;
}
CGImageRef srcImage = img->getCGImageRef();
CGRect rect;
rect.size = img->size();
rect.origin.x = 0;
rect.origin.y = -rect.size.height;
static const CGFloat white [] = {1.0, 1.0, 1.0, 1.0};
CGContextScaleCTM(drawContext, 1, -1);
CGContextSetFillColor(drawContext, white);
CGContextFillRect(drawContext, rect);
CGContextSetBlendMode(drawContext, kCGBlendModeNormal);
CGContextDrawImage(drawContext, rect, srcImage);
CGContextRelease(drawContext);
exit:
if (workingDC)
DeleteDC(workingDC);
ReleaseDC(0, dc);
return hbmp;
}
示例15: 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;
}