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


C++ BBitmap::IsValid方法代码示例

本文整理汇总了C++中BBitmap::IsValid方法的典型用法代码示例。如果您正苦于以下问题:C++ BBitmap::IsValid方法的具体用法?C++ BBitmap::IsValid怎么用?C++ BBitmap::IsValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BBitmap的用法示例。


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

示例1: fFrame

OffscreenBitmap::OffscreenBitmap(BRect frame, color_space colorSpace)
	: fFrame(frame)
	, fColorSpace(colorSpace)
	, fStatus(B_ERROR)
	, fBitmap(NULL)
	, fView(NULL)
{
	BBitmap *bitmap = new BBitmap(frame, fColorSpace, true);
	AutoDelete<BBitmap> _bitmap(bitmap);
	if (bitmap == NULL || bitmap->IsValid() == false || bitmap->InitCheck() != B_OK)
		return;
	
	BView *view = new BView(frame, "offscreen", B_FOLLOW_ALL, B_WILL_DRAW);
	AutoDelete<BView> _view(view);
	if (view == NULL)
		return;
	
	bitmap->Lock();
	bitmap->AddChild(view);
	// bitmap is locked during the life time of this object
	
	fBitmap = _bitmap.Release();
	fView = _view.Release();
	fStatus = B_OK;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:25,代码来源:PictureTest.cpp

示例2: new

status_t
BIconButton::SetIcon(const BMimeType* fileType, bool small)
{
	status_t status = fileType ? fileType->InitCheck() : B_BAD_VALUE;
	if (status >= B_OK) {
		BBitmap* mimeBitmap = new(std::nothrow) BBitmap(BRect(0.0, 0.0, 15.0,
			15.0), B_CMAP8);
		if (mimeBitmap && mimeBitmap->IsValid()) {
			status = fileType->GetIcon(mimeBitmap, small ? B_MINI_ICON
				: B_LARGE_ICON);
			if (status >= B_OK) {
				if (BBitmap* bitmap = _ConvertToRGB32(mimeBitmap)) {
					status = _MakeBitmaps(bitmap);
					delete bitmap;
				} else {
					printf("BIconButton::SetIcon() - B_RGB32 bitmap is not "
						"valid\n");
				}
			} else {
				printf("BIconButton::SetIcon() - fileType->GetIcon() failed: "
					"%s\n", strerror(status));
			}
		} else
			printf("BIconButton::SetIcon() - B_CMAP8 bitmap is not valid\n");
		delete mimeBitmap;
	} else {
		printf("BIconButton::SetIcon() - fileType is not valid: %s\n",
			strerror(status));
	}
	return status;
}
开发者ID:Barrett17,项目名称:Faber,代码行数:31,代码来源:IconButton.cpp

示例3: r

BBitmap *
TransportButton::MakeBitmap(uint32 mask)
{
    BRect r(Bounds());
    BBitmap *result = new BBitmap(r, B_CMAP8);

    uint8* src = (uint8*)BitsForMask(mask);

    if (src && result && result->IsValid()) {
        // int32 width = r.IntegerWidth() + 1;
        int32 height = r.IntegerHeight() + 1;
        int32 bpr = result->BytesPerRow();
        uint8* dst = (uint8*)result->Bits();
        // copy source bits into bitmap line by line,
        // taking possible alignment into account
        // since the source data has been generated
        // by QuickRes, it still contains aligment too
        // (hence skipping bpr and not width bytes)
        for (int32 y = 0; y < height; y++) {
            memcpy(dst, src, bpr);
            src += bpr;
            dst += bpr;
        }
        ReplaceTransparentColor(result, Parent()->ViewColor());
    } else {
        delete result;
        result = NULL;
    }
    
    return result;
}
开发者ID:FLYKingdom,项目名称:vlc,代码行数:31,代码来源:TransportButton.cpp

示例4: view

BBitmap*
PictureView::_CopyPicture(uint8 alpha)
{
	bool hasAlpha = alpha != 255;

	if (!fPicture)
		return NULL;

	BRect rect = fPictureRect.OffsetToCopy(B_ORIGIN);
	BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW);
	BBitmap* bitmap = new(nothrow) BBitmap(rect, hasAlpha ? B_RGBA32
		: fPicture->ColorSpace(), true);
	if (bitmap == NULL || !bitmap->IsValid()) {
		delete bitmap;
		return NULL;
	}

	if (bitmap->Lock()) {
		bitmap->AddChild(&view);
		if (hasAlpha) {
			view.SetHighColor(0, 0, 0, 0);
			view.FillRect(rect);
			view.SetDrawingMode(B_OP_ALPHA);
			view.SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);
			view.SetHighColor(0, 0, 0, alpha);
		}
		view.DrawBitmap(fPicture, fPicture->Bounds().OffsetToCopy(B_ORIGIN),
			rect, B_FILTER_BITMAP_BILINEAR);
		view.Sync();
		bitmap->RemoveChild(&view);
		bitmap->Unlock();
	}

	return bitmap;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:35,代码来源:PictureView.cpp

