本文整理汇总了C++中gdiplus::Bitmap::UnlockBits方法的典型用法代码示例。如果您正苦于以下问题:C++ Bitmap::UnlockBits方法的具体用法?C++ Bitmap::UnlockBits怎么用?C++ Bitmap::UnlockBits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gdiplus::Bitmap
的用法示例。
在下文中一共展示了Bitmap::UnlockBits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
Gdiplus::Bitmap* GdiplusUtilities::FromHICON32(HICON hIcon)
{
Gdiplus::Bitmap* ret = NULL;
ICONINFO iconInfo;
GetIconInfo(hIcon, &iconInfo);
BITMAP bitmapData;
GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bitmapData);
if (bitmapData.bmBitsPixel != 32)
ret = Gdiplus::Bitmap::FromHICON(hIcon);
else
{
ret = new Gdiplus::Bitmap(bitmapData.bmWidth, bitmapData.bmHeight, PixelFormat32bppARGB);
Gdiplus::BitmapData bmpData;
ret->LockBits(&Gdiplus::Rect(0,0,bitmapData.bmWidth, bitmapData.bmHeight), Gdiplus::ImageLockModeWrite, PixelFormat32bppARGB, &bmpData);
#ifndef GetDIBitsVERSION
//===Version GetBitmapBits
// THIS FUNCTION IS UNDER TESTING. WHAT IF THE bitmap stride is different? Where will the new data go?
ASSERT(bmpData.Stride == bmpData.Width * 4);
::GetBitmapBits(iconInfo.hbmColor, 4 * bitmapData.bmWidth * bitmapData.bmHeight, bmpData.Scan0);
//===Version GetBitmapBits===END
#else
//===Version GetDIBits (incomplete)
::GetDIBits(GetDC(), iconInfo.hbmColor, 0, bitmapData.bm)
//===Version GetDIBits
#endif
ret->UnlockBits(&bmpData);
}
DeleteObject(iconInfo.hbmColor);
DeleteObject(iconInfo.hbmMask);
return ret;
}
示例2: convertGdiplusBitmap
Surface8u convertGdiplusBitmap( Gdiplus::Bitmap &bitmap )
{
Gdiplus::BitmapData bitmapData;
Gdiplus::Rect rect( 0, 0, bitmap.GetWidth(), bitmap.GetHeight() );
Gdiplus::PixelFormat requestedFormat = bitmap.GetPixelFormat();
SurfaceChannelOrder sco;
bool premult;
gdiplusPixelFormatToSurfaceChannelOrder( requestedFormat, &sco, &premult );
if( sco == SurfaceChannelOrder::UNSPECIFIED ) {
UINT flags = bitmap.GetFlags();
sco = ( flags & Gdiplus::ImageFlagsHasAlpha ) ? SurfaceChannelOrder::BGRA : SurfaceChannelOrder::BGR;
requestedFormat = ( flags & Gdiplus::ImageFlagsHasAlpha ) ? PixelFormat32bppARGB : PixelFormat24bppRGB;
}
bitmap.LockBits( &rect, Gdiplus::ImageLockModeRead, requestedFormat, &bitmapData );
Surface8u result( bitmap.GetWidth(), bitmap.GetHeight(), sco.hasAlpha(), sco );
const uint8_t *srcDataBase = (uint8_t*)bitmapData.Scan0;
int32_t width = bitmap.GetWidth();
for( uint32_t y = 0; y < bitmap.GetHeight(); ++y ) {
memcpy( result.getData( Vec2i( 0, y ) ), srcDataBase + y * bitmapData.Stride, width * result.getPixelInc() );
}
bitmap.UnlockBits( &bitmapData );
return result;
}
示例3: Gdip_RemoveAlpha
// hack for stupid GDIplus
void Gdip_RemoveAlpha(Gdiplus::Bitmap& source, Gdiplus::Color color )
{
using namespace Gdiplus;
Rect r( 0, 0, source.GetWidth(),source.GetHeight() );
BitmapData bdSrc;
source.LockBits( &r, ImageLockModeRead , PixelFormat32bppARGB,&bdSrc);
BYTE* bpSrc = (BYTE*)bdSrc.Scan0;
//bpSrc += (int)sourceChannel;
for ( int i = r.Height * r.Width; i > 0; i-- )
{
BGRA_COLOR * c = (BGRA_COLOR *)bpSrc;
if(c->a!=255)
{
//c = 255;
DWORD * d= (DWORD*)bpSrc;
*d= color.ToCOLORREF();
c ->a= 255;
}
bpSrc += 4;
}
source.UnlockBits( &bdSrc );
}
示例4: CreateAtlasTexture
//---------------------------------------------------------------------------
HRESULT CreateAtlasTexture(ID3D11Device* device, Gdiplus::Bitmap& fontSheetBitmap, const FontAtlasSizeInfo* pSizeInfo,
ID3D11Texture2D** ppD3dTexture, ID3D11ShaderResourceView** ppD3dShaderResourceView )
{
using namespace Gdiplus;
HRESULT hr = S_OK;
// Lock the bitmap for direct memory access
BitmapData bmData;
Rect rect(0, 0, pSizeInfo->atlasTextureWidth, pSizeInfo->atlasTextureHeight );
fontSheetBitmap.LockBits(&rect,ImageLockModeRead, PixelFormat32bppARGB, &bmData);
// Copy into a texture.
D3D11_TEXTURE2D_DESC texDesc;
texDesc.Width = pSizeInfo->atlasTextureWidth;
texDesc.Height = pSizeInfo->atlasTextureHeight;
texDesc.MipLevels = 1;
texDesc.ArraySize = 1;
texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D11_USAGE_IMMUTABLE;
texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texDesc.CPUAccessFlags = 0;
texDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA data;
data.pSysMem = bmData.Scan0;
data.SysMemPitch = pSizeInfo->atlasTextureWidth * 4;
data.SysMemSlicePitch = 0;
hr = device->CreateTexture2D(&texDesc, &data, ppD3dTexture );
if(FAILED(hr))
return hr;
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = 1;
srvDesc.Texture2D.MostDetailedMip = 0;
hr = device->CreateShaderResourceView(*ppD3dTexture, &srvDesc, ppD3dShaderResourceView );
if(FAILED(hr))
return hr;
fontSheetBitmap.UnlockBits(&bmData);
return hr;
}
示例5: convertGdiplusBitmap
Surface8u convertGdiplusBitmap( Gdiplus::Bitmap &bitmap, bool premultiplied )
{
Gdiplus::BitmapData bitmapData;
Gdiplus::Rect rect( 0, 0, bitmap.GetWidth(), bitmap.GetHeight() );
bitmap.LockBits( &rect, Gdiplus::ImageLockModeRead, (premultiplied) ? PixelFormat32bppPARGB : PixelFormat32bppARGB, &bitmapData );
Surface8u result( bitmap.GetWidth(), bitmap.GetHeight(), true, SurfaceChannelOrder::BGRA );
const uint8_t *srcDataBase = (uint8_t*)bitmapData.Scan0;
int32_t width = bitmap.GetWidth();
for( uint32_t y = 0; y < bitmap.GetHeight(); ++y ) {
memcpy( result.getData( Vec2i( 0, y ) ), srcDataBase + y * bitmapData.Stride, width * 4 );
}
bitmap.UnlockBits( &bitmapData );
return result;
}
示例6: BuildFontSheetTexture
bool DxFont::BuildFontSheetTexture(Gdiplus::Bitmap & fontSheetBitmap)
{
Gdiplus::BitmapData bmData;
fontSheetBitmap.LockBits(&Gdiplus::Rect(0, 0, TexWidth, TexHeight ), Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bmData);
D3D11_TEXTURE2D_DESC texDesc;
texDesc.Width = TexWidth;
texDesc.Height = TexHeight;
texDesc.MipLevels = 1;
texDesc.ArraySize = 1;
texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D11_USAGE_IMMUTABLE;
texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texDesc.CPUAccessFlags = 0;
texDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA data;
data.pSysMem = bmData.Scan0;
data.SysMemPitch = TexWidth * 4;
data.SysMemSlicePitch = 0;
if(FAILED(Globals::Get().device.m_device->CreateTexture2D(&texDesc, &data, &FontSheetTex )))
assert(false);
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = 1;
srvDesc.Texture2D.MostDetailedMip = 0;
if(FAILED(Globals::Get().device.m_device->CreateShaderResourceView(FontSheetTex, &srvDesc, &FontSheetSRV)))
assert(false);
fontSheetBitmap.UnlockBits(&bmData);
return true;
}
示例7: loadImage
void* BaseManager::loadImage(int& _width, int& _height, MyGUI::PixelFormat& _format, const std::string& _filename)
{
std::string fullname = MyGUI::OpenGL3DataManager::getInstance().getDataPath(_filename);
void* result = 0;
Gdiplus::Bitmap* image = Gdiplus::Bitmap::FromFile(MyGUI::UString(fullname).asWStr_c_str());
if (image)
{
_width = image->GetWidth();
_height = image->GetHeight();
Gdiplus::PixelFormat format = image->GetPixelFormat();
if (format == PixelFormat24bppRGB)
_format = MyGUI::PixelFormat::R8G8B8;
else if (format == PixelFormat32bppARGB)
_format = MyGUI::PixelFormat::R8G8B8A8;
else
_format = MyGUI::PixelFormat::Unknow;
if (_format != MyGUI::PixelFormat::Unknow)
{
Gdiplus::Rect rect(0, 0, _width, _height);
Gdiplus::BitmapData out_data;
image->LockBits(&rect, Gdiplus::ImageLockModeRead, format, &out_data);
size_t size = out_data.Height * out_data.Stride;
result = new unsigned char[size];
convertRawData(&out_data, result, size, _format);
image->UnlockBits(&out_data);
}
delete image;
}
return result;
}
示例8: assert
//.........这里部分代码省略.........
token;
unsigned char
*p;
wchar_t
fileName[MagickPathExtent];
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
image=AcquireImage(image_info,exception);
if (Gdiplus::GdiplusStartup(&token,&startup_input,NULL) !=
Gdiplus::Status::Ok)
ThrowReaderException(CoderError, "GdiplusStartupFailed");
MultiByteToWideChar(CP_UTF8,0,image->filename,-1,fileName,MagickPathExtent);
source=Gdiplus::Image::FromFile(fileName);
if (source == (Gdiplus::Image *) NULL)
{
Gdiplus::GdiplusShutdown(token);
ThrowReaderException(FileOpenError,"UnableToOpenFile");
}
image->resolution.x=source->GetHorizontalResolution();
image->resolution.y=source->GetVerticalResolution();
image->columns=(size_t) source->GetWidth();
image->rows=(size_t) source->GetHeight();
if (image_info->density != (char *) NULL)
{
flags=ParseGeometry(image_info->density,&geometry_info);
image->resolution.x=geometry_info.rho;
image->resolution.y=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
image->resolution.y=image->resolution.x;
if ((image->resolution.x > 0.0) && (image->resolution.y > 0.0))
{
image->columns=(size_t) floor((Gdiplus::REAL) source->GetWidth() /
source->GetHorizontalResolution() * image->resolution.x + 0.5);
image->rows=(size_t)floor((Gdiplus::REAL) source->GetHeight() /
source->GetVerticalResolution() * image->resolution.y + 0.5);
}
}
bitmap=new Gdiplus::Bitmap((INT) image->columns,(INT) image->rows,
PixelFormat32bppARGB);
graphics=Gdiplus::Graphics::FromImage(bitmap);
graphics->SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
graphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
graphics->SetTextRenderingHint(Gdiplus::TextRenderingHintClearTypeGridFit);
graphics->Clear(Gdiplus::Color((BYTE) ScaleQuantumToChar(
image->background_color.alpha),(BYTE) ScaleQuantumToChar(
image->background_color.red),(BYTE) ScaleQuantumToChar(
image->background_color.green),(BYTE) ScaleQuantumToChar(
image->background_color.blue)));
graphics->DrawImage(source,0,0,(INT) image->columns,(INT) image->rows);
delete graphics;
delete source;
rect=Gdiplus::Rect(0,0,(INT) image->columns,(INT) image->rows);
if (bitmap->LockBits(&rect,Gdiplus::ImageLockModeRead,PixelFormat32bppARGB,
&bitmap_data) != Gdiplus::Ok)
{
delete bitmap;
Gdiplus::GdiplusShutdown(token);
ThrowReaderException(FileOpenError,"UnableToReadImageData");
}
image->alpha_trait=BlendPixelTrait;
for (y=0; y < (ssize_t) image->rows; y++)
{
p=(unsigned char *) bitmap_data.Scan0+(y*abs(bitmap_data.Stride));
if (bitmap_data.Stride < 0)
q=GetAuthenticPixels(image,0,image->rows-y-1,image->columns,1,exception);
else
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
SetPixelRed(image,ScaleCharToQuantum(*p++),q);
SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
bitmap->UnlockBits(&bitmap_data);
delete bitmap;
Gdiplus::GdiplusShutdown(token);
return(image);
}
示例9: initWithEncodedData
//.........这里部分代码省略.........
HGLOBAL hGlobal = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, (SIZE_T)size);
if (!hGlobal)
return false;
BYTE* pDest = (BYTE*)::GlobalLock(hGlobal);
memcpy(pDest, bufferData, size);
::GlobalUnlock(hGlobal);
IStream* pStream = NULL;
if (::CreateStreamOnHGlobal(hGlobal, FALSE, &pStream) != S_OK)
return false;
Gdiplus::Bitmap* bitmap = Gdiplus::Bitmap::FromStream(pStream);
bitmap->RotateFlip(Gdiplus::RotateNoneFlipY);
this->imageRect.width = bitmap->GetWidth();
this->imageRect.height = bitmap->GetHeight();
VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
this->useRectExtension = theVisualGraphics->canUseTextureRectExtension();
if (this->useRectExtension == false) {
this->textureRect.width = theVisualGraphics->power2Ceiling(this->imageRect.width);
this->textureRect.height = theVisualGraphics->power2Ceiling(this->imageRect.height);
} else {
this->textureRect.width = this->imageRect.width;
this->textureRect.height = this->imageRect.height;
}
aPixelBuffer = (uint32*)malloc(this->imageRect.width * this->imageRect.height * sizeof(uint32));
Gdiplus::Rect rect(0, 0, this->imageRect.width, this->imageRect.height);
Gdiplus::BitmapData* bitmapData = new Gdiplus::BitmapData;
bitmapData->Width = this->imageRect.width;
bitmapData->Height = this->imageRect.height;
bitmapData->Stride = sizeof(uint32) * bitmapData->Width;
bitmapData->PixelFormat = PixelFormat32bppARGB;
bitmapData->Scan0 = (VOID*)aPixelBuffer;
Gdiplus::Status status = Gdiplus::Ok;
status = bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeUserInputBuf, PixelFormat32bppPARGB, bitmapData);
#endif
#if TARGET_OS_MAC
CFDataRef dataRef = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, (UInt8*)bufferData, (CFIndex)size, kCFAllocatorDefault);
CFDictionaryRef options = NULL;
CGImageSourceRef imageSourceRef = CGImageSourceCreateWithData(dataRef, options);
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSourceRef, 0, options);
this->imageRect.width = CGImageGetWidth(imageRef);
this->imageRect.height = CGImageGetHeight(imageRef);
VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
this->useRectExtension = theVisualGraphics->canUseTextureRectExtension();
if (this->useRectExtension == false) {
this->textureRect.width = theVisualGraphics->power2Ceiling(this->imageRect.width);
this->textureRect.height = theVisualGraphics->power2Ceiling(this->imageRect.height);
} else {
this->textureRect.width = this->imageRect.width;
this->textureRect.height = this->imageRect.height;
}
CGContextRef contextPtr = theVisualGraphics->createBitmapContext(this->imageRect.width, this->imageRect.height);
CGContextTranslateCTM(contextPtr, 0, this->imageRect.height);
CGContextScaleCTM(contextPtr, 1.0f, -1.0f);
CGRect rect = CGRectMake(0, 0, this->imageRect.width, this->imageRect.height);
CGContextDrawImage(contextPtr, rect, imageRef);
aPixelBuffer = static_cast<uint32*>(CGBitmapContextGetData(contextPtr));
#endif
PixelColor* interleavedARGBColorPixelBuffer = NULL;
if (debug == true) {
interleavedARGBColorPixelBuffer = VisualColorTools::createARGBCheckPixels(this->textureRect.width, this->textureRect.height);
} else {
interleavedARGBColorPixelBuffer = static_cast<PixelColor*>(aPixelBuffer);
}
success = this->initWithARGBPixelData(interleavedARGBColorPixelBuffer, this->imageRect.width, this->imageRect.height);
#if TARGET_OS_MAC
CGContextRelease(contextPtr);
CGImageRelease(imageRef);
#endif
#if TARGET_OS_WIN
bitmap->UnlockBits(bitmapData);
#endif
return success;
}
示例10: LoadTexture
//*************************************************************************************************************
GLuint LoadTexture(const std::wstring& file)
{
GLuint texid = 0;
Gdiplus::Bitmap* bitmap = LoadPicture(file);
if( bitmap )
{
if( bitmap->GetLastStatus() == Gdiplus::Ok )
{
Gdiplus::BitmapData data;
unsigned char* tmpbuff;
bitmap->LockBits(0, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &data);
tmpbuff = new unsigned char[data.Width * data.Height * 4];
memcpy(tmpbuff, data.Scan0, data.Width * data.Height * 4);
for( UINT i = 0; i < data.Height; ++i )
{
// swap red and blue
for( UINT j = 0; j < data.Width; ++j )
{
UINT index = (i * data.Width + j) * 4;
std::swap<unsigned char>(tmpbuff[index + 0], tmpbuff[index + 2]);
}
// flip on X
for( UINT j = 0; j < data.Width / 2; ++j )
{
UINT index1 = (i * data.Width + j) * 4;
UINT index2 = (i * data.Width + (data.Width - j - 1)) * 4;
std::swap<unsigned int>(*((unsigned int*)(tmpbuff + index1)), *((unsigned int*)(tmpbuff + index2)));
}
}
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D, texid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glBindTexture(GL_TEXTURE_2D, texid);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data.Width, data.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpbuff);
glBindTexture(GL_TEXTURE_2D, 0);
GLenum err = glGetError();
if( err != GL_NO_ERROR )
MYERROR("Could not create texture")
else
std::cout << "Created texture " << data.Width << "x" << data.Height << "\n";
bitmap->UnlockBits(&data);
delete[] tmpbuff;
}
delete bitmap;
}
示例11: rect
Texture::Texture(const string& path) {
int Multiplier2[] = {
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096
};
wstring wpath;
wpath.assign(path.begin(), path.end());
Gdiplus::Bitmap* image = Gdiplus::Bitmap::FromFile(wpath.c_str());
Gdiplus::Rect rect(0, 0, image->GetWidth(), image->GetHeight());
Gdiplus::BitmapData bitmapData;
image->LockBits(&rect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bitmapData);
DWORD* bitmapDataScan0 = (DWORD*) bitmapData.Scan0;
_size = Size((float) image->GetWidth(), (float) image->GetHeight());
for (float width = 1.0f;; width *= 2.0f) {
if (width >= _size.width) {
_glSize.width = width;
break;
}
}
for (float height = 1.0f;; height *= 2.0f) {
if (height >= _size.height) {
_glSize.height = height;
break;
}
}
DWORD* glImage = (DWORD*) malloc(sizeof(DWORD) * (int) _glSize.width * (int) _glSize.height);
for (int y = 0; y < (int) _glSize.height; y++) {
if (y < _size.height) {
memcpy(&glImage[(int) (y * _glSize.width)], &bitmapDataScan0[(int) (y * _size.width)], sizeof(DWORD) * (int) _size.width);
memset(&glImage[(int) (y * _glSize.width + _size.width)], 0, sizeof(DWORD) * (int) (_glSize.width - _size.width));
} else {
memset(&glImage[(int) (y * _glSize.width)], 0, sizeof(DWORD) * (int) _glSize.width);
}
}
image->UnlockBits(&bitmapData);
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
glGenTextures(1, &_textureID);
glPushAttrib(GL_ALL_ATTRIB_BITS);
glBindTexture(GL_TEXTURE_2D, _textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei) _glSize.width, (GLsizei) _glSize.height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, glImage);
glPopAttrib();
free(glImage);
delete image;
}
示例12: MyCreateFromGdiplusBitmap
HRESULT BitmapUtil::MyCreateFromGdiplusBitmap( Gdiplus::Bitmap& bmSrc ) throw()
{
Gdiplus::PixelFormat eSrcPixelFormat = bmSrc.GetPixelFormat();
UINT nBPP = 32;
DWORD dwFlags = 0;
Gdiplus::PixelFormat eDestPixelFormat = PixelFormat32bppRGB;
if( eSrcPixelFormat&PixelFormatGDI )
{
nBPP = Gdiplus::GetPixelFormatSize( eSrcPixelFormat );
eDestPixelFormat = eSrcPixelFormat;
}
if( Gdiplus::IsAlphaPixelFormat( eSrcPixelFormat ) )
{
nBPP = 32;
dwFlags |= createAlphaChannel;
eDestPixelFormat = PixelFormat32bppARGB;
}
BOOL bSuccess = Create( bmSrc.GetWidth(), bmSrc.GetHeight(), nBPP, dwFlags );
if( !bSuccess )
{
return( E_FAIL );
}
Gdiplus::ColorPalette* pPalette = NULL;
if( Gdiplus::IsIndexedPixelFormat( eSrcPixelFormat ) )
{
UINT nPaletteSize = bmSrc.GetPaletteSize();
pPalette = static_cast< Gdiplus::ColorPalette* >( _alloca( nPaletteSize ) );
bmSrc.GetPalette( pPalette, nPaletteSize );
RGBQUAD argbPalette[256];
ATLASSERT( (pPalette->Count > 0) && (pPalette->Count <= 256) );
for( UINT iColor = 0; iColor < pPalette->Count; iColor++ )
{
Gdiplus::ARGB color = pPalette->Entries[iColor];
argbPalette[iColor].rgbRed = BYTE( color>>RED_SHIFT );
argbPalette[iColor].rgbGreen = BYTE( color>>GREEN_SHIFT );
argbPalette[iColor].rgbBlue = BYTE( color>>BLUE_SHIFT );
argbPalette[iColor].rgbReserved = 0;
}
SetColorTable( 0, pPalette->Count, argbPalette );
}
if( eDestPixelFormat == eSrcPixelFormat )
{
// The pixel formats are identical, so just memcpy the rows.
Gdiplus::BitmapData data;
Gdiplus::Rect rect( 0, 0, GetWidth(), GetHeight() );
bmSrc.LockBits( &rect, Gdiplus::ImageLockModeRead, eSrcPixelFormat, &data );
UINT nBytesPerRow = AtlAlignUp( nBPP*GetWidth(), 8 )/8;
BYTE* pbDestRow = static_cast< BYTE* >( GetBits() );
BYTE* pbSrcRow = static_cast< BYTE* >( data.Scan0 );
for( int y = 0; y < GetHeight(); y++ )
{
memcpy( pbDestRow, pbSrcRow, nBytesPerRow );
pbDestRow += GetPitch();
pbSrcRow += data.Stride;
}
bmSrc.UnlockBits( &data );
}
else
{
// Let GDI+ work its magic
Gdiplus::Bitmap bmDest( GetWidth(), GetHeight(), GetPitch(), eDestPixelFormat, static_cast< BYTE* >( GetBits() ) );
Gdiplus::Graphics gDest( &bmDest );
gDest.DrawImage( &bmSrc, 0, 0 );
}
return( S_OK );
}
示例13: GdiRenderFontShadow
//.........这里部分代码省略.........
rtDraw);
UINT* pixelsSrc = NULL;
UINT* pixelsDest = NULL;
UINT* pixelsMask = NULL;
using namespace Gdiplus;
BitmapData bitmapDataSrc;
BitmapData bitmapDataDest;
BitmapData bitmapDataMask;
Rect rect(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight() );
pBmpFontBodyBackup->LockBits(
&rect,
ImageLockModeWrite,
PixelFormat32bppARGB,
&bitmapDataSrc );
pBmpDisplay->LockBits(
&rect,
ImageLockModeWrite,
PixelFormat32bppARGB,
&bitmapDataDest );
pBmpMask->LockBits(
&rect,
ImageLockModeWrite,
PixelFormat32bppARGB,
&bitmapDataMask );
// Write to the temporary buffer provided by LockBits.
pixelsSrc = (UINT*)bitmapDataSrc.Scan0;
pixelsDest = (UINT*)bitmapDataDest.Scan0;
pixelsMask = (UINT*)bitmapDataMask.Scan0;
if( !pixelsSrc || !pixelsDest || !pixelsMask)
return;
UINT col = 0;
int stride = bitmapDataDest.Stride >> 2;
if(m_bDiffuseShadow&&!m_bExtrudeShadow)
{
for(UINT row = 0; row < bitmapDataDest.Height; ++row)
{
for(col = 0; col < bitmapDataDest.Width; ++col)
{
using namespace Gdiplus;
UINT index = row * stride + col;
BYTE nAlpha = pixelsMask[index] & 0xff;
UINT clrShadow = 0xff000000 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
if(nAlpha>0)
{
UINT clrtotal = clrShadow;
for(int i=2;i<=m_nShadowThickness; ++i)
pixelsSrc[index] = Alphablend(pixelsSrc[index],clrtotal,m_clrShadow.GetA());
pixelsDest[index] = pixelsSrc[index];
}
}
}
}
else
{
for(UINT row = 0; row < bitmapDataDest.Height; ++row)
{
for(col = 0; col < bitmapDataDest.Width; ++col)
{
using namespace Gdiplus;
UINT index = row * stride + col;
BYTE nAlpha = pixelsMask[index] & 0xff;
UINT clrShadow = 0xff000000 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
if(nAlpha>0)
pixelsDest[index] = Alphablend(pixelsSrc[index],clrShadow,m_clrShadow.GetA());
}
}
}
pBmpMask->UnlockBits(&bitmapDataMask);
pBmpDisplay->UnlockBits(&bitmapDataDest);
pBmpFontBodyBackup->UnlockBits(&bitmapDataSrc);
pGraphics->DrawImage(pBmpDisplay,0,0,pBmpDisplay->GetWidth(),pBmpDisplay->GetHeight());
if(pBmpMask)
{
delete pBmpMask;
pBmpMask = NULL;
}
if(pBmpFontBodyBackup)
{
delete pBmpFontBodyBackup;
pBmpFontBodyBackup = NULL;
}
if(pBmpDisplay)
{
delete pBmpDisplay;
pBmpDisplay = NULL;
}
}
示例14: RenderFontShadow
//.........这里部分代码省略.........
if(!b) return false;
b = m_pFontBodyShadow->DrawString(
pGraphicsDrawn,
pFontFamily,
fontStyle,
nfontSize,
pszText,
rtDraw,
pStrFormat);
if(!b) return false;
b = m_pShadowStrategy->DrawString(
pGraphicsDrawn,
pFontFamily,
fontStyle,
nfontSize,
pszText,
rtDraw,
pStrFormat);
if(!b) return false;
UINT* pixelsDest = NULL;
UINT* pixelsMask = NULL;
UINT* pixelsShadowMask = NULL;
using namespace Gdiplus;
BitmapData bitmapDataDest;
BitmapData bitmapDataMask;
BitmapData bitmapDataShadowMask;
Rect rect(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight() );
pBitmapDrawn->LockBits(
&rect,
ImageLockModeWrite,
PixelFormat32bppARGB,
&bitmapDataDest );
pBitmapMask->LockBits(
&rect,
ImageLockModeWrite,
PixelFormat32bppARGB,
&bitmapDataMask );
pBitmapShadowMask->LockBits(
&rect,
ImageLockModeWrite,
PixelFormat32bppARGB,
&bitmapDataShadowMask );
pixelsDest = (UINT*)bitmapDataDest.Scan0;
pixelsMask = (UINT*)bitmapDataMask.Scan0;
pixelsShadowMask = (UINT*)bitmapDataShadowMask.Scan0;
if( !pixelsDest || !pixelsMask || !pixelsShadowMask )
return false;
UINT col = 0;
int stride = bitmapDataDest.Stride >> 2;
for(UINT row = 0; row < bitmapDataDest.Height; ++row)
{
for(col = 0; col < bitmapDataDest.Width; ++col)
{
using namespace Gdiplus;
UINT index = row * stride + col;
BYTE nAlpha = pixelsMask[index] & 0xff;
BYTE nAlphaShadow = pixelsShadowMask[index] & 0xff;
if(nAlpha>0&&nAlpha>nAlphaShadow)
{
pixelsDest[index] = nAlpha << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
}
else if(nAlphaShadow>0)
{
pixelsDest[index] = nAlphaShadow << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
pixelsMask[index] = pixelsShadowMask[index];
}
}
}
pBitmapShadowMask->UnlockBits(&bitmapDataShadowMask);
pBitmapMask->UnlockBits(&bitmapDataMask);
pBitmapDrawn->UnlockBits(&bitmapDataDest);
if(pGraphicsShadowMask)
{
delete pGraphicsShadowMask;
pGraphicsShadowMask = NULL;
}
if(pBitmapShadowMask)
{
delete pBitmapShadowMask;
pBitmapShadowMask = NULL;
}
return true;
}
示例15: UnlockBits
void Bitmap::UnlockBits(BitmapData* data) {
Gdiplus::BitmapData* bd = reinterpret_cast<Gdiplus::BitmapData*>(data->_private);
Gdiplus::Bitmap* gdiBitmap = dynamic_cast<Gdiplus::Bitmap*>(reinterpret_cast<Gdiplus::Image*>(_private));
gdiBitmap->UnlockBits(bd);
}