这篇教程C++ CGContextRelease函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CGContextRelease函数的典型用法代码示例。如果您正苦于以下问题:C++ CGContextRelease函数的具体用法?C++ CGContextRelease怎么用?C++ CGContextRelease使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CGContextRelease函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: quartzgen_end_jobstatic 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,
示例2: tryFastCallocauto_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,
示例3: MCMacRenderBitsToCGstatic 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,
示例4: createDragImageFromImageDragImageRef 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,
示例5: CGBitmapContextCreateImagevoid 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,
示例6: CGImageGetWidthCGImageRef 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,
示例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,
示例8: m_dataImageBuffer::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,
示例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,
示例10: ASSERTbool 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,
示例11: GetObjectvoid 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,
示例12: imageFromRectstatic 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,
示例13: SkCopyPixelsFromCGImageSK_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,
示例14: CFDataCreateWithBytesNoCopyvoid 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,
示例15: CGRectMakevoid 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,
示例16: CGPointMakeFX_BOOL CFX_QuartzDeviceDriver::GetDIBits(CFX_DIBitmap* bitmap, FX_INT32 left, FX_INT32 top, void* pIccTransform, FX_BOOL bDEdge){ if (FXDC_PRINTER == _deviceClass) { return FALSE; } if (bitmap->GetBPP() < 32) { return FALSE; } if (!(_renderCaps | FXRC_GET_BITS)) { return FALSE; } CGPoint pt = CGPointMake(left, top); pt = CGPointApplyAffineTransform(pt, _foxitDevice2User); CGAffineTransform ctm = CGContextGetCTM(_context); pt.x *= FXSYS_fabs(ctm.a); pt.y *= FXSYS_fabs(ctm.d); CGImageRef image = CGBitmapContextCreateImage(_context); if (NULL == image) { return FALSE; } CGFloat width = (CGFloat) bitmap->GetWidth(); CGFloat height = (CGFloat) bitmap->GetHeight(); if (width + pt.x > _width) { width -= (width + pt.x - _width); } if (height + pt.y > _height) { height -= (height + pt.y - _height); } CGImageRef subImage = CGImageCreateWithImageInRect(image, CGRectMake(pt.x, pt.y, width, height)); CGContextRef context = createContextWithBitmap(bitmap); CGRect rect = CGContextGetClipBoundingBox(context); CGContextClearRect(context, rect); CGContextDrawImage(context, rect, subImage); CGContextRelease(context); CGImageRelease(subImage); CGImageRelease(image); if (bitmap->HasAlpha()) { for (int row = 0; row < bitmap->GetHeight(); row ++) { FX_LPBYTE pScanline = (FX_LPBYTE)bitmap->GetScanline(row); for (int col = 0; col < bitmap->GetWidth(); col ++) { if (pScanline[3] > 0) { pScanline[0] = (pScanline[0] * 255.f / pScanline[3] + .5f); pScanline[1] = (pScanline[1] * 255.f / pScanline[3] + .5f); pScanline[2] = (pScanline[2] * 255.f / pScanline[3] + .5f); } pScanline += 4; } } } return TRUE;}
开发者ID:151706061,项目名称:PDFium,代码行数:59,
示例17: os_image_load_from_fileunsigned char* os_image_load_from_file(const char* filename, int* outWidth, int* outHeight, int* outChannels, int unused) { const int fileHandle = open(filename, O_RDONLY); struct stat statBuffer; fstat(fileHandle, &statBuffer); const size_t bytesInFile = (size_t)(statBuffer.st_size); uint8_t* fileData = (uint8_t*)(mmap(NULL, bytesInFile, PROT_READ, MAP_SHARED, fileHandle, 0)); if (fileData == MAP_FAILED) { fprintf(stderr, "Couldn't open file '%s' with mmap/n", filename); return NULL; } CFDataRef fileDataRef = CFDataCreateWithBytesNoCopy(NULL, fileData, bytesInFile, kCFAllocatorNull); CGDataProviderRef imageProvider = CGDataProviderCreateWithCFData(fileDataRef); const char* suffix = strrchr(filename, '.'); if (!suffix || suffix == filename) { suffix = ""; } CGImageRef image; if (strcasecmp(suffix, ".png") == 0) { image = CGImageCreateWithPNGDataProvider(imageProvider, NULL, true, kCGRenderingIntentDefault); } else if ((strcasecmp(suffix, ".jpg") == 0) || (strcasecmp(suffix, ".jpeg") == 0)) { image = CGImageCreateWithJPEGDataProvider(imageProvider, NULL, true, kCGRenderingIntentDefault); } else { munmap(fileData, bytesInFile); close(fileHandle); CFRelease(imageProvider); CFRelease(fileDataRef); fprintf(stderr, "Unknown suffix for file '%s'/n", filename); return NULL; } const int width = (int)CGImageGetWidth(image); const int height = (int)CGImageGetHeight(image); const int channels = 4; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); const int bytesPerRow = (width * channels); const int bytesInImage = (bytesPerRow * height); uint8_t* result = (uint8_t*)(malloc(bytesInImage)); const int bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(result, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context, CGRectMake(0, 0, width, height), image); CGContextRelease(context); CFRelease(image); munmap(fileData, bytesInFile); close(fileHandle); CFRelease(imageProvider); CFRelease(fileDataRef); *outWidth = width; *outHeight = height; *outChannels = channels; return result;}
开发者ID:anshulnsit,项目名称:MDig,代码行数:59,
示例18: Quartz_Closestatic void Quartz_Close(NewDevDesc *dd){ QuartzDesc *xd = (QuartzDesc *) dd->deviceSpecific; if(xd->window) DisposeWindow(xd->window); if(xd->family) free(xd->family); if(xd->context) CGContextRelease(xd->context); if(xd->auxcontext) CGContextRelease(xd->auxcontext); free(xd);}
开发者ID:Vladimir84,项目名称:rcc,代码行数:17,
示例19: CGContextReleasevoid BitLockerSkia::releaseIfNeeded(){ if (!m_cgContext) return; m_canvas->getDevice()->accessBitmap(true).unlockPixels(); CGContextRelease(m_cgContext); m_cgContext = 0;}
开发者ID:1833183060,项目名称:wke,代码行数:8,
示例20: CGContextReleaseCFX_QuartzDevice::~CFX_QuartzDevice(){ if (m_pContext) { CGContextRelease(m_pContext); } if (GetBitmap() && m_bOwnedBitmap) { delete GetBitmap(); }}
开发者ID:151706061,项目名称:PDFium,代码行数:9,
示例21: onDraw virtual void onDraw(SkCanvas* canvas) {#ifdef SK_BUILD_FOR_MAC CGContextRef cg = 0; { SkImageInfo info; size_t rowBytes; const void* addr = canvas->peekPixels(&info, &rowBytes); if (addr) { cg = makeCG(info, addr, rowBytes); } }#endif drawGrad(canvas); const SkColor fg[] = { 0xFFFFFFFF, 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFF000000, }; const char* text = "Hamburgefons"; size_t len = strlen(text); SkPaint paint; setFont(&paint, "Times"); paint.setTextSize(SkIntToScalar(16)); paint.setAntiAlias(true); paint.setLCDRenderText(true); SkScalar x = SkIntToScalar(10); for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) { paint.setColor(fg[i]); SkScalar y = SkIntToScalar(40); SkScalar stopy = SkIntToScalar(HEIGHT); while (y < stopy) { if (true) { canvas->drawText(text, len, x, y, paint); }#ifdef SK_BUILD_FOR_MAC else { cgDrawText(cg, text, len, SkScalarToFloat(x), static_cast<float>(HEIGHT) - SkScalarToFloat(y), paint); }#endif y += paint.getTextSize() * 2; } x += SkIntToScalar(1024) / SK_ARRAY_COUNT(fg); }#ifdef SK_BUILD_FOR_MAC CGContextRelease(cg);#endif }
开发者ID:UIKit0,项目名称:skia,代码行数:56,
示例22: scaleDragImageDragImageRef 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; HDC dc = GetDC(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); ReleaseDC(0, dc); return hbmp;}
开发者ID:Czerrr,项目名称:ISeeBrowser,代码行数:43,
示例23: SkStreamToCGImageSourcebool 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(SK_ColorTRANSPARENT); // 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); if (NULL == cg) { // perhaps the image's colorspace does not work for a context, so try just rgb cs = CGColorSpaceCreateDeviceRGB(); cg = CGBitmapContextCreate(bm->getPixels(), width, height, 8, bm->rowBytes(), cs, BITMAP_INFO); CFRelease(cs); } CGContextDrawImage(cg, CGRectMake(0, 0, width, height), image); CGContextRelease(cg); CGImageAlphaInfo info = CGImageGetAlphaInfo(image); switch (info) { case kCGImageAlphaNone: case kCGImageAlphaNoneSkipLast: case kCGImageAlphaNoneSkipFirst: SkASSERT(SkBitmap::ComputeIsOpaque(*bm)); bm->setIsOpaque(true); break; default: // we don't know if we're opaque or not, so compute it. bm->computeAndSetOpaquePredicate(); } bm->unlockPixels(); return true;}
开发者ID:ConradIrwin,项目名称:gecko-dev,代码行数:55,
示例24: CGContextRestoreGStateCFX_QuartzDeviceDriver::~CFX_QuartzDeviceDriver(){ CGContextRestoreGState(_context); m_saveCount--; for (int i = 0; i < m_saveCount; ++i) { CGContextRestoreGState(_context); } if (_context) { CGContextRelease(_context); }}
开发者ID:151706061,项目名称:PDFium,代码行数:11,
示例25: GeneratePreviewForURLOSStatus 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;}
开发者ID:UIKit0,项目名称:QLdds,代码行数:41,
示例26: GraphicsContextPlatformPrivatevoid GraphicsContext::platformInit(HDC hdc, bool hasAlpha){ m_data = new GraphicsContextPlatformPrivate(CGContextWithHDC(hdc, hasAlpha)); CGContextRelease(m_data->m_cgContext.get()); m_data->m_hdc = hdc; setPaintingDisabled(!m_data->m_cgContext); if (m_data->m_cgContext) { // Make sure the context starts in sync with our state. setPlatformFillColor(fillColor(), ColorSpaceDeviceRGB); setPlatformStrokeColor(strokeColor(), ColorSpaceDeviceRGB); }}
开发者ID:3163504123,项目名称:phantomjs,代码行数:12,
示例27: SetCGContextOSStatus SetCGContext(QuartzDesc *xd){ Rect rect; OSStatus err = noErr; CGRect cgRect; if(xd->context){ CGContextRelease(xd->context); xd->context = NULL; } if(xd->auxcontext){ CGContextRelease(xd->auxcontext); xd->auxcontext = NULL; } if(xd->window) err = CreateCGContextForPort(GetWindowPort(xd->window), &xd->context); if(xd->window) GetPortBounds(GetWindowPort(xd->window), &rect); if(xd->context){ CGContextTranslateCTM(xd->context,0, (float)(rect.bottom - rect.top));/* Be aware that by performing a negative scale in the following line of code, your text will also be flipped*/ CGContextScaleCTM(xd->context, 1, -1); /* We apply here Antialiasing if necessary */ CGContextSetShouldAntialias(xd->context, xd->Antialias); } return err;}
开发者ID:Vladimir84,项目名称:rcc,代码行数:40,
示例28: m_commonGraphicsContext::GraphicsContext(HDC hdc, bool hasAlpha) : m_common(createGraphicsContextPrivate()) , m_data(new GraphicsContextPlatformPrivate(CGContextWithHDC(hdc, hasAlpha))){ CGContextRelease(m_data->m_cgContext); m_data->m_hdc = hdc; setPaintingDisabled(!m_data->m_cgContext); if (m_data->m_cgContext) { // Make sure the context starts in sync with our state. setPlatformFillColor(fillColor()); setPlatformStrokeColor(strokeColor()); }}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:13,
注:本文中的CGContextRelease函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ CGContextRestoreGState函数代码示例 C++ CGContextDrawImage函数代码示例 |