示例5: new

// SetIcon
status_t
IconButton::SetIcon(const unsigned char* bitsFromQuickRes,
                    uint32 width, uint32 height, color_space format, bool convertToBW)
{
    status_t status = B_BAD_VALUE;
    if (bitsFromQuickRes && width > 0 && height > 0) {
        BBitmap* quickResBitmap = new(nothrow) BBitmap(BRect(0.0, 0.0, width - 1.0, height - 1.0), format);
        status = quickResBitmap ? quickResBitmap->InitCheck() : B_ERROR;
        if (status >= B_OK) {
            // It doesn't look right to copy BitsLength() bytes, but bitmaps
            // exported from QuickRes still contain their padding, so it is alright.
            memcpy(quickResBitmap->Bits(), bitsFromQuickRes, quickResBitmap->BitsLength());
            if (format != B_RGB32 && format != B_RGBA32 && format != B_RGB32_BIG && format != B_RGBA32_BIG) {
                // colorspace needs conversion
                BBitmap* bitmap = new(nothrow) BBitmap(quickResBitmap->Bounds(), B_RGB32, true);
                if (bitmap && bitmap->IsValid()) {
                    BView* helper = new BView(bitmap->Bounds(), "helper",
                                              B_FOLLOW_NONE, B_WILL_DRAW);
                    if (bitmap->Lock()) {
                        bitmap->AddChild(helper);
                        helper->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
                        helper->FillRect(helper->Bounds());
                        helper->SetDrawingMode(B_OP_OVER);
                        helper->DrawBitmap(quickResBitmap, BPoint(0.0, 0.0));
                        helper->Sync();
                        bitmap->Unlock();
                    }
                    status = _MakeBitmaps(bitmap);
                } else
                    printf("IconButton::SetIcon() - B_RGB32 bitmap is not valid\n");
                delete bitmap;
            } else {
                // native colorspace (32 bits)
                if (convertToBW) {
                    // convert to gray scale icon
                    uint8* bits = (uint8*)quickResBitmap->Bits();
                    uint32 bpr = quickResBitmap->BytesPerRow();
                    for (uint32 y = 0; y < height; y++) {
                        uint8* handle = bits;
                        uint8 gray;
                        for (uint32 x = 0; x < width; x++) {
                            gray = uint8((116 * handle[0] + 600 * handle[1] + 308 * handle[2]) / 1024);
                            handle[0] = gray;
                            handle[1] = gray;
                            handle[2] = gray;
                            handle += 4;
                        }
                        bits += bpr;
                    }
                }
                status = _MakeBitmaps(quickResBitmap);
            }
        } else
            printf("IconButton::SetIcon() - error allocating bitmap: %s\n", strerror(status));
        delete quickResBitmap;
    }
    return status;
}
开发者ID:mmanley,项目名称:Antares,代码行数:59,代码来源:IconButton.cpp

示例6: new

