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


C++ CGBitmapContextCreate函数代码示例

本文整理汇总了C++中CGBitmapContextCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ CGBitmapContextCreate函数的具体用法?C++ CGBitmapContextCreate怎么用?C++ CGBitmapContextCreate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CGBitmapContextCreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: resolveColorSpace

static void resolveColorSpace(const SkBitmap& bitmap, CGColorSpaceRef colorSpace)
{
    int width = bitmap.width();
    int height = bitmap.height();
    CGImageRef srcImage = SkCreateCGImageRefWithColorspace(bitmap, colorSpace);
    SkAutoLockPixels lock(bitmap);
    void* pixels = bitmap.getPixels();
    RetainPtr<CGContextRef> cgBitmap(AdoptCF, CGBitmapContextCreate(pixels, width, height, 8, width * 4, deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst));
    if (!cgBitmap)
        return;
    CGContextSetBlendMode(cgBitmap.get(), kCGBlendModeCopy);
    CGRect bounds = { {0, 0}, {width, height} };
    CGContextDrawImage(cgBitmap.get(), bounds, srcImage);
}
开发者ID:1833183060,项目名称:wke,代码行数:14,代码来源:ImageDecoderSkia.cpp

示例2: SkPDFDocumentToBitmap

bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output) {
    size_t size = stream->getLength();
    void* ptr = sk_malloc_throw(size);
    stream->read(ptr, size);
    CGDataProviderRef data = CGDataProviderCreateWithData(NULL, ptr, size,
                                          CGDataProviderReleaseData_FromMalloc);
    if (NULL == data) {
        return false;
    }
    
    CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(data);
    CGDataProviderRelease(data);
    if (NULL == pdf) {
        return false;
    }
    SkAutoPDFRelease releaseMe(pdf);

    CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
    if (NULL == page) {
        return false;
    }
    
    CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
    
    int w = (int)CGRectGetWidth(bounds);
    int h = (int)CGRectGetHeight(bounds);
        
    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h);
    bitmap.allocPixels();
    bitmap.eraseColor(SK_ColorWHITE);

    size_t bitsPerComponent;
    CGBitmapInfo info;
    getBitmapInfo(bitmap, &bitsPerComponent, &info, NULL); 

    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
    CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h,
                                             bitsPerComponent, bitmap.rowBytes(),
                                             cs, info);
    CGColorSpaceRelease(cs);

    if (ctx) {
        CGContextDrawPDFPage(ctx, page);
        CGContextRelease(ctx);
    }

    output->swap(bitmap);
    return true;
}
开发者ID:AliFarahnak,项目名称:XobotOS,代码行数:50,代码来源:SkCreateCGImageRef.cpp

示例3: IllegalArgumentException

void CGImageLuminanceSource::init (CGImageRef cgimage, int left, int top, int width, int height) {
    data_ = 0;
    image_ = cgimage;
    left_ = left;
    top_ = top;
    width_ = width;
    height_ = height;
    dataWidth_ = (int)CGImageGetWidth(image_);
    dataHeight_ = (int)CGImageGetHeight(image_);

    if (left_ + width_ > dataWidth_ ||
        top_ + height_ > dataHeight_ ||
        top_ < 0 ||
        left_ < 0) {
        throw IllegalArgumentException("Crop rectangle does not fit within image data.");
    }

    CGColorSpaceRef space = CGImageGetColorSpace(image_);
    CGColorSpaceModel model = CGColorSpaceGetModel(space);

    if (model != kCGColorSpaceModelMonochrome || CGImageGetBitsPerComponent(image_) != 8 || CGImageGetBitsPerPixel(image_) != 8) {
        CGColorSpaceRef gray = CGColorSpaceCreateDeviceGray();
        
        CGContextRef ctx = CGBitmapContextCreate(0, width, height, 8, width, gray, kCGImageAlphaNone);
        
        CGColorSpaceRelease(gray);

        if (top || left) {
            CGContextClipToRect(ctx, CGRectMake(0, 0, width, height));
        }

        CGContextDrawImage(ctx, CGRectMake(-left, -top, width, height), image_);
    
        image_ = CGBitmapContextCreateImage(ctx);

        bytesPerRow_ = width;
        top_ = 0;
        left_ = 0;
        dataWidth_ = width;
        dataHeight_ = height;

        CGContextRelease(ctx);
    } else {
        CGImageRetain(image_);
    }

    CGDataProviderRef provider = CGImageGetDataProvider(image_);
    data_ = CGDataProviderCopyData(provider);
}
开发者ID:conradev,项目名称:QuickQR,代码行数:49,代码来源:CGImageLuminanceSource.cpp

