コード例 #1
0
ImageInfoPtr ImageInfo::CopyToImageInfo( const wxRect& rect )
{
	ImageInfoPtr result;
	wxRect checkRect = rect;
	checkRect.Intersect( wxRect(0, 0, mIndexMask->GetWidth(), mIndexMask->GetHeight()) );

	if ( !(checkRect.GetWidth() >= 0 && checkRect.GetHeight() >= 0) )
	{
		return result;
	}

	int w = checkRect.GetWidth();
	int h = checkRect.GetHeight();

	size_t size = mPalette->GetCorrectImageSize(w, h, true);
	wxByte* buf = (wxByte*) malloc( size );
	int bytesOnPixel = size / (w * h);

	switch (bytesOnPixel)
	{
		case 1:
			Helpers::CropSubBuffer( buf, w, h, mIndexMask->GetMask(), 
								mIndexMask->GetWidth(), rect.x, rect.y);
		break;

		case 2:
			Helpers::CropSubBuffer<short>((short*) buf, w, h, (const short*) mIndexMask->GetMask(), 
								mIndexMask->GetWidth(), rect.x, rect.y);
		break;

		case 3:
			Helpers::CropSubBuffer<Pixel>((Pixel*)(buf), w, h, 
								(const Pixel*) mIndexMask->GetMask(), 
								mIndexMask->GetWidth(), rect.x, rect.y);
		break;

		case 4:
			Helpers::CropSubBuffer<PixelA>((PixelA*) buf, w, h, (const PixelA*) mIndexMask->GetMask(), 
								mIndexMask->GetWidth(), rect.x, rect.y);
		break;

		default:
			wxLogError( wxString::Format("ImageInfo::CopyToImageInfo: Bytes on pixel = %d", bytesOnPixel));
	}

	
	
	IndexMaskPtr mask = std::make_shared<IndexMask>();
	mask->SetMask( buf, size, w, h );
	free(buf);
	result = std::make_shared<ImageInfo>(mask, mPalette);

	if (!result->IsOk())
	{
		result = nullptr;
	}
	return result;
}
コード例 #2
0
bool ImageInfo::CopyToClipBoard( const wxRect& rect )
{
	ImageInfoPtr newBuffered = CopyToImageInfo( rect );
	bool res = newBuffered->IsOk();

	if (res)
	{
		sBuffered = newBuffered;
		
		wxBitmap* bmp = sBuffered->GetBitmap();
		Helpers::CopyToClipboard(bmp->ConvertToImage());
		delete bmp;
	}

	return res;
}