• 9751阅读
  • 6回复

关于设置一段文本作为叠加图像 [复制链接]

上一主题 下一主题
离线nevcry
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2013-08-04
先上图



在设置文本叠加时,文本显示黑边很严重,很难看...
还有就是 参数613 在SDK,没有详细说明
613 - Picture font                   str      R/W         获取或设置叠加文本的字体,格式:"fontname;fontsize;fontcolor;edge"
fontname;fontsize;fontcolor;edge
四个参数的说明不够详细(没有准确的标出对应值的取值范围)
实际应用中还得重新测试范围...
fontname:系统已注册字体名称
fontsize:0-255
fontcolor:255*255*255(红*绿*蓝)
edge:参数不太明白.设置为0和100 没有什么区别.
还有就是对于已经设置的文本如何清除掉呢?
我这里设置为空时,左上角会有一个黑点.
而要完成 不显示,我这里使用的 是 设置透明度.将透明度设置为0,完全透明,需要显示时再将透明度修改过来.. 这样感觉不是很直观..
不知道 管理员,是使用什么方法来处理  比如:播放,暂停,继续播放,音量+,音量-,静音,这样的信息显示和清空.

迅雷看看的效果如图:




离线aplayer

只看该作者 沙发  发表于: 2013-08-05
楼主,文字黑边是程序为了使文字能在明暗任意视频背景上能看清而故意生成的,如果需要对叠加的文字有更多定制,建议绘制到一个图像RGBA Buffer中再叠加。
离线nevcry

只看该作者 板凳  发表于: 2013-08-05
回 aplayer 的帖子
aplayer:楼主,文字黑边是程序为了使文字能在明暗任意视频背景上能看清而故意生成的,如果需要对叠加的文字有更多定制,建议绘制到一个图像RGBA Buffer中再叠加。
 (2013-08-05 11:04) 

如何绘制图像RGBA Buffer呢,不是很明白,可否给出一个示例代码..谢谢...
离线aplayer

只看该作者 地板  发表于: 2013-08-05
如APlayerSDK文档中提到的:
614 - Picture RGBA buffer    str   W     set picture data by RGBA buffer, format: "address;width;height"

即, "adress" 参数为指向一个包含RGBA 内存缓冲图像的地址的十进制串, width 为该内存缓冲图的宽度, height 为高度, 例如缓冲区地址为 0x21000000, 宽度为 400, 高度为 300 的图像缓冲区缓冲写成:
"553648128;400;300", 其中"553648128" 即 0x21000000 的十进制串.

至于如何把文字写入 RGBA 缓冲作为图像, 你可以创建一个内存DC, 并且创建一个 32 bit 位图, 关联它们, 然后渲染文字到该DC, 渲染完后,  再按照需要的方式通过 GetDIBits 和 SetDIBitsToDevice 处理这个 32bit 位图的高 8 位用作 Alpha 通道即可

离线nevcry

只看该作者 4楼 发表于: 2013-08-07
回 aplayer 的帖子
aplayer:
如APlayerSDK文档中提到的:
614 - Picture RGBA buffer    str   W     set picture data by RGBA buffer, format: "address;width;height"
即, "adress" 参数为指向一个包含RGBA 内存缓冲图像的地址的十进制串, width 为该内存缓冲图的宽度, height 为高度, 例如缓冲区地址为 0x21000000, 宽度为 400, 高度为 300 的图像缓冲区缓冲写成:
"553648128;400;300", 其中"553648128" 即 0x21000000 的十进制串.
.......

请教管理员,因为我图形图像不是很了解.. 下面是我找到的 利用Gdi 实现的文字输出..
如图:


代码如下:

