久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2382|回復: 0
收起左側

C++ 指針與引用

[復制鏈接]
ID:77367 發表于 2015-4-18 20:13 | 顯示全部樓層 |閱讀模式
傳遞一個指針變量的引用



// function : String2BW
// description: generate a BW image(bpp==1) with a given string.
// param:
//       pDst[out], Dst image data, ##NB## does not include bitmap head data
//       size[out],Dst image size in Bytes
//       strTitle[in], input string
//       nWidth[in], image width in pixels
//       nHeight[in], image height in pixels
//       iFontSize[in], draw string font size
BOOL String2BW(BYTE*& pDst/*out*/, int& size/*out*/, CString strTitle, int nWidth, int nHeight, int iFontSize = 300)
{
ASSERT(nWidth > 0);
ASSERT(nHeight > 0);
if ( strTitle.IsEmpty() || nWidth <= 0 || nHeight <= 0)
{
return FALSE;
}

if (!pDst)
{
delete pDst;
pDst = NULL;
}

Bitmap *pBitmap = NULL;
RectF textArea;
StringFormat strFormat;
SolidBrush brText(Color::White);


// 生成一個1bpp的圖像出來
pBitmap = new Bitmap(nWidth, nHeight, PixelFormat1bppIndexed);
ASSERT(pBitmap);

//  ResetPalette(m_pBitmap);

//
Graphics *g = Graphics::FromImage(pBitmap);
g->Clear(Color::Black);
//g->SetInterpolationMode( InterpolationModeHighQualityBicubic );

strFormat.SetFormatFlags(StringFormatFlagsNoClip);
Gdiplus::Font textF(L"", (REAL)iFontSize, FontStyleRegular, UnitPoint, NULL);

g->MeasureString(strTitle,
strTitle.GetLength(),
&textF,
RectF(0, 0, 0, 0),
&textArea);

g->DrawString(strTitle,
strTitle.GetLength(),
&textF,
RectF(0,
0,
textArea.Width,
textArea.Height),
&strFormat,
&brText);


// paser data
int  iWidth = pBitmap->GetWidth();// 只有一列的數據,所以偏移量是0bit就夠了  2048
int  iHeight = pBitmap->GetHeight();// 簡單的,原始圖像高度是384了。。。。
Gdiplus::PixelFormat format = pBitmap->GetPixelFormat();

ASSERT(iWidth == nWidth);
ASSERT(iHeight == nHeight);
ASSERT(format == PixelFormat1bppIndexed);

Rect rect(0, 0, nWidth, nHeight);
BitmapData  *pBitmapData = new BitmapData;
pBitmap->LockBits(&rect, ImageLockModeRead, format, pBitmapData);
BYTE *pByte = (BYTE *)pBitmapData->Scan0;

//
size = pBitmapData->Stride * nHeight;
pDst = new BYTE[size];
ASSERT(pDst);

memcpy(pDst, pByte, size);

pBitmap->UnlockBits(pBitmapData);

//clear:
delete pBitmapData;
pBitmapData = NULL;
delete pBitmap;
delete g;

//return pBitmap;
return TRUE;
}



回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 天天草天天干 | 国产一区欧美 | 婷婷久久综合 | 亚洲在线 | 亚洲精品国产精品国自产在线 | av手机在线观看 | 精品免费观看 | 国产福利久久 | 亚洲一区在线视频 | 成人做爰9片免费视频 | 精品日韩一区二区 | 户外少妇对白啪啪野战 | 亚洲另类色图 | www.99色| 国产精品久久久久久久 | 国产美女视频 | 99午夜| 九九视频在线观看 | 欧美三级精品 | 国产在线视频一区二区 | 性生活网址 | 精品一二区| 久久久夜 | 国产一区二区精品丝袜 | 热久久久久 | 黄色小视频免费 | 日本天堂网 | 一区二区在线免费观看 | 在线国产小视频 | 韩日av在线 | 日韩一区二区三 | 日韩精品第一页 | 99re在线 | 一区二区三区四区在线 | 日韩a视频 | 日本欧美在线 | 亚洲精品一区二区三区精华液 | 亚洲最新视频 | 国产欧美久久久 | 国产黄色在线播放 | 国产免费黄色片 |