示例4: SetupContext

CGContextRef SetupContext()
{
	//UIGraphicsBeginImageContext
	int w = 480, h = 640;
	
	//CGColorSpaceRef csICC = CGColorSpaceCreateWithIndex(15);
	CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
	CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, CGBitmapGetAlignedBytesPerRow(w*4), colourSpace, kCGImageAlphaPremultipliedFirst);
	CGColorSpaceRelease (colourSpace);
	CGContextClear(context);
	CGContextTranslateCTM(context, 0.0, 640.0);
	CGContextScaleCTM(context, 1.0, -1.0);

   return context;
}
开发者ID:NSOiO,项目名称:freequartz,代码行数:15,代码来源:TestCoreGraphics.cpp

示例5: makeCG

static CGContextRef makeCG(const SkImageInfo& info, const void* addr,
                           size_t rowBytes) {
    if (kPMColor_SkColorType != info.colorType() || NULL == addr) {
        return NULL;
    }
    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
    CGContextRef cg = CGBitmapContextCreate((void*)addr, info.width(), info.height(),
                                            8, rowBytes, space, BITMAP_INFO_RGB);
    CFRelease(space);

    CGContextSetAllowsFontSubpixelQuantization(cg, false);
    CGContextSetShouldSubpixelQuantizeFonts(cg, false);

    return cg;
}
开发者ID:UIKit0,项目名称:skia,代码行数:15,代码来源:gammatext.cpp

示例6: SkPDFDocumentToBitmap

bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output) {
    CGDataProviderRef data = SkCreateDataProviderFromStream(stream);
    if (NULL == data) {
        return false;
    }

    CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(data);
    CGDataProviderRelease(data);
    if (NULL == pdf) {
        return false;
    }
    SkAutoPDFRelease releaseMe(pdf);

    CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
    if (NULL == page) {
        return false;
    }

    CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);

    int w = (int)CGRectGetWidth(bounds);
    int h = (int)CGRectGetHeight(bounds);

    SkBitmap bitmap;
    if (!bitmap.tryAllocN32Pixels(w, h)) {
        return false;
    }
    bitmap.eraseColor(SK_ColorWHITE);

    size_t bitsPerComponent;
    CGBitmapInfo info;
    getBitmapInfo(bitmap, &bitsPerComponent, &info, NULL);

    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
    CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h,
                                             bitsPerComponent, bitmap.rowBytes(),
                                             cs, info);
    CGColorSpaceRelease(cs);

    if (ctx) {
        CGContextDrawPDFPage(ctx, page);
        CGContextRelease(ctx);
    }

    output->swap(bitmap);
    return true;
}
开发者ID:Arternis,项目名称:skia,代码行数:47,代码来源:SkCreateCGImageRef.cpp

示例7: CreatePDFPageImage

CGImageRef CreatePDFPageImage(CGPDFPageRef page, CGFloat scale, bool transparentBackground)
{
	CGSize pageSize = PDFPageGetSize(page, kCGPDFCropBox);
	
	size_t width = scale * floorf(pageSize.width);
	size_t height = scale * floorf(pageSize.height);
	size_t bytesPerLine = width * 4;
	uint64_t size = (uint64_t)height * (uint64_t)bytesPerLine;
	
	if ((size == 0) || (size > SIZE_MAX))
		return NULL;
	
	void *bitmapData = malloc(size);
	if (!bitmapData)
		return NULL;
	
#if TARGET_OS_IPHONE
	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
#else
	CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(&kCGColorSpaceSRGB ? kCGColorSpaceSRGB : kCGColorSpaceGenericRGB);
#endif
	CGContextRef context = CGBitmapContextCreate(bitmapData, width, height, 8, bytesPerLine, colorSpace, kCGImageAlphaPremultipliedFirst);
	
	if (transparentBackground)
	{
		CGContextClearRect(context, CGRectMake(0, 0, width, height));
	}
	else
	{
		CGContextSetRGBFillColor(context, 1, 1, 1, 1); // white
		CGContextFillRect(context, CGRectMake(0, 0, width, height));
	}
	
	// CGPDFPageGetDrawingTransform unfortunately does not upscale, see http://lists.apple.com/archives/quartz-dev/2005/Mar/msg00112.html
	CGAffineTransform drawingTransform = PDFPageGetDrawingTransform(page, kCGPDFCropBox, scale);
	CGContextConcatCTM(context, drawingTransform);
	
	CGContextDrawPDFPage(context, page);
	
	CGImageRef pdfImage = CGBitmapContextCreateImage(context);
	
	CGContextRelease(context);
	CGColorSpaceRelease(colorSpace);
	free(bitmapData);
	
	return pdfImage;
}
开发者ID:0xced,项目名称:pdfrasterize,代码行数:47,代码来源:CGPDFAdditions.c

