图像处理 高手请进(高分请教)

lnhjf 2005-09-06 04:42:31
各位大虾好,小弟请教一个问题:
1、能否通过C++(或其他语言)实现 一个图像(图形/bmp/jpg...) 和一个字符串(文本)的合成?
2、也就是说:能否对一个给定的图片,把一句文字合成上去??
...全文
389 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
菜牛 2005-12-16
  • 打赏
  • 举报
回复
可以啊,如果你有信心,可以分析一下图形格式,最终在内存中把文字信息转换成点阵信息,合并到内存位图数据中,这是图形处理的简单方法,不需要任何GDI操作也可以。
lj3562732 2005-12-16
  • 打赏
  • 举报
回复
可以呀 用opengl先做一个纹理 然后把你要写的数字 画到纹理的上面就可以了
howard 2005-12-14
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4439/4439152.xml?temp=.3963892

楼下,还有楼上到楼主那个高手帮我个忙,去看看这个问题吧。谢谢了,我好着急啊。自己水平又不高,只能依靠你们了!谢谢了!!1
DooDu 2005-09-17
  • 打赏
  • 举报
回复
用vb吧,直接print到picturebox上就可以了
kevinmartin 2005-09-14
  • 打赏
  • 举报
回复
首先将图片读入到内存中,然后通过背景覆盖的方法,将文字的背景处理成透明的,再放到图片上,然后再输出成bmp图像就可以了。
lnhjf 2005-09-14
  • 打赏
  • 举报
回复
首先: 感谢 IceKettle(冰湖) 的回复,我先学习一下您的大作!首先感谢,
此次:回复 n6002(阿斯) 就是把文字 + 图片文件,形成一个新的图片文件。
n6002 2005-09-12
  • 打赏
  • 举报
回复
合成?把文字写到指定图片上?文字加密揉到图片中去?还是如楼上所说文字+图片的文件?
IceKettle 2005-09-12
  • 打赏
  • 举报
回复
//这个函数用来把文本写到一个bmp上,如果想看到3d效果的话,用这个bmp作为前景图与背景图融合(调用上楼的函数实现)
HBITMAP MakeDraw2BITMAP(HDC hDC,long nWidth, long nHeight, const TCHAR* text, HFONT hFont,BOOL bVersion)
{
HBITMAP hBitmap = NULL;
BYTE* pDrawBits=NULL;
COLORREF backClr = RGB(255, 255, 255);
HDC hMemDC=::CreateCompatibleDC((HDC)hDC);
if(hMemDC == NULL)
return NULL;

BITMAPINFOHEADER bmih;
memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
bmih.biSize = sizeof(BITMAPINFOHEADER);
bmih.biBitCount = 24;
bmih.biPlanes = 1;
bmih.biCompression = BI_RGB;
bmih.biWidth = nWidth;
bmih.biHeight = nHeight;
bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) & ~31) >> 3) * bmih.biHeight;
hBitmap = CreateDIBSection(hDC, (CONST BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&pDrawBits, NULL, 0);
if((hBitmap == NULL) || (pDrawBits == NULL))
return NULL;

HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
/////////////////////////////////////////////////////////////////////////////////////
//Once out drawing surface has been selected into the memory dc, we can draw anything
//and have it all nicely collected in our bitmap for future use
//Fill up the background
::SetBkColor(hMemDC, backClr);
RECT rc;
rc.left = rc.top =0;
rc.bottom = nHeight;
rc.right = nWidth;
::ExtTextOut(hMemDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);

HFONT hOldFont=NULL;
/*
hFont=CreateFontIndirect(pFont);
*/
if (hFont)
hOldFont = (HFONT)SelectObject(hMemDC,hFont);
else
hOldFont = (HFONT)SelectObject(hMemDC,GetStockObject(DEFAULT_GUI_FONT));

//Set text color
SetTextColor(hMemDC,RGB(0,0,0));
SetBkColor(hMemDC,RGB(255,255,255));

//draw the text
SetBkMode(hMemDC,OPAQUE);

TEXTMETRIC tm;
::GetTextMetrics(hMemDC,&tm);

::SetTextAlign(hMemDC,TA_CENTER | TA_TOP);

long len = (long)_tcslen(text); // For UNICODE support
if(!bVersion)
{
::ExtTextOut(hMemDC,(rc.left + rc.right) / 4, (rc.top + rc.bottom - tm.tmHeight) / 4, ETO_CLIPPED, &rc, text, len, NULL);

::ExtTextOut(hMemDC,(rc.left + rc.right) * 3 / 4, (rc.top + rc.bottom - tm.tmHeight) / 4, ETO_CLIPPED, &rc, text, len, NULL);

::ExtTextOut(hMemDC,(rc.left + rc.right) / 2, (rc.top + rc.bottom - tm.tmHeight) / 2, ETO_CLIPPED, &rc, text, len, NULL);

::ExtTextOut(hMemDC,(rc.left + rc.right) / 4, (rc.top + rc.bottom - tm.tmHeight) * 3 / 4, ETO_CLIPPED, &rc, text, len, NULL);

::ExtTextOut(hMemDC,(rc.left + rc.right) * 3 / 4, (rc.top + rc.bottom - tm.tmHeight) * 3 / 4, ETO_CLIPPED, &rc, text, len, NULL);
}
else
::ExtTextOut(hMemDC,(rc.left + rc.right) * 3 / 4, (rc.top + rc.bottom - tm.tmHeight) * 3 / 4 + 25, ETO_CLIPPED, &rc, text, len, NULL);

//And deselect the drawing surface
if (hOldFont) SelectObject(hMemDC,hOldFont);

SelectObject(hMemDC, hOldBitmap);

return hBitmap;
}
IceKettle 2005-09-12
  • 打赏
  • 举报
