本文整理匯總了C++中CGContextRelease函數的典型用法代碼示例。如果您正苦於以下問題:C++ CGContextRelease函數的具體用法?C++ CGContextRelease怎麽用?C++ CGContextRelease使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CGContextRelease函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: quartzgen_end_job
static void quartzgen_end_job(GVJ_t *job)
{
CGContextRef context = (CGContextRef)job->context;
if (!job->external_context) {
switch (job->device.id) {
case FORMAT_PDF:
/* save the PDF */
CGPDFContextClose(context);
break;
case FORMAT_CGIMAGE:
break;
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1040
default: /* bitmap formats */
{
/* create an image destination */
CGDataConsumerRef data_consumer = CGDataConsumerCreate(job, &device_data_consumer_callbacks);
CGImageDestinationRef image_destination = CGImageDestinationCreateWithDataConsumer(data_consumer, format_uti[job->device.id], 1, NULL);
/* add the bitmap image to the destination and save it */
CGImageRef image = CGBitmapContextCreateImage(context);
CGImageDestinationAddImage(image_destination, image, NULL);
CGImageDestinationFinalize(image_destination);
/* clean up */
if (image_destination)
CFRelease(image_destination);
CGImageRelease(image);
CGDataConsumerRelease(data_consumer);
}
break;
#endif
}
CGContextRelease(context);
}
else if (job->device.id == FORMAT_CGIMAGE)
{
/* create an image and save it where the window field is, which was set to the passed-in context at begin job */
*((CGImageRef*)job->window) = CGBitmapContextCreateImage(context);
#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 20000
void* context_data = CGBitmapContextGetData(context);
size_t context_datalen = CGBitmapContextGetBytesPerRow(context) * CGBitmapContextGetHeight(context);
#endif
CGContextRelease(context);
#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 20000
munmap(context_data, context_datalen);
#endif
}
}
示例2: tryFastCalloc
auto_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, bool grayScale)
{
if (size.width() < 0 || size.height() < 0)
return auto_ptr<ImageBuffer>();
unsigned int bytesPerRow = size.width();
if (!grayScale) {
// Protect against overflow
if (bytesPerRow > 0x3FFFFFFF)
return auto_ptr<ImageBuffer>();
bytesPerRow *= 4;
}
void* imageBuffer = tryFastCalloc(size.height(), bytesPerRow);
if (!imageBuffer)
return auto_ptr<ImageBuffer>();
CGColorSpaceRef colorSpace = grayScale ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
CGContextRef cgContext = CGBitmapContextCreate(imageBuffer, size.width(), size.height(), 8, bytesPerRow,
colorSpace, grayScale ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
if (!cgContext) {
fastFree(imageBuffer);
return auto_ptr<ImageBuffer>();
}
auto_ptr<GraphicsContext> context(new GraphicsContext(cgContext));
context->scale(FloatSize(1, -1));
context->translate(0, -size.height());
CGContextRelease(cgContext);
return auto_ptr<ImageBuffer>(new ImageBuffer(imageBuffer, size, context));
}
示例3: MCMacRenderBitsToCG
static void MCMacRenderBitsToCG(CGContextRef p_target, CGRect p_area, const void *p_bits, uint32_t p_stride, bool p_has_alpha)
{
CGColorSpaceRef t_colorspace;
t_colorspace = CGColorSpaceCreateDeviceRGB();
if (t_colorspace != nil)
{
CGBitmapInfo t_bitmap_info;
t_bitmap_info = kCGBitmapByteOrder32Host;
t_bitmap_info |= p_has_alpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst;
CGContextRef t_cgcontext;
t_cgcontext = CGBitmapContextCreate((void *)p_bits, p_area . size . width, p_area . size . height, 8, p_stride, t_colorspace, t_bitmap_info);
if (t_cgcontext != nil)
{
CGImageRef t_image;
t_image = CGBitmapContextCreateImage(t_cgcontext);
CGContextRelease(t_cgcontext);
if (t_image != nil)
{
CGContextClipToRect((CGContextRef)p_target, p_area);
CGContextDrawImage((CGContextRef)p_target, p_area, t_image);
CGImageRelease(t_image);
}
}
CGColorSpaceRelease(t_colorspace);
}
}
示例4: createDragImageFromImage
DragImageRef createDragImageFromImage(Image* img, ImageOrientationDescription)
{
HWndDC dc(0);
auto workingDC = adoptGDIObject(::CreateCompatibleDC(dc));
if (!workingDC)
return 0;
CGContextRef drawContext = 0;
auto hbmp = allocImage(workingDC.get(), img->size(), &drawContext);
if (!hbmp || !drawContext)
return 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);
if (srcImage) {
CGContextSetBlendMode(drawContext, kCGBlendModeNormal);
CGContextDrawImage(drawContext, rect, srcImage);
}
CGContextRelease(drawContext);
return hbmp.leak();
}
示例5: CGBitmapContextCreateImage
void GiCanvasIos::endPaint(bool draw)
{
if (m_draw->getContext())
{
if (draw && m_draw->_buffctx && m_draw->_context) {
CGContextRef context = m_draw->_context;
CGImageRef image = CGBitmapContextCreateImage(m_draw->_buffctx);
CGRect rect = CGRectMake(0, 0, m_draw->width(), m_draw->height()); // 邏輯寬高點數
if (image) {
CGAffineTransform af = CGAffineTransformMake(1, 0, 0, -1, 0, m_draw->height());
CGContextConcatCTM(context, af); // 圖像是朝上的,上下文坐標係朝下,上下顛倒顯示
CGInterpolationQuality old = CGContextGetInterpolationQuality(context);
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
CGContextDrawImage(context, rect, image);
CGContextSetInterpolationQuality(context, old);
CGContextConcatCTM(context, CGAffineTransformInvert(af)); // 恢複成坐標係朝下
CGImageRelease(image);
}
}
if (m_draw->_buffctx) {
CGContextRelease(m_draw->_buffctx);
m_draw->_buffctx = NULL;
}
m_draw->_context = NULL;
if (owner())
owner()->_endPaint();
}
}
示例6: CGImageGetWidth
CGImageRef GiCanvasIos::cachedBitmap(bool invert)
{
CGImageRef image = m_draw->_caches[0];
if (!image || !invert)
return image; // 調用者不能釋放圖像
size_t w = CGImageGetWidth(image); // 圖像寬度,像素單位,不是點單位
size_t h = CGImageGetHeight(image);
CGImageRef newimg = NULL;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, w * 4,
colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
if (context) {
CGAffineTransform af = CGAffineTransformMake(1, 0, 0, -1, 0, h);
CGContextConcatCTM(context, af); // 圖像是朝上的,上下文坐標係朝下,上下顛倒顯示
CGContextDrawImage(context, CGRectMake(0, 0, w, h), image);
CGContextConcatCTM(context, CGAffineTransformInvert(af));
newimg = CGBitmapContextCreateImage(context); // 得到上下顛倒的新圖像
CGContextRelease(context);
}
return newimg; // 由調用者釋放圖像, CGImageRelease
}
示例7: darwinToCGImageRef
/**
* Converts a QPixmap to a CGImage.
*
* @returns CGImageRef for the new image. (Remember to release it when finished with it.)
* @param aPixmap Pointer to the QPixmap instance to convert.
*/
CGImageRef darwinToCGImageRef(const QPixmap *pPixmap)
{
/* It seems Qt releases the memory to an returned CGImageRef when the
* associated QPixmap is destroyed. This shouldn't happen as long a
* CGImageRef has a retrain count. As a workaround we make a real copy. */
int bitmapBytesPerRow = pPixmap->width() * 4;
int bitmapByteCount = (bitmapBytesPerRow * pPixmap->height());
/* Create a memory block for the temporary image. It is initialized by zero
* which means black & zero alpha. */
void *pBitmapData = RTMemAllocZ(bitmapByteCount);
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
/* Create a context to paint on */
CGContextRef ctx = CGBitmapContextCreate(pBitmapData,
pPixmap->width(),
pPixmap->height(),
8,
bitmapBytesPerRow,
cs,
kCGImageAlphaPremultipliedFirst);
/* Get the CGImageRef from Qt */
CGImageRef qtPixmap = pPixmap->toMacCGImageRef();
/* Draw the image from Qt & convert the context back to a new CGImageRef. */
CGContextDrawImage(ctx, CGRectMake(0, 0, pPixmap->width(), pPixmap->height()), qtPixmap);
CGImageRef newImage = CGBitmapContextCreateImage(ctx);
/* Now release all used resources */
CGImageRelease(qtPixmap);
CGContextRelease(ctx);
CGColorSpaceRelease(cs);
RTMemFree(pBitmapData);
/* Return the new CGImageRef */
return newImage;
}
示例8: m_data
ImageBuffer::ImageBuffer(const IntSize& size, bool grayScale, bool& success)
: m_data(size)
, m_size(size)
{
success = false; // Make early return mean failure.
unsigned bytesPerRow;
if (size.width() < 0 || size.height() < 0)
return;
bytesPerRow = size.width();
if (!grayScale) {
// Protect against overflow
if (bytesPerRow > 0x3FFFFFFF)
return;
bytesPerRow *= 4;
}
m_data.m_data = tryFastCalloc(size.height(), bytesPerRow);
ASSERT((reinterpret_cast<size_t>(m_data.m_data) & 2) == 0);
CGColorSpaceRef colorSpace = grayScale ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
CGContextRef cgContext = CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow,
colorSpace, grayScale ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
if (!cgContext)
return;
m_context.set(new GraphicsContext(cgContext));
m_context->scale(FloatSize(1, -1));
m_context->translate(0, -size.height());
CGContextRelease(cgContext);
success = true;
}
示例9: isInTransparencyLayer
// FIXME: Is it possible to merge getWindowsContext and createWindowsBitmap into a single API
// suitable for all clients?
void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
{
bool createdBitmap = mayCreateBitmap && (!m_data->m_hdc || isInTransparencyLayer());
if (!createdBitmap) {
m_data->restore();
return;
}
if (dstRect.isEmpty())
return;
OwnPtr<HBITMAP> bitmap = adoptPtr(static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)));
DIBPixelData pixelData(bitmap.get());
ASSERT(pixelData.bitsPerPixel() == 32);
CGContextRef bitmapContext = CGBitmapContextCreate(pixelData.buffer(), pixelData.size().width(), pixelData.size().height(), 8,
pixelData.bytesPerRow(), deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little |
(supportAlphaBlend ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst));
CGImageRef image = CGBitmapContextCreateImage(bitmapContext);
CGContextDrawImage(m_data->m_cgContext.get(), dstRect, image);
// Delete all our junk.
CGImageRelease(image);
CGContextRelease(bitmapContext);
::DeleteDC(hdc);
}
示例10: ASSERT
bool BitmapImage::getHBITMAPOfSize(HBITMAP bmp, LPSIZE size)
{
ASSERT(bmp);
BITMAP bmpInfo;
GetObject(bmp, sizeof(BITMAP), &bmpInfo);
ASSERT(bmpInfo.bmBitsPixel == 32);
int bufferSize = bmpInfo.bmWidthBytes * bmpInfo.bmHeight;
CGContextRef cgContext = CGBitmapContextCreate(bmpInfo.bmBits, bmpInfo.bmWidth, bmpInfo.bmHeight,
8, bmpInfo.bmWidthBytes, deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
GraphicsContext gc(cgContext);
IntSize imageSize = BitmapImage::size();
if (size)
drawFrameMatchingSourceSize(&gc, FloatRect(0.0f, 0.0f, bmpInfo.bmWidth, bmpInfo.bmHeight), IntSize(*size), ColorSpaceDeviceRGB, CompositeCopy);
else
draw(&gc, FloatRect(0.0f, 0.0f, bmpInfo.bmWidth, bmpInfo.bmHeight), FloatRect(0.0f, 0.0f, imageSize.width(), imageSize.height()), ColorSpaceDeviceRGB, CompositeCopy);
// Do cleanup
CGContextRelease(cgContext);
return true;
}
示例11: GetObject
void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
{
if (mayCreateBitmap && hdc && inTransparencyLayer()) {
if (dstRect.isEmpty())
return;
HBITMAP bitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP));
// Need to make a CGImage out of the bitmap's pixel buffer and then draw
// it into our context.
BITMAP info;
GetObject(bitmap, sizeof(info), &info);
ASSERT(info.bmBitsPixel == 32);
CGColorSpaceRef deviceRGB = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext = CGBitmapContextCreate(info.bmBits, info.bmWidth, info.bmHeight, 8,
info.bmWidthBytes, deviceRGB, kCGBitmapByteOrder32Little |
(supportAlphaBlend ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst));
CGColorSpaceRelease(deviceRGB);
CGImageRef image = CGBitmapContextCreateImage(bitmapContext);
CGContextDrawImage(m_data->m_cgContext, dstRect, image);
// Delete all our junk.
CGImageRelease(image);
CGContextRelease(bitmapContext);
::DeleteDC(hdc);
::DeleteObject(bitmap);
return;
}
m_data->restore();
}
示例12: imageFromRect
static HBITMAP imageFromRect(const Frame* frame, IntRect& ir)
{
PaintBehavior oldPaintBehavior = frame->view()->paintBehavior();
frame->view()->setPaintBehavior(oldPaintBehavior | PaintBehaviorFlattenCompositingLayers);
void* bits;
HDC hdc = CreateCompatibleDC(0);
int w = ir.width();
int h = ir.height();
BitmapInfo bmp = BitmapInfo::create(IntSize(w, h));
HBITMAP hbmp = CreateDIBSection(0, &bmp, DIB_RGB_COLORS, static_cast<void**>(&bits), 0, 0);
HBITMAP hbmpOld = static_cast<HBITMAP>(SelectObject(hdc, hbmp));
CGContextRef context = CGBitmapContextCreate(static_cast<void*>(bits), w, h,
8, w * sizeof(RGBQUAD), deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGContextSaveGState(context);
GraphicsContext gc(context);
drawRectIntoContext(ir, frame->view(), &gc);
CGContextRelease(context);
SelectObject(hdc, hbmpOld);
DeleteDC(hdc);
frame->view()->setPaintBehavior(oldPaintBehavior);
return hbmp;
}
示例13: SkCopyPixelsFromCGImage
SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* pixels,
CGImageRef image) {
CGBitmapInfo cg_bitmap_info = 0;
size_t bitsPerComponent = 0;
switch (info.colorType()) {
case kRGBA_8888_SkColorType:
bitsPerComponent = 8;
cg_bitmap_info = ComputeCGAlphaInfo_RGBA(info.alphaType());
break;
case kBGRA_8888_SkColorType:
bitsPerComponent = 8;
cg_bitmap_info = ComputeCGAlphaInfo_BGRA(info.alphaType());
break;
default:
return false; // no other colortypes are supported (for now)
}
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGContextRef cg = CGBitmapContextCreate(pixels, info.width(), info.height(), bitsPerComponent,
rowBytes, cs, cg_bitmap_info);
CFRelease(cs);
if (NULL == cg) {
return false;
}
// use this blend mode, to avoid having to erase the pixels first, and to avoid CG performing
// any blending (which could introduce errors and be slower).
CGContextSetBlendMode(cg, kCGBlendModeCopy);
CGContextDrawImage(cg, CGRectMake(0, 0, info.width(), info.height()), image);
CGContextRelease(cg);
return true;
}
示例14: CFDataCreateWithBytesNoCopy
void GL::Image::load(const unsigned char *buf, size_t bufSize)
{
CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, (const UInt8*)buf, (CFIndex)bufSize, kCFAllocatorNull);
if (data != NULL) {
CGImageSourceRef imageSource = CGImageSourceCreateWithData(data, NULL);
if (imageSource != NULL) {
CGImageRef img = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
if (img != NULL) {
width_ = (int)CGImageGetWidth(img);
height_ = (int)CGImageGetHeight(img);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
if (colorSpace != NULL) {
char *texData = (char*)calloc(width_ * height_ * 4, sizeof(char));
CGContextRef ctx = CGBitmapContextCreate(texData, width_, height_, 8, width_ * 4, colorSpace, kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
if (ctx != NULL) {
CGContextDrawImage(ctx, CGRectMake(0.0, 0.0, width_, height_), img);
CGContextRelease(ctx);
loadTextureData_(texData);
}
free(texData);
CGColorSpaceRelease(colorSpace);
}
CGImageRelease(img);
}
CFRelease(imageSource);
}
CFRelease(data);
}
}
示例15: CGRectMake
void MCStack::redrawicon()
{
// MW-2005-07-18: It is possible for this to be called if window == NULL in which
// case bad things can happen - so don't let this occur.
if (iconid != 0 && window != NULL)
{
MCImage *iptr = (MCImage *)getobjid(CT_IMAGE, iconid);
if (iptr != NULL)
{
CGImageRef tdockimage;
CGrafPtr tport;
CGrafPtr curport;
CGContextRef context;
OSStatus theErr;
CGRect cgrect = CGRectMake(0,0,128,128);
GetPort( &curport);
OSErr err = CreateQDContextForCollapsedWindowDockTile((WindowPtr)window->handle.window, &tport);
if (err == noErr)
{
SetPort(tport);
CreateCGContextForPort(tport, &context);
tdockimage = iptr -> makeicon(128, 128);
CGContextDrawImage(context,cgrect,tdockimage);
if ( tdockimage )
CGImageRelease( tdockimage );
CGContextFlush(context);
CGContextRelease(context);
SetPort(curport);
ReleaseQDContextForCollapsedWindowDockTile((WindowPtr)window->handle.window, tport);
}
}
}
}