Tuesday, January 21, 2014
XAML close minimize restore and maximize Geometry
Thursday, May 7, 2009
Embeding String as overlay on a bitmap
want to write your own string as an overlay of a given bitmap?
Use this code
CFont* pFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
CFont* pOldFont = dc.SelectObject(pFont);
dc.SetTextColor(RGB(255,255,255));
dc.SetBkMode(TRANSPARENT);
dc.TextOut(500,397,"String");
dc.SelectObject(pOldFont);
Tuesday, May 5, 2009
save rectangle to JPEG
When you need to save a rectangle in your program to a file
the im.Save( "c:\\image.jpg", ImageFormatJPEG); line determines the file format
#include//For Image
using namespace Gdiplus; //For Image
void BitmapUtils::SaveBitmapToFile(HDC hdc,CRect rect)
{
HDC hMemDC = CreateCompatibleDC(hdc);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc,rect.right, rect.Height() + rect.bottom);
if (hBitmap)
{
HBITMAP hOld = (HBITMAP) SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0, rect.right, rect.Height() + rect.bottom, hdc, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOld);
DeleteDC(hMemDC);
::ReleaseDC(NULL, hdc);
}
CImage im;
im.Attach(hBitmap);
im.Save( "c:\\image.jpg", ImageFormatJPEG);
}
Monday, May 4, 2009
Writing a bitmap to a BMP file
Great function to save a bitmap structure to a file
// WriteDIB - Writes a DIB to file
// Returns - TRUE on success
// szFile - Name of file to write to
// hDIB - Handle of the DIB
BOOL WriteDIB( LPTSTR szFile, HANDLE hDIB)
{
BITMAPFILEHEADER hdr;
LPBITMAPINFOHEADER lpbi;
if (!hDIB)
return FALSE;
CFile file;
if( !file.Open( szFile, CFile::modeWrite|CFile::modeCreate) )
return FALSE;
lpbi = (LPBITMAPINFOHEADER)hDIB;
int nColors = 1 << lpbi->biBitCount;
// Fill in the fields of the file header
hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM"
hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr );
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize +
nColors * sizeof(RGBQUAD));
// Write the file header
file.Write( &hdr, sizeof(hdr) );
// Write the DIB header and the bits
file.Write( lpbi, GlobalSize(hDIB) );
return TRUE;
}