回复
///////////////////////////////////////////////////////////////////////////////////
// Emboss - Creates a 3D embossed effect
// Returns - A new bitmap containing the resulting effect
// hBitmap - Bitmap that contains the basic text & shapes
// hbmBackGnd - Contains the color image
// hPal - Handle of palette associated with hbmBackGnd
// bRaised - True if raised effect is desired. False for sunken effect
// xDest - x coordinate - used to offset hBitmap
// yDest - y coordinate - used to offset hBitmap
// clrHightlight - Color used for the highlight edge
// clrShadow - Color used for the shadow
//
// Note - 1. Neither of the bitmap handles passed in should be selected
// in a device context.
// 2. The pixel at 0,0 in hBitmap is considered the background color
//
HBITMAP Emboss( HBITMAP hBitmap, HBITMAP hbmBackGnd, HPALETTE hPal,
BOOL bRaised, int xDest, int yDest,
COLORREF clrHighlight, COLORREF clrShadow )
{
const DWORD PSDPxax = 0x00B8074A;
BITMAP bmInfo ;
HBITMAP hbmOld, hbmShadow, hbmHighlight, hbmResult, hbmOldMem ;
HBRUSH hbrPat ;
HDC hDC, hColorDC, hMonoDC, hMemDC ;

if( !bRaised )
{
// Swap the highlight and shadow color
COLORREF clrTemp = clrShadow;
clrShadow = clrHighlight;
clrHighlight = clrTemp;
}

// We create two monochrome bitmaps. One of them will contain the
// highlighted edge and the other will contain the shadow. These
// bitmaps are then used to paint the highlight and shadow on the
// background image.

hbmResult = NULL ;
hDC = GetDC( NULL ) ;

// Create a compatible DCs
hMemDC = ::CreateCompatibleDC( hDC );
hMonoDC = CreateCompatibleDC( hDC );
hColorDC = CreateCompatibleDC( hDC );

if( hMemDC == NULL || hMonoDC == NULL || hColorDC == NULL )
{
if( hMemDC ) DeleteDC( hMemDC );
if( hMonoDC ) DeleteDC( hMonoDC );
if( hColorDC ) DeleteDC( hColorDC );

return NULL;
}

// Select the background image into memory DC so that we can draw it
hbmOldMem = (HBITMAP)::SelectObject( hMemDC, hbmBackGnd );

// Get dimensions of the background image
BITMAP bm;
::GetObject( hbmBackGnd, sizeof( bm ), &bm );



// Create the monochrome and compatible color bitmaps
GetObject( hBitmap, sizeof( BITMAP ), (LPSTR) &bmInfo ) ;
hbmShadow =
CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 1, NULL ) ;
hbmHighlight =
CreateBitmap( bmInfo.bmWidth, bmInfo.bmHeight, 1, 1, NULL ) ;
hbmResult =
CreateCompatibleBitmap( hDC, bm.bmWidth, bm.bmHeight ) ;

hbmOld = (HBITMAP)SelectObject( hColorDC, hBitmap ) ;

// Set background color of bitmap for mono conversion
// We assume that the pixel in the top left corner has the background color
SetBkColor( hColorDC, GetPixel( hColorDC, 0, 0 ) ) ;

// Create the highlight bitmap.
hbmHighlight = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmHighlight ) ;
PatBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight, WHITENESS ) ;
BitBlt( hMonoDC, 0, 0, bmInfo.bmWidth - 1, bmInfo.bmHeight - 1,
hColorDC, 1, 1, SRCCOPY ) ;
BitBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
hColorDC, 0, 0, MERGEPAINT ) ;
hbmHighlight = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmHighlight ) ;


