- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图在现有位图上绘制文本,但是当我使用图形上下文的 DrawText 方法时,背景被删除。但只有当我从空位图创建背景图像时才会发生这种情况(在加载图像的位图上使用 DrawText 效果很好)。我认为发生这个问题是因为我使用 MemoryDC 创建一个空位图,但我对 wxPython 很陌生,所以我不知道如何修复它。
这是我到目前为止所做的事情:
import wx
def GetEmptyBitmap(w, h, color=(0,0,0)):
"""
Create monochromatic bitmap with desired background color.
Default is black
"""
b = wx.EmptyBitmap(w, h)
dc = wx.MemoryDC(b)
dc.SetBrush(wx.Brush(color))
dc.DrawRectangle(0, 0, w, h)
return b
def drawTextOverBitmap(bitmap, text='', fontcolor=(255, 255, 255)):
"""
Places text on the center of bitmap and returns modified bitmap.
Fontcolor can be set as well (white default)
"""
dc = wx.MemoryDC(bitmap)
gc = wx.GraphicsContext.Create(dc)
font = wx.Font(16, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
gc.SetFont(font, fontcolor)
w,h = dc.GetSize()
tw, th = dc.GetTextExtent(text)
gc.DrawText(text, (w - tw) / 2, (h - th) / 2)
return bitmap
app = wx.App()
bmp_from_img = bmp = wx.Image(location).Rescale(200, 100).ConvertToBitmap()
bmp_from_img = drawTextOverBitmap(bmp_from_img, "From Image", (255,255,255))
bmp_from_empty = GetEmptyBitmap(200, 100, (255,0,0))
bmp_from_empty = drawTextOverBitmap(bmp_from_empty, "From Empty", (255,255,255))
frame = wx.Frame(None)
st1 = wx.StaticBitmap(frame, -1, bmp_from_img, (0,0), (200,100))
st2 = wx.StaticBitmap(frame, -1, bmp_from_empty, (0, 100), (200, 100))
frame.Show()
app.MainLoop()
正如我所说,使用加载图像的 StaticBitmap 可以正确显示,但使用 EmptyBitmap 创建的 StaticBitmap 没有背景。
你有什么想法让它发挥作用吗?
谢谢
最佳答案
这对我来说似乎是一个错误。使用以下命令使其工作:
def GetEmptyBitmap(w, h, color=(0,0,0)):
# ...
# instead of
# b = wx.EmptyBitmap(w, h)
# use the following:
img = wx.EmptyImage(w, h)
b = img.ConvertFromBitmap()
# ...
我认为问题不在于 wx.MemoryDC
,而是平台特定的位图创建例程,其中在幕后还有更多的事情发生。通过从 wx.Image
开始,输出似乎更可预测/更有用。
关于python - wxPython - GC.DrawText 删除背景位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36447192/
绘制文本选项 有一个 '画' 指定是否应绘制文本的表达式。 http://www.ffmpeg.org/ffmpeg-filters.html#drawtext-1 我发现我们可以使用以下表达式在特定
我正在使用 ffmpeg 库在特定时间在视频上绘制文本,我成功了 我正在使用此命令将文本从上到下移动,但我无法确定 x 和 Y 从 x,y 移动到特定 x,y ffmpeg -i VideoInput
我们正在尝试使用 ffmpeg drawtext 来支持印地语字体。但是数据的顺序是不正确的。 印地语文本的 unicode 是这样传递的 1. पिता माता िस्रफ 但输出呈现为 Outp
我正在开发一个对 FFmpeg 进行系统调用的应用程序。 我找到了一种方法来隔离和淡出 drawtext 过滤器,但是渲染时间增加了大约 5 倍。 我只是想看看我提出的命令是否有明显错误。 ffmpe
我正在尝试设置此 FFmpeg 命令的 drawtext 何时开始,我尝试使用 start_number 但看起来它不会成功。 ffmpeg -i 1.mp4 -acodec aac -keyint_
我正在尝试使用 ffmpeg drawtext 过滤器将藏文呈现为视频。但有些字符没有正确呈现。 例如: སྤྱི་སྟེགས Expected render output 一些垂直太长的字符无法正确
我使用 shell_exec 在 PHP 中运行以下命令: ffmpeg -i $sourcePath -vf \"drawtext=text='$txt':fontfile='$fontPath':
我正在使用 ffmpeg 库在特定时间在视频上绘制文本,我成功了 我正在使用此命令将文本从上到下移动,但我无法确定 x 和 Y 从 x,y 移动到特定 x,y ffmpeg -i VideoInput
我在 ffmpeg 中为 drawtext 使用以下参数 ffmpeg -i input.gif -vf drawtext="fontfile='ariblk.ttf':text=' Hello
我必须在视频开头添加声明符几秒钟,水平居中,绿色背景,如何使用单个命令来完成并覆盖现有视频而不重新编码 最佳答案 如果您愿意将免责声明图像转换为视频剪辑,则可以将两个视频合并为一个序列而无需重新编码。
是否可以在一个 ffmpeg 命令中包含电影覆盖和绘制文本。 我尝试了命令,但它给出了错误 [drawtext @ 03B2BBC0] Key '"fontsize' not found. [draw
将一些代码从 D2007 移植到 XE2 时,我遇到了一个我无法理解的编译器错误。请参阅以下示例: procedure TForm1.FormPaint(Sender: TObject); var
如何在一张图像上显示多行 我尝试了命令,但它给出了错误 [NULL @ 0203D780] Unable to find a suitable output format for '[in][T1]'
我正在 Canvas 上绘制关于现在轮到谁的信息。我使用 validate() 两次使屏幕无效并再次绘制文本。但是使用 invalidate() 我正在重绘所有板,这会持续很长时间,有什么方法可以使
我在 Win32 程序中使用 DrawText 函数在屏幕顶部中央显示“本地”,在中央显示“服务器”。当我运行程序时,它显示“本地”而不是“服务器”。这是我的消息循环中的代码: case WM_PAI
我想在屏幕 Canvas 上绘制与第一个字符串相邻的第二个字符串。第二个字符串的起点应该是第一个字符串的宽度。我使用了Android的paint.measuretext()方法。但它返回的宽度小于实际
我的主要目标是收集用户输入并将其转换为黑色背景的视频,然后输入文本将从左向右移动,同时视频在背景中播放音频。 目前有人建议我使用“drawtext”,但我发现它不起作用。 我的命令: ffmpeg -
有没有办法检测文本何时传递给 DrawText被剪掉了? 我希望能够在给定的矩形中绘制任何文本(即已被 DrawText 剪裁,这意味着用户可能会错过文本的某些重要部分)。 我想获得显示剪切文本所需的
我正在使用 DrawText 将一些文本绘制到我在插件中制作的一堆矩形中。 现在我从嵌入式 python 接收到一个字符指针: char *a=PyString_AsString(value); 当我
我目前正在创建一个图像编辑器,并尝试使用 canvas.drawText() 在图像上绘制文本。到目前为止,我已经成功地做到了这一点,但是当用户输入太长的文本时,文本只会在页面外的一行上继续,并且不会
我是一名优秀的程序员,十分优秀!