纯代码方式的图片透明传输

原创 2004年06月23日 07:04:00

Option Explicit
Public Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Public Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Public Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public Declare Function SetBkColor Lib "gdi32.dll" (ByVal hdc As Long, ByVal crColor As Long) As Long
Public Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Public Declare Function StretchBlt Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

Public Function TBitBlt(ByVal hDestDC As Long, _
                        ByVal x As Long, ByVal y As Long, _
                        ByVal nWidth As Long, ByVal nHeight As Long, _
                        ByVal hSrcDC As Long, _
                        ByVal xSrc As Long, ByVal ySrc As Long, _
                        ByVal TransColor As Long) As Long
Dim hTmpDC As Long, hMonoDC As Long
Dim hTmpBmp As Long, hMonoBmp As Long
Dim hTmpBmpOld As Long, hMonoBmpOld As Long
   
    hMonoDC = CreateCompatibleDC(0)
    hMonoBmp = CreateCompatibleBitmap(hMonoDC, nWidth, nHeight)
    hMonoBmpOld = SelectObject(hMonoDC, hMonoBmp)

    hTmpDC = CreateCompatibleDC(hSrcDC)
    hTmpBmp = CreateCompatibleBitmap(hSrcDC, nWidth, nHeight)
    hTmpBmpOld = SelectObject(hTmpDC, hTmpBmp)
    BitBlt hTmpDC, 0, 0, nWidth, nHeight, hSrcDC, xSrc, ySrc, vbSrcCopy


    Call SetBkColor(hTmpDC, TransColor)
    BitBlt hMonoDC, 0, 0, nWidth, nHeight, hTmpDC, 0, 0, vbSrcCopy
    BitBlt hTmpDC, 0, 0, nWidth, nHeight, hMonoDC, 0, 0, vbNotSrcCopy
    BitBlt hTmpDC, 0, 0, nWidth, nHeight, hSrcDC, xSrc, ySrc, vbSrcAnd

    BitBlt hDestDC, x, y, nWidth, nHeight, hMonoDC, 0, 0, vbSrcCopy

    BitBlt hDestDC, x, y, nWidth, nHeight, hTmpDC, 0, 0, vbSrcPaint

    Call SelectObject(hTmpDC, hTmpBmpOld)
    Call SelectObject(hMonoDC, hMonoBmpOld)


    Call DeleteDC(hMonoDC)
    Call DeleteDC(hTmpDC)
    Call DeleteObject(hMonoBmp)
    Call DeleteObject(hTmpBmp)
    Call DeleteObject(hMonoBmpOld)
    Call DeleteObject(hTmpBmpOld)
   
'    BitBlt Form1.p.hdc, x, y, nWidth, nHeight, hTmpDC, xSrc, ySrc, vbSrcCopy
'    BitBlt Form1.p.hdc, x, y, nWidth, nHeight, hMonoDC, xSrc, ySrc, vbSrcCopy

End Function
Public Function TStretchBlt(ByVal hDestDC As Long, _
                            ByVal x As Long, ByVal y As Long, _
                            ByVal nWidth As Long, ByVal nHeight As Long, _
                            ByVal hSrcDC As Long, _
                            ByVal xSrc As Long, ByVal ySrc As Long, _
                            ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, _
                            ByVal TransColor As Long)
Dim hMidDC As Long, hMidBmp As Long, hMidBmpOld As Long
    hMidDC = CreateCompatibleDC(hSrcDC)
    hMidBmp = CreateCompatibleBitmap(hSrcDC, nWidth, nHeight)
    hMidBmpOld = SelectObject(hMidDC, hMidBmp)
   
    StretchBlt hMidDC, 0, 0, nWidth, nHeight, hSrcDC, xSrc, ySrc, nSrcWidth, nSrcHeight, vbSrcCopy
   
    TBitBlt hDestDC, x, y, nWidth, nHeight, hMidDC, 0, 0, TransColor
   
    Call SelectObject(hMidDC, hMidBmpOld)
   
    Call DeleteDC(hMidDC)
    Call DeleteObject(hMidBmp)
    Call DeleteObject(hMidBmpOld)
   
End Function


 用法基本与BitBlt相同

透明传输方法总结

原文出处: http://blog.csdn.net/u014301418/article/details/24877431 帧的传送需要具有透明性,即透明传输。透明传输是指不管所传数据是什么样的...
  • HUA425387356
  • HUA425387356
  • 2014年12月29日 16:41
  • 2682

7、如何实现透明传输

透明传输的基本概念: 数据透明传输就是用户不受协议中的任何限制,可随机的传输任意比特编码的信息用户可以完全不必知道协议中所规定的结束段的比特编码或者其他的控制字符,因而不受限制的进行传输。 ...
  • xie294777315
  • xie294777315
  • 2014年04月20日 10:45
  • 2501

透明传输

透明传输是指不管所传数据是什么样的比特组合,都应当能够在链路上传送。当所传数据中的比特组合恰巧与某一个控制信息完全一样时,就必须采取适当的措施,使接收方不会将这样的数据误认为是某种控制信息。这样才能保...
  • duqi_2009
  • duqi_2009
  • 2011年01月12日 15:54
  • 2861

数据链路层三个问题---封装成帧、透明传输、差错检查

数据链路层: 前言: 数据链路层使用的信道主要有以下的两种类型:  1. 点对点信道。这种信道使用一对一的点对点信道方式。  2. 广播信道。这种信道使用一对多的广播通信方式,因此过程比较复杂。 通...
  • hj605635529
  • hj605635529
  • 2017年05月14日 16:08
  • 467

点对点通信解决透明传输的方法

计算机网络、点对点透明传输、数据链路层
  • HK_5788
  • HK_5788
  • 2016年08月19日 10:28
  • 856

JAVA中传输图片的示例

利用JAVA中的字节流传输图片 服务端代码 Server package net; import java.io.BufferedInputStream; import java.io....
  • u010214003
  • u010214003
  • 2015年01月17日 18:16
  • 3366

数据链路层的三个基本问题:封装成帧 透明传输 差错检测

一. 封装成帧 透明传输 差错检测
  • azsx02
  • azsx02
  • 2017年04月06日 11:29
  • 1244

纯代码实现图片预览

1UI效果图 2.代码实现 // // ViewController.m // 04-图片浏览器 // // Created by liuhang on 15...
  • LiuHang03
  • LiuHang03
  • 2015年11月20日 22:51
  • 215

Zigbee串口透明传输(转载)

http://blog.sina.com.cn/s/blog_6ad3d9630100yp3y.html 使用的协议栈版本信息: ZigBee2006\ZStack-1.4.3-1.2....
  • tanqiuwei
  • tanqiuwei
  • 2012年06月07日 10:27
  • 5326

android 设置图片透明

方法一: 在xml中,设置如下 java
  • hhbgk
  • hhbgk
  • 2012年10月23日 10:36
  • 6650
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:纯代码方式的图片透明传输
举报原因:
原因补充:

(最多只允许输入30个字)