示例8: createBitmapContextFromWebView

PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool onscreen, bool incrementalRepaint, bool sweepHorizontally, bool drawSelectionRect)
{
    RECT frame;
    if (!GetWindowRect(webViewWindow, &frame))
        return nullptr;

    BITMAPINFO bmp = {0};
    bmp.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmp.bmiHeader.biWidth = frame.right - frame.left;
    bmp.bmiHeader.biHeight = -(frame.bottom - frame.top);
    bmp.bmiHeader.biPlanes = 1;
    bmp.bmiHeader.biBitCount = 32;
    bmp.bmiHeader.biCompression = BI_RGB;

    void* bits = 0;
    HBITMAP bitmap = ::CreateDIBSection(0, &bmp, DIB_RGB_COLORS, &bits, 0, 0);
    if (!bitmap)
        return nullptr;

    auto memoryDC = adoptGDIObject(::CreateCompatibleDC(0));
    ::SelectObject(memoryDC.get(), bitmap);
    SendMessage(webViewWindow, WM_PRINT, reinterpret_cast<WPARAM>(memoryDC.get()), PRF_CLIENT | PRF_CHILDREN | PRF_OWNED);

    BITMAP info = {0};
    GetObject(bitmap, sizeof(info), &info);
    ASSERT(info.bmBitsPixel == 32);

    // We create a context that has an alpha channel below so that the PNGs we generate will also
    // have an alpha channel. But WM_PRINT doesn't necessarily write anything into the alpha
    // channel, so we set the alpha channel to constant full opacity to make sure the resulting image is opaque.
    makeAlphaChannelOpaque(info.bmBits, info.bmWidth, info.bmHeight);

#if USE(CG)
    RetainPtr<CGColorSpaceRef> colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
    CGContextRef context = CGBitmapContextCreate(info.bmBits, info.bmWidth, info.bmHeight, 8,
                                                info.bmWidthBytes, colorSpace.get(), kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
#elif USE(CAIRO) 
    cairo_surface_t* image = cairo_image_surface_create_for_data((unsigned char*)info.bmBits, CAIRO_FORMAT_ARGB32, 
                                                      info.bmWidth, info.bmHeight, info.bmWidthBytes); 
    cairo_t* context = cairo_create(image); 
    cairo_surface_destroy(image); 
#endif 

   return BitmapContext::createByAdoptingBitmapAndContext(bitmap, context);
}
开发者ID:AndriyKalashnykov,项目名称:webkit,代码行数:45,代码来源:PixelDumpSupportWin.cpp

示例9: 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);
}
开发者ID:imclab,项目名称:vrlt,代码行数:18,代码来源:LoadImage.cpp

示例10: draw__new_bitmap

draw__Bitmap draw__new_bitmap(int w, int h) {
  init_if_needed();

  int bytes_per_row = w * 4;
  draw__Bitmap bitmap = CGBitmapContextCreate(NULL,   // data
                                              w,
                                              h,
                                              8,      // bits per component
                                              bytes_per_row,
                                              generic_rgb_colorspace,
                                              (CGBitmapInfo)kCGImageAlphaPremultipliedLast);

  // Make (0, 0) correspond to the lower-left corner.
  CGContextTranslateCTM(bitmap, 0, h);
  CGContextScaleCTM(bitmap, 1.0, -1.0);

  return bitmap;
}
开发者ID:carriercomm,项目名称:gameshell-mac,代码行数:18,代码来源:draw.c

示例11: MCTileCacheCoreGraphicsCompositor_AllocateTile

