当前位置: 首页>>代码示例>>C++>>正文


C++ CGContextRelease函数代码示例

本文整理汇总了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
	}
}
开发者ID:nyue,项目名称:graphviz-cmake,代码行数:51,代码来源:gvrender_quartz.c

示例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));
}
开发者ID:acss,项目名称:owb-mirror,代码行数:31,代码来源:ImageBufferCG.cpp

示例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);
	}
}
开发者ID:Bjoernke,项目名称:livecode,代码行数:29,代码来源:osxstack.cpp

示例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();
}
开发者ID:Happy-Ferret,项目名称:webkit.js,代码行数:29,代码来源:DragImageCGWin.cpp

示例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();
    }
}
开发者ID:huangzongwu,项目名称:touchvg,代码行数:31,代码来源:ioscanvas.cpp

示例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
}
开发者ID:huangzongwu,项目名称:touchvg,代码行数:27,代码来源:ioscanvas.cpp

示例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;
}
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:39,代码来源:VBoxUtils-darwin.cpp

示例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;
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:32,代码来源:ImageBufferCG.cpp

示例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);
}
开发者ID:3163504123,项目名称:phantomjs,代码行数:31,代码来源:GraphicsContextCGWin.cpp

示例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;
}
开发者ID:dog-god,项目名称:iptv,代码行数:26,代码来源:ImageCGWin.cpp

示例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();
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:34,代码来源:GraphicsContextCGWin.cpp

示例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;
}
开发者ID:1833183060,项目名称:wke,代码行数:29,代码来源:FrameCGWin.cpp

示例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;
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:33,代码来源:SkCreateCGImageRef.cpp

示例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);
    }
}
开发者ID:MaddTheSane,项目名称:Glypha,代码行数:29,代码来源:GLImage_CoreImage.cpp

示例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);
			}
		}
	}
}
开发者ID:Bjoernke,项目名称:livecode,代码行数:33,代码来源:osxstack.cpp


注:本文中的CGContextRelease函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。