BBitmap*
BIcon::CopyBitmap(const BBitmap& bitmapToClone, uint32 which)
{
	BBitmap* bitmap = new(std::nothrow) BBitmap(bitmapToClone);
	if (bitmap == NULL || !bitmap->IsValid() || !SetBitmap(bitmap, which)) {
		delete bitmap;
		return NULL;
	}

	return bitmap;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:11,代码来源:Icon.cpp

示例7: create_img

 //------------------------------------------------------------------------
 bool platform_support::create_img(unsigned idx, unsigned width, unsigned height)
 {
     if(idx < max_images)
     {
         if(width  == 0) width  = m_specific->fApp->Window()->View()->Bitmap()->Bounds().IntegerWidth() + 1;
         if(height == 0) height = m_specific->fApp->Window()->View()->Bitmap()->Bounds().IntegerHeight() + 1;
         BBitmap* bitmap = new BBitmap(BRect(0.0, 0.0, width - 1, height - 1), 0, B_RGBA32);;
         if (bitmap && bitmap->IsValid()) {
             delete m_specific->fImages[idx];
             m_specific->fImages[idx] = bitmap;
             attach_buffer_to_BBitmap(m_rbuf_img[idx], bitmap, m_flip_y);
             return true;
         } else {
             delete bitmap;
         }
     }
     return false;
 }
开发者ID:Rodeo314,项目名称:vasFMC,代码行数:19,代码来源:agg_platform_support.cpp

示例8: BBitmap

BBitmap*
OffscreenBitmap::Copy()
{
	// the result bitmap that does not accept views	
	// to save resources in the application server
	BBitmap *copy = new BBitmap(fFrame, fColorSpace, false);
	AutoDelete<BBitmap> _copy(copy);
	if (copy == NULL || copy->IsValid() == false || copy->InitCheck() != B_OK)
		return NULL;

	fView->Sync();
	fBitmap->Unlock();
	
	memcpy(copy->Bits(), fBitmap->Bits(), fBitmap->BitsLength());	
	
	fBitmap->Lock();

	return _copy.Release();
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:19,代码来源:PictureTest.cpp

示例9: r

void
BIconButton::Draw(BRect updateRect)
{
	rgb_color background;
	if (fCustomBackground)
		background = {120,120,120};
	else
		background = LowColor();

	BRect r(Bounds());

	uint32 flags = 0;
	BBitmap* bitmap = fNormalBitmap;
	if (!IsEnabled()) {
		flags |= BControlLook::B_DISABLED;
		bitmap = fDisabledBitmap;
	}
	if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED))
		flags |= BControlLook::B_ACTIVATED;

	if (ShouldDrawBorder()) {
		DrawBorder(r, updateRect, background, flags);
		DrawBackground(r, updateRect, background, flags);
	} else {
		SetHighColor(background);
		FillRect(r);
	}

	if (bitmap && bitmap->IsValid()) {
		if (bitmap->ColorSpace() == B_RGBA32
			|| bitmap->ColorSpace() == B_RGBA32_BIG) {
			SetDrawingMode(B_OP_ALPHA);
			SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
		}
		float x = r.left + floorf((r.Width()
			- bitmap->Bounds().Width()) / 2.0 + 0.5);
		float y = r.top + floorf((r.Height()
			- bitmap->Bounds().Height()) / 2.0 + 0.5);
		DrawBitmap(bitmap, BPoint(x, y));
	}
}
开发者ID:Barrett17,项目名称:Faber,代码行数:41,代码来源:IconButton.cpp

示例10: FrameResized

void CounterView::FrameResized (float width, float height)
{
  BRect BitmapRect (0, 0, width, height);
  char  TempString [40];

  m_BndRect = Bounds ();

  m_MovingDotSize = (int) (height / 20);
  if (m_MovingDotSize < 1)
    m_MovingDotSize = 1;
  m_MoveSpeed = m_MovingDotSize / 2.0;
  
  // Resize the offscreen bitmap and its view.

  if (m_BackingBitmap != NULL)
  {
    m_BackingBitmap->RemoveChild (&m_BackingView);
    delete m_BackingBitmap;
    m_BackingBitmap = NULL;
  }

  m_BackingView.ResizeTo (width, height);

  m_BackingBitmap = new BBitmap (BitmapRect, B_RGBA32, true /* Accepts subviews */);
  if (!m_BackingBitmap->IsValid ())
  {
    delete m_BackingBitmap;
    m_BackingBitmap = NULL;
  }
  else
  {
    m_BackingBitmap->AddChild (&m_BackingView);
    m_BackingBitmap->Lock ();
    m_BackingView.SetDrawingMode (B_OP_ALPHA);
    m_BackingView.SetFontSize (height * 0.8);
    sprintf (TempString, "%d", m_CurrentCount);
    m_TextStartPoint.x = width / 2 - m_BackingView.StringWidth (TempString) / 2;
    m_TextStartPoint.y = height / 2 + height * 0.25;
    m_BackingBitmap->Unlock ();
  }
}
开发者ID:kallisti5,项目名称:VNCServer,代码行数:41,代码来源:UserAppMessageMonitor.cpp

示例11: r