bool MCTileCacheCoreGraphicsCompositor_AllocateTile(void *p_context, int32_t p_size, const void *p_bits, uint32_t p_stride, void*& r_tile)
{
	MCTileCacheCoreGraphicsCompositorContext *self;
	self = (MCTileCacheCoreGraphicsCompositorContext *)p_context;
	
	// If the stride is exactly one tile wide, we don't need a copy.
	void *t_data;
	t_data = nil;
	if (p_stride == p_size * sizeof(uint32_t))
		t_data = (void *)p_bits;
	else if (MCMemoryAllocate(p_size * p_size * sizeof(uint32_t), t_data))
	{
		// Copy across each scanline of the tile into the buffer.
		for(int32_t y = 0; y < p_size; y++)
			memcpy((uint8_t *)t_data + y * p_size * sizeof(uint32_t), (uint8_t *)p_bits + p_stride * y, p_size * sizeof(uint32_t));
	}
	
	CGImageRef t_tile;
	t_tile = nil;
	if (t_data != nil)
	{
		// IM-2013-08-21: [[ RefactorGraphics ]] Refactor CGImage creation code to be pixel-format independent
		CGBitmapInfo t_bm_info;
		t_bm_info = MCGPixelFormatToCGBitmapInfo(kMCGPixelFormatNative, true);
		
		CGContextRef t_cgcontext;
		t_cgcontext = CGBitmapContextCreate((void *)t_data, p_size, p_size, 8, p_size * sizeof(uint32_t), self -> colorspace, t_bm_info);
		if (t_cgcontext != nil)
		{
			t_tile = CGBitmapContextCreateImage(t_cgcontext);
			CGContextRelease(t_cgcontext);
		}
	}
	
	if (t_data != p_bits)
		MCMemoryDeallocate(t_data);
		
	if (t_tile == nil)
		return false;

	r_tile = t_tile;
	
	return true;
}
开发者ID:alilloyd,项目名称:livecode,代码行数:44,代码来源:tilecachecg.cpp

示例12: allocImage

GDIObject<HBITMAP> allocImage(HDC dc, IntSize size, CGContextRef *targetRef)
{
    BitmapInfo bmpInfo = BitmapInfo::create(size);

    LPVOID bits;
    auto hbmp = adoptGDIObject(::CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0));

    if (!targetRef)
        return hbmp;

    CGContextRef bitmapContext = CGBitmapContextCreate(bits, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, 8,
                                                       bmpInfo.bmiHeader.biWidth * 4, deviceRGBColorSpaceRef(),
                                                       kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
    if (!bitmapContext)
        return GDIObject<HBITMAP>();

    *targetRef = bitmapContext;
    return hbmp;
}
开发者ID:Happy-Ferret,项目名称:webkit.js,代码行数:19,代码来源:DragImageCGWin.cpp

示例13: CFDataGetMutableBytePtr

CGImageRef Image::createAbstraction(float stylization, uint quantization)
{
	pixel4b *rgbPixels = (pixel4b *) CFDataGetMutableBytePtr(_data);
	
	// Convert from RGB to Lab colorspace to perform operations on lightness channel.
	RGBtoLab(rgbPixels, _pixels);
	
	// Initial bilateral filter.
	bilateral();
	
	// Extract edges.
	pixel3f *edges = createEdges(stylization);
	
	// Additional bilateral filtering.
	bilateral();
	bilateral();
	
	// Quantize lightness channel.
	quantize(quantization);
	 
	// Overlay edges.
	overlayEdges(edges);
	 
	// Convert back to RGB colorspace.
	LabtoRGB(_pixels, rgbPixels);
	
	// Create an image from the modified data.
	CGContextRef context = CGBitmapContextCreate(
		rgbPixels,
		_width,
		_height,
		_bitsPerComponent,
		_bytesPerRow,
		_colorSpaceRef,
		_bitmapInfo
	);
	
	CGImageRef image = CGBitmapContextCreateImage(context);
	
	delete[] edges;
	
	return image;
}
开发者ID:NanYoMy,项目名称:ImageAbstraction,代码行数:43,代码来源:Image.cpp

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

示例15: 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;
    }
}
开发者ID:AndriyKalashnykov,项目名称:webkit,代码行数:42,代码来源:BitmapImageCG.cpp


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