picture contorl怎么把背景透明

wuchongshao 2018-07-03 11:54:17


比如背景色是红色的 不要红色要中间的图象显示在picture contor 中 上传不了图片
只能用文字描述了
怎么把图中的绿色去掉显示在picture contor 中
...全文
427 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2018-08-02
  • 打赏
  • 举报
回复
不建议用picture ctrl,建议你通过定义控件实现,可参考
https://blog.csdn.net/xianglitian/article/details/6075653
schlafenhamster 2018-07-28
  • 打赏
  • 举报
回复
一种背景色 可以用
TransparentBlt
[This is preliminary documentation and subject to change.]

The TransparentBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.

BOOL TransparentBlt(
HDC hdcDest,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int hHeightDest,
HDC hdcSrc,
int nXOriginSrc,
int nYOriginSrc,
int nWidthSrc,
int nHeightSrc,
UINT crTransparent
);

赵4老师 2018-07-19
  • 打赏
  • 举报
回复
AlphaBlend
[This is preliminary documentation and subject to change.]

The AlphaBlend function displays bitmaps that have transparent or semitransparent pixels.

AlphaBlend(
HDC hdcDest,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int hHeightDest,
HDC hdcSrc,
int nXOriginSrc,
int nYOriginSrc,
int nWidthSrc,
int nHeightSrc,
BLENDFUNCTION blendFunction
);

Parameter
hdcDest
Handle to the destination device context.
nXOriginDest
Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nYOriginDest
Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nWidthDest
Specifies the width, in logical units, of the destination rectangle.
hHeightDset
Handle to the height, in logical units, of the destination rectangle.
hdcSrc
Handle to the source device context.
nXOriginSrc
Specifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle.
nYOriginSrc
Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle.
nWidthSrc
Specifies the width, in logical units, of the source rectangle.
nHeightSrc
Specifies the height, in logical units, of the source rectangle.
blendFunction
Specifies the alpha blending function for source and destination bitmaps, a global alpha value to be applied to the entire source bitmap, and format information for the source bitmap. The source and destination blend functions are currently limited to AC_SRC_OVER. See the BLENDFUNCTION and EMRALPHABLEND structures.
Return Values
If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE.

Windows NT: To get extended error information, callGetLastError.

Remarks
If the source rectangle and destination rectangle are not the same size, the source bitmap is stretched to match the destination rectangle. If the SetStretchBltMode function is used, the iStretchMode value is BLACKONWHITE and WHITEONBLACK; the iStretchMode value is automatically converted to COLORONCOLOR for this function.

The destination coordinates are transformed by using the transformation currently specified for the destination device context. The source coordinates are transformed by using the transformation currently specified for the source device context.

An error occurs (and the function returns FALSE) if the source device context identifies an enhanced metafile device context.

If destination and source bitmaps do not have the same color format, AlphaBlend converts the source bitmap to match the destination bitmap.

AlphaBlend does not support mirroring. If either the width or height of the source or destination is negative, this call will fail.

Note: The SourceConstantaAlpha member of BLENDFUNCTION specifies an alpha transparancy value to be used on the entire source bitmap. The SourceConstantAlpha value is combined with any per-pixel alpha values. If you set SourceConstantAlpha to 0, it is assumed that your image is transparent. Set the SourceConstantAlpha value to 255 (indicates that the image is opaque) when you only want to use per-pixel alpha values.

QuickInfo
Windows NT: Requires version 5.0 or later.
Windows: Requires Windows 98 or later.
Windows CE: Unsupported.
Header: Declared in wingdi.h.
Import Library: Included as a resource in msimg32.dll.

See Also
Bitmaps Overview, Bitmap Functions


绿色盒子 2018-07-19
  • 打赏
  • 举报
回复
这问题看的我稀里糊涂的
weixin_36514487 2018-07-19
  • 打赏
  • 举报
回复
举个简单的例子:
CBrush newBrush; CBrush *pOldBrush; newBrush.CreateSolidBrush(RGB(0,0,0)); CClientDC clientDC(this); CRect rect; m_Picture.GetWindowRect(&rect); ScreenToClient(&rect); pOldBrush = clientDC.SelectObject(&newBrush); clientDC.Rectangle(rect); clientDC.SetBkMode(TRANSPARENT); clientDC.SetTextColor(RGB(255,255,255)); clientDC.TextOutW(rect.left+rect.Width()/2,rect.top+rect.Height()/2,_T("呵呵哒"),3);
weixin_36514487 2018-07-18
  • 打赏
  • 举报