void
AGGView::FrameResized(float width, float height)
{
    BRect r(0.0, 0.0, width, height);
    BBitmap* bitmap = new BBitmap(r, 0, pix_format_to_color_space(fFormat));
    if (bitmap->IsValid()) {
        delete fBitmap;
        fBitmap = bitmap;
           attach_buffer_to_BBitmap(fAGG->rbuf_window(), fBitmap, fFlipY);

        fAGG->trans_affine_resizing((int)width + 1,
                                    (int)height + 1);

        // pass the event on to AGG
        fAGG->on_resize((int)width + 1, (int)height + 1);
        
        fRedraw = true;
        Invalidate();
    } else
        delete bitmap;
}
开发者ID:Rodeo314,项目名称:vasFMC,代码行数:21,代码来源:agg_platform_support.cpp

示例12: string

bool
ClipView::InitiateDrag(BPoint point, int32 index, bool wasSelected)
{
	ClipItem* sItem = dynamic_cast<ClipItem *> (ItemAt(index));
	if (sItem == NULL)
		return false;

	BString string(sItem->GetClip());
	BMessage message(FAV_ADD);
	message.AddData("text/plain", B_MIME_TYPE, string, string.Length());
	message.AddPointer("clip", sItem);

	BRect dragRect(0.0f, 0.0f, Bounds().Width(), sItem->Height());
	BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
	if (dragBitmap->IsValid()) {
		BView* view = new BView(dragBitmap->Bounds(), "helper", B_FOLLOW_NONE,
			B_WILL_DRAW);
		dragBitmap->AddChild(view);
		dragBitmap->Lock();

		sItem->DrawItem(view, dragRect);
		view->SetHighColor(0, 0, 0, 255);
		view->StrokeRect(view->Bounds());
		view->Sync();

		dragBitmap->Unlock();
	} else {
		delete dragBitmap;
		dragBitmap = NULL;
	}

	if (dragBitmap != NULL)
		DragMessage(&message, dragBitmap, B_OP_ALPHA, BPoint(0.0, 0.0));
	else
		DragMessage(&message, dragRect.OffsetToCopy(point), this);

	return true;
}
开发者ID:humdingerb,项目名称:clipdinger,代码行数:38,代码来源:ClipView.cpp

示例13:

BBitmap::BBitmap(const BBitmap& source, uint32 flags)
	:
	fBasePointer(NULL),
	fSize(0),
	fColorSpace(B_NO_COLOR_SPACE),
	fBounds(0, 0, -1, -1),
	fBytesPerRow(0),
	fWindow(NULL),
	fServerToken(-1),
	fAreaOffset(-1),
	fArea(-1),
	fServerArea(-1),
	fFlags(0),
	fInitError(B_NO_INIT)
{
	if (!source.IsValid())
		return;

	_InitObject(source.Bounds(), source.ColorSpace(), flags,
		source.BytesPerRow(), B_MAIN_SCREEN_ID);

	if (InitCheck() == B_OK)
		memcpy(Bits(), source.Bits(), min_c(BitsLength(), source.BitsLength()));
}
开发者ID:orangejua,项目名称:haiku,代码行数:24,代码来源:Bitmap.cpp

示例14: dragRect