// create the shadow bitmap
hbmShadow = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmShadow ) ;
PatBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight, WHITENESS ) ;
BitBlt( hMonoDC, 1, 1, bmInfo.bmWidth-1, bmInfo.bmHeight-1,
hColorDC, 0, 0, SRCCOPY ) ;
BitBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
hColorDC, 0, 0, MERGEPAINT ) ;
hbmShadow = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmShadow ) ;


// Now let's start working on the final image
SelectObject( hColorDC, hbmResult ) ;
// Select and realize the palette if one is supplied
if( hPal && GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE )
{
::SelectPalette( hColorDC, hPal, FALSE );
::RealizePalette(hColorDC);
}
// Draw the background image
BitBlt(hColorDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,SRCCOPY);
// Restore the old bitmap in the hMemDC
::SelectObject( hMemDC, hbmOldMem );


// Set the background and foreground color for the raster operations
SetBkColor( hColorDC, RGB(255,255,255) ) ;
SetTextColor( hColorDC, RGB(0,0,0) ) ;

// blt the highlight edge
hbrPat = CreateSolidBrush( clrHighlight ) ;
hbrPat = (HBRUSH)SelectObject( hColorDC, hbrPat ) ;
hbmHighlight = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmHighlight ) ;
BitBlt( hColorDC, xDest, yDest, bmInfo.bmWidth, bmInfo.bmHeight,
hMonoDC, 0, 0, PSDPxax ) ;
DeleteObject( SelectObject( hColorDC, hbrPat ) ) ;
hbmHighlight = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmHighlight ) ;

// blt the shadow edge
hbrPat = CreateSolidBrush( clrShadow ) ;
hbrPat = (HBRUSH)SelectObject( hColorDC, hbrPat ) ;
hbmShadow = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmShadow ) ;
BitBlt( hColorDC, xDest, yDest, bmInfo.bmWidth, bmInfo.bmHeight,
hMonoDC, 0, 0, PSDPxax ) ;
DeleteObject( SelectObject( hColorDC, hbrPat ) ) ;
hbmShadow = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmShadow ) ;

// select old bitmap into color DC
SelectObject( hColorDC, hbmOld ) ;

DeleteObject( (HGDIOBJ) hbmShadow ) ;
DeleteObject( (HGDIOBJ) hbmHighlight ) ;

ReleaseDC( NULL, hDC ) ;

return ( hbmResult ) ;
}
jsjjms 2005-09-08
  • 打赏
  • 举报
回复
偶以前见过一中加密的原理类似楼主说的.

大家在Dos里敲 copy a.txt+b.jpg c.dat

文本和图象就会合到一起.如果用记事本打开那个dat文件

可以发现里面的文本.这样可以起到对图象进行加密的作用.

不过好象说的和楼主是另一个路子.呵呵。
hunterwan 2005-09-07
  • 打赏
  • 举报
回复
如果不是采用windows系统或者想通过命令行方式实现这个功能,请使用
ImageMagick的C函数库可直接实现。ImageMagick也提供一个命令行的工
具可以直接在各种类型的图片上加字。
blackcrusoe 2005-09-07
  • 打赏
  • 举报
回复
应该不是太难吧
peterID 2005-09-06
  • 打赏
  • 举报
回复
找本《数字图像处理》的书看看吧,不是很难。
lujun-cc 2005-09-06
  • 打赏
  • 举报
回复
将位图加载到内存DC中,在该DC的表面写文字,这样就合成了!
OpenHero 2005-09-06
  • 打赏
  • 举报
回复
可以做
还有可以用YUV格式把两个图片合成一个,俗名 电子水印
healer_kx 2005-09-06
  • 打赏
  • 举报
回复
支持PhotoShop吧,开源的有PCL库,和一个类似于fotoshp的软件.
寻开心 2005-09-06
  • 打赏
  • 举报
回复
www.codeproject.com/bitmap/cximage.asp
寻开心 2005-09-06
  • 打赏
  • 举报
回复
借助cximage吧
cximage加载图片,写到一个窗口上,再向这个窗口上写文字
然后把这个窗口用cximage存储成磁盘文件就可以了


用纯粹的c/c++?
不是打算自杀吧??
自己做格式识别和图片处理???
只见烟火飞扬 2005-09-06
  • 打赏
  • 举报
回复
读到内存DC,再在上面写字,再保存~-~代码不会
zhouhuahai 2005-09-06
  • 打赏
  • 举报
回复
顶一个
加载更多回复(2)

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