回复
没明白你说的问题,不过可以试试这几个函数 SetBkColor:设置背景颜色 (文本的背景色) SetTextColor:设置文本颜色 (输出文字的颜色) SetBkMode:设置背景模式 (是否背景透明) 我当时遇到的问题是黑色背景中显示几个字,但是字会有白色小筐,这时候用setbkmode(TRANSPARENT )就好了
赵4老师 2018-07-03
  • 打赏
  • 举报
回复

PaintPicture 方法


用以在 Form, PictureBox 或 Printer 上绘制图形文件(.bmp、.wmf、.emf、.cur、.ico或 .dib)的内容。不支持命名参数。

语法

object.PaintPicture picture, x1, y1, width1, height1, x2, y2, width2, height2, opcode

PaintPicture 方法的语法包含下列部分:

部分 描述
object 可选的。一个对象表达式,其值为“应用于”列表中的一个对象。如果省略 object,带有焦点的 Form 对象缺省为 object。
Picture 必需的。要绘制到 object 上的图形源。Form 或 PictureBox 必须是 Picture 属性。
x1, y1 必需的。均为单精度值,指定在 object 上绘制 picture 的目标坐标(x-轴和y-轴)。object 的 ScaleMode 属性决定使用的度量单位。
Width1 可选的。单精度值,指示 picture 的目标宽度。object 的 ScaleMode 属性决定使用的度量单位。如果目标宽度比源宽度 (width2) 大或小,将适当地拉伸或压缩 picture。如果该参数省略,则使用源宽度。
Height1 可选的。 单精度值,指示 picture 的目标高度。object 的 ScaleMode 属性决定使用的度量单位。如果目标高度比源高度 (height2) 大或小,将适当地拉伸或压缩 picture。如果该参数省略,则使用源高度。
x2, y2 可选的。均为单精度值,指示 picture 内剪贴区的坐标(x-轴和y-轴)。object 的 ScaleMode 属性决定使用的度量单位。如果该参数省略,则缺省为 0。
Width2 可选的。单精度值,指示 picture 内剪贴区的源宽度。object 的 ScaleMode 属性决定使用的度量单位。如果该参数省略,则使用整个源宽度。
Height2 可选的。 单精度值,指示 picture 内剪贴区的源高度。object 的 ScaleMode 属性决定使用的度量单位。如果该参数省略,则使用整个源高度。
Opcode 可选的。是长型值或仅由位图使用的代码。它用来定义在将 pictur 绘制到 object 上时对 picture 执行的位操作(例如, vbMergeCopy 或 vbSrcAnd 操作符)。关于位操作符常数的完整列表,请参阅 Visual Basic Help 文件中的 RasterOp Constants 主题。
在使用opcode时有一些限制。例如,如果资源是图标或图元文件,则只能使用 vbSrcCopy,而不能使用其他的opcode;并且,与图案 (或 SDK 术语中的"画笔"),如 MERGECOPY、 PATCOPY、 PATPAINT 和 PATINVERT,相交互的opcode实际上是同目标的 FillStyle 属性交互。

注意 Opcode 用于将按位操作传递到位图。当传递其他图象类型时将一个值给该参数会造成“无效过程调用或参数”错误。这是设计的原因。要避免这个错误,对于除位图外的图象,将 Opcode 参数置为空。



说明

通过使用负的目标高度值 (height1) 和 / 或目标宽度值 (width1) ,可以水平或垂直翻转位图。

可以省略任何多个可选的尾部的参数 。如果省略了一个或多个可选尾部参数,则不能在指定的最后一个参数后面使用逗号。如果想指定某个可选参数,则必须先指定语法中出现在该参数前面的全部参数。

注意,在将一个.Bmp加载入 PictureBox 控件和使用 Windows API 函数 BitBlt() 添加图片之间有一点不同。当您对一个图象使用 BitBlt() 时,PictureBox 控件不知道象您使用 LoadPicture方法那样去调整大小。将 ScaleWidth 和 ScaleHeight 属性设置为图象的大小也不起作用。如果您想在使用 BitBlt 之后用 PictureBox 调整新图片的大小,必须用代码手工做,转换单位并处理边框,下面是如何这样做的一个简单示例:

Sub ResizePictureBoxToImage(pic as PictureBox, twipWd _
as Integer, twipHt as Integer)
' 该代码假设所有的单位都为缇。如果
' 不是,必须在调用该例程之前,转换为缇。
' 这里也假设图象显示在0,0处。
Dim BorderHt as Integer, BorderWd as Integer
BorderWd = Pic.Width - Pic.ScaleWidth
BorderHt = Pic.Height - Pic.ScaleHeight
pic.Move pic.Left, pic.Top, twipWd + BorderWd, _
twipHt + BorderHt
End Sub

15,979

社区成员

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

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