bool
LanguageListView::InitiateDrag(BPoint point, int32 dragIndex,
	bool /*wasSelected*/)
{
	if (fDragMessage == NULL)
		return false;

	BListItem* item = ItemAt(CurrentSelection(0));
	if (item == NULL) {
		// workaround for a timing problem
		// TODO: this should support extending the selection
		item = ItemAt(dragIndex);
		Select(dragIndex);
	}
	if (item == NULL)
		return false;

	// create drag message
	BMessage message = *fDragMessage;
	message.AddPointer("listview", this);

	for (int32 i = 0;; i++) {
		int32 index = CurrentSelection(i);
		if (index < 0)
			break;

		message.AddInt32("index", index);
	}

	// figure out drag rect

	BRect dragRect(0.0, 0.0, Bounds().Width(), -1.0);
	int32 numItems = 0;
	bool fade = false;

	// figure out, how many items fit into our bitmap
	for (int32 i = 0, index; message.FindInt32("index", i, &index) == B_OK;
			i++) {
		BListItem* item = ItemAt(index);
		if (item == NULL)
			break;

		dragRect.bottom += ceilf(item->Height()) + 1.0;
		numItems++;

		if (dragRect.Height() > MAX_DRAG_HEIGHT) {
			dragRect.bottom = MAX_DRAG_HEIGHT;
			fade = true;
			break;
		}
	}

	BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
	if (dragBitmap->IsValid()) {
		BView* view = new BView(dragBitmap->Bounds(), "helper", B_FOLLOW_NONE,
			B_WILL_DRAW);
		dragBitmap->AddChild(view);
		dragBitmap->Lock();
		BRect itemBounds(dragRect) ;
		itemBounds.bottom = 0.0;
		// let all selected items, that fit into our drag_bitmap, draw
		for (int32 i = 0; i < numItems; i++) {
			int32 index = message.FindInt32("index", i);
			LanguageListItem* item
				= static_cast<LanguageListItem*>(ItemAt(index));
			itemBounds.bottom = itemBounds.top + ceilf(item->Height());
			if (itemBounds.bottom > dragRect.bottom)
				itemBounds.bottom = dragRect.bottom;
			item->DrawItem(view, itemBounds);
			itemBounds.top = itemBounds.bottom + 1.0;
		}
		// make a black frame arround the edge
		view->SetHighColor(0, 0, 0, 255);
		view->StrokeRect(view->Bounds());
		view->Sync();

		uint8* bits = (uint8*)dragBitmap->Bits();
		int32 height = (int32)dragBitmap->Bounds().Height() + 1;
		int32 width = (int32)dragBitmap->Bounds().Width() + 1;
		int32 bpr = dragBitmap->BytesPerRow();

		if (fade) {
			for (int32 y = 0; y < height - ALPHA / 2; y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = ALPHA;
			}
			for (int32 y = height - ALPHA / 2; y < height;
				y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = (height - y) << 1;
			}
		} else {
			for (int32 y = 0; y < height; y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = ALPHA;
			}
		}
//.........这里部分代码省略.........
开发者ID:veer77,项目名称:Haiku-services-branch,代码行数:101,代码来源:LanguageListView.cpp

示例15: load_img

    //------------------------------------------------------------------------
    bool platform_support::load_img(unsigned idx, const char* file)
    {
        if (idx < max_images)
        {
            char path[B_PATH_NAME_LENGTH];
            sprintf(path, "%s/%s%s", m_specific->fAppPath, file, img_ext());
            BBitmap* transBitmap = BTranslationUtils::GetBitmap(path);
            if (transBitmap && transBitmap->IsValid()) {
                if(transBitmap->ColorSpace() != B_RGB32 && transBitmap->ColorSpace() != B_RGBA32) {
                    // ups we got a smart ass Translator making our live harder
                    delete transBitmap;
                    return false;
                }

                color_space format = B_RGB24;

                switch (m_format) {
                    case pix_format_gray8:
                        format = B_GRAY8;
                        break;
                    case pix_format_rgb555:
                        format = B_RGB15;
                        break;
                    case pix_format_rgb565:
                        format = B_RGB16;
                        break;
                    case pix_format_rgb24:
                        format = B_RGB24_BIG;
                        break;
                    case pix_format_bgr24:
                        format = B_RGB24;
                        break;
                    case pix_format_abgr32:
                    case pix_format_argb32:
                    case pix_format_bgra32:
                        format = B_RGB32;
                        break;
                    case pix_format_rgba32:
                        format = B_RGB32_BIG;
                        break;
                }
                BBitmap* bitmap = new (nothrow) BBitmap(transBitmap->Bounds(), 0, format);
                if (!bitmap || !bitmap->IsValid()) {
                    fprintf(stderr, "failed to allocate temporary bitmap!\n");
                    delete transBitmap;
                    delete bitmap;
                    return false;
                }

                delete m_specific->fImages[idx];

                rendering_buffer rbuf_tmp;
                attach_buffer_to_BBitmap(rbuf_tmp, transBitmap, m_flip_y);
        
                m_specific->fImages[idx] = bitmap;
        
                attach_buffer_to_BBitmap(m_rbuf_img[idx], bitmap, m_flip_y);
        
                rendering_buffer* dst = &m_rbuf_img[idx];

                switch(m_format)
                {
                case pix_format_gray8:
                    return false;
//                  color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_gray8()); break;
                    break;
        
                case pix_format_rgb555:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb555()); break;
                    break;
        
                case pix_format_rgb565:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb565()); break;
                    break;
        
                case pix_format_rgb24:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb24()); break;
                    break;
        
                case pix_format_bgr24:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgr24()); break;
                    break;
        
                case pix_format_abgr32:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_abgr32()); break;
                    break;
        
                case pix_format_argb32:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_argb32()); break;
                    break;
        
                case pix_format_bgra32:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgra32()); break;
                    break;
        
                case pix_format_rgba32:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgba32()); break;
                    break;
                }
//.........这里部分代码省略.........
开发者ID:Rodeo314,项目名称:vasFMC,代码行数:101,代码来源:agg_platform_support.cpp


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