Public Function DrawText(ByVal text As String) As Boolean
    If text = "" Then Exit Function
    LastText = text
    Dim tempBI     As BITMAPINFO
    Dim tempBlend  As BLENDFUNCTION
    Dim lngHeight  As Long, lngWidth As Long
    Dim curWinLong As Long
    Dim graphics   As Long
    Dim winSize    As Size
    Dim srcPoint   As POINTAPI
    Me.Cls
    SelectObject mDC, oldBitmap
    DeleteObject mainBitmap
    DeleteObject oldBitmap
    DeleteDC mDC
    GdipDeleteFontFamily fontFam
    GdipDeleteStringFormat strFormat
    GdipDeletePath strPath
    GdipDeleteBrush Brush
    GdipDeletePen pen
    GdipDeleteGraphics graphics '释放graphics占用的内存
    '清除上次使用的内存
    With tempBI.bmiHeader
        .biSize = Len(tempBI.bmiHeader)
        .biBitCount = 32
        .biHeight = Me.ScaleHeight
        .biWidth = Me.ScaleWidth
        .biPlanes = 1
        .biSizeImage = .biWidth * .biHeight * (.biBitCount / 8)
    End With
    mDC = CreateCompatibleDC(Me.hdc)
    mainBitmap = CreateDIBSection(mDC, tempBI, DIB_RGB_COLORS, ByVal 0, 0, 0)
    oldBitmap = SelectObject(mDC, mainBitmap)
    Call GdipCreateFromHDC(mDC, graphics)
    GdipSetSmoothingMode graphics, SmoothingModeHighQuality
    GdipCreateFontFamilyFromName StrPtr(GFont.FontName), 0, fontFam
    GdipCreateStringFormat 0, 0, strFormat
    GdipSetStringFormatAlign strFormat, StringAlignmentCenter
    Dim rectf1 As RECTF
    rectf1.Height = 10
    rectf1.Width = 240
    rectf1.Top = 1
    rectf1.Left = 1
    '填充坐标   '&HFFA5DAF7, &HC8468DCC,&HFF010101
    '-----------------------------------------------------
    Call GdipCreateLineBrushFromRect(rectf1, &HC0000000, &HC0000000, LinearGradientModeBackwardDiagonal, WrapModeTileFlipXY, Brush)
    '创建一个填充笔刷
    '创建一个描边的笔刷
    rclayout.Left = 2
    rclayout.Top = 2
    rclayout.Right = Screen.Width / 15
    rclayout.Bottom = 0
    GdipCreatePath FillModeAlternate, strPath
    Call GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)
    GdipFillPath graphics, Brush, strPath
    GdipDrawPath graphics, pen, strPath
    '------------------------------------------------------
    Call GdipCreateLineBrushFromRect(rectf1, GFont.ForeColor1, GFont.ForeColor2, LinearGradientModeBackwardDiagonal, WrapModeTileFlipXY, Brush)
    '创建一个填充笔刷
    GdipCreatePen1 &HC0000000, GFont.FontWidth, UnitDocument, pen
    '创建一个描边的笔刷
    rclayout.Left = 0
    rclayout.Top = 0
    rclayout.Right = Screen.Width / 15
    rclayout.Bottom = 0
    GdipCreatePath FillModeAlternate, strPath
    Call GdipAddPathStringI(strPath, StrPtr(text), -1, fontFam, FontStyle.FontStyleBold, GFont.FontSize, rclayout, strFormat)
    GdipFillPath graphics, Brush, strPath
    GdipDrawPath graphics, pen, strPath
    '--------------------------------------------------------------
    curWinLong = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
    SetWindowLong Me.hwnd, GWL_EXSTYLE, curWinLong Or WS_EX_LAYERED
    srcPoint.x = 0
    srcPoint.y = 0
    winSize.cx = Me.ScaleWidth
    winSize.cy = Me.ScaleHeight
    With blendFunc32bpp
        .AlphaFormat = AC_SRC_ALPHA
        .BlendFlags = 0
        .BlendOp = AC_SRC_OVER
        .SourceConstantAlpha = 255
    End With
    Call GdipDeleteGraphics(graphics)
    Call UpdateLayeredWindow(Me.hwnd, Me.hdc, ByVal 0&, winSize, mDC, srcPoint, 0, blendFunc32bpp, ULW_ALPHA)
End Function


不知道如何修改,以内存图像的形式加载到aplayer中..望管理员指教,谢谢...
离线aplayer

只看该作者 5楼 发表于: 2013-08-07
在最后一句修改, 把 mDC 中的图像用取出来 GetDIBits 取出来, 放到一个RGB32Bit 的数组
把这数组的地址按这形势填充 "地址;图像宽度;图像高度" 的形式字符串填入 614 - Picture RGBA buffer  参数试试看.
离线潇洒人生

只看该作者 6楼 发表于: 2016-04-25
看看
快速回复
限100 字节
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
上一个 下一个