首页 > 其他分享 >DrawImage On DeskTop with GDI Plus

DrawImage On DeskTop with GDI Plus

时间:2022-11-25 16:00:54浏览次数:41  
标签:Bub1 Bx image Plus dx dy GDI DrawImage dist

; Draw image on desktop with GDI Plus

If OpenLibrary(0, "gdiplus.dll") = 0
  MessageRequester("Error","Required component gdiplus.dll is not found. Please install it and retry    ", #MB_ICONERROR)
  End
EndIf
Structure GdiplusStartupInput
  GdiPlusVersion.i
  *DebugEventCallback.DebugEventProc
  SuppressBackgroundThread.i
  SuppressExternalCodecs.i
EndStructure
Structure RectF
  x.f
  y.f
  width.f
  height.f
EndStructure

Structure ColorMatrix ;{ 
  M00.f 
  M01.f 
  M02.f 
  M03.f 
  M04.f 
  M10.f 
  M11.f 
  M12.f 
  M13.f 
  M14.f 
  M20.f 
  M21.f 
  M22.f 
  M23.f 
  M24.f 
  M30.f 
  M31.f 
  M32.f 
  M33.f 
  M34.f 
  M40.f 
  M41.f 
  M42.f 
  M43.f 
  M44.f 
EndStructure ;}

Global ncolor.ColorMatrix
With ncolor
  \M00=1
  \M11=1
  \M22=1
  \M33=1
  \M44=1
EndWith

#UnitPixel=2
#Count=10

Global Dim Bx.w(#Count),Dim By.w(#Count)
Global Dim adx.w(#Count),Dim ady.w(#Count)
Global Dim nColors.f(#Count,3)
Global D.w=180
Global Dw.w,Dh.w
Global m_hdcMemory
Global *imgc

Import "gdiplus.lib"
  GdiplusStartup(token, *input.GdiplusStartupInput, output)
  GdiplusShutdown(token)
  GdipCreateFromHDC(hdc, *graphics)
  GdipReleaseDC(*graphics, hdc.l)
  GdipLoadImageFromFile(filename.p-unicode, *image)
  GdipCloneImage(*image, *cloneImage)
  GdipGetImageHeight(*image, *height.integer)
  GdipGetImageWidth(*image, *width.integer)
  GdipImageRotateFlip(*image, rotateFlipType)
  GdipGetImageBounds(*image, *srcRect.RectF, *srcUnit.integer)
  GdipDrawImage(*graphics, *image, x.f, y.f)
  GdipDrawImageI(*graphics, *image, x.l, y.l)
  GdipDrawImageRectI(*graphics, *image, x.l, y.l, width.l, height.l)
  GdipDrawImageRect(*graphics, *image, x.f, y.f, width.f, height.f)
  GdipGraphicsClear(*graphics, color)
  GdipDisposeImage(image)
  GdipDeleteGraphics(*graphics) 
  GdipCreateImageAttributes(*imageattr)
  GdipDisposeImageAttributes(*imageattr)
  GdipResetImageAttributes(*imageattr, type.l)
  SetColorMatrix(*In_ImageAttr, *In_colorMatrix)
  GdipSetImageAttributesColorMatrix(*imageattr, type.l, enableFlag.l, *colorMatrix.ColorMatrix, *grayMatrix.ColorMatrix, flags.l)
  GdipDrawImageRectRect(*graphics, *image, dstx.f, dsty.f, dstwidth.f, dstheight.f, srcx.f, srcy.f, srcwidth.f, srcheight.f, srcUnit.l, *ImageAttributes, *callback, *callbackData)
  ;GdipSetImageAttributesColorMatrix(*In_ImageAttr, #ColorAdjustTypeDefault, #True, *In_colorMatrix, #Null, #ColorMatrixFlagsDefault)
EndImport 

Declare checkCollision(bub0, bub1)
Declare BlitWindow(*image)
ExamineDesktops()
dw=DesktopWidth(0)
dh=DesktopHeight(0)

input.GdiplusStartupInput
input\GdiPlusVersion = 1.1
GdiplusStartup(@token, @input, #Null)

GdipLoadImageFromFile("popobluebig.png", @image) 
;GdipCloneImage(image,@imgc)

For i=1 To #Count
  adx(i)=10:ady(i)=10
Next i

RandomSeed(Date())
For i=1 To #Count
  Bx(i)=Random(dw,0)
  By(i)=Random(dh,0)
Next i

If ExamineDesktops()
OpenWindow(0,0,0,DesktopWidth(0),DesktopHeight(0),"Gdiplus Drawing",#PB_Window_ScreenCentered|#PB_Window_BorderLess)

SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED|#WS_EX_TRANSPARENT|#WS_EX_TOPMOST)
SetWindowPos_(WindowID(0),#HWND_TOPMOST,#Null,#Null,#Null,#Null,#SWP_NOMOVE|#SWP_NOSIZE)

Repeat
  EventID = WindowEvent()
  Select EventID 
    ;Case #WM_LBUTTONDOWN
     ; SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
;     Case #PB_Event_Menu
;       If EventMenu()=9 : End : EndIf
;     Case #WM_RBUTTONDOWN
;       DisplayPopupMenu(0, WindowID(0))
     Case #WM_KEYDOWN
      If EventwParam()=27
        End
      EndIf
      
  EndSelect
  BlitWindow(image)
Until EventID = #PB_Event_CloseWindow
EndIf
End


Procedure checkCollision(bub0, bub1)
  Protected dx.w,dy.w,Dist.w,px1.w,px2.w,py1.w,py2.w,dx2.w,dy2.w,d2.w
  dx=Abs(Bx(bub1)-Bx(bub0))
  dy=Abs(By(bub1)-By(bub0))
  dist=Sqr(dx*dx+dy*dy);
  If dist = 0 
    dist= 1
  EndIf
  D2=D-Dist
  If d2>=0 
    ;  p的速度的交换分
    py1=(dy* dy) *Ady(bub1)/dist / dist +(dy * dx)*Adx(Bub1)/dist /dist
    px1=(dx* dx) *Adx(Bub1)/dist / dist +(dx * dy)*Ady(Bub1)/dist /dist
    
    ; this的速度的交换分量
    py2=(dy* dy) *Ady(Bub0)/dist /dist +(dy * dx)*Adx(Bub0)/dist /dist
    px2=(dx* dx) *Adx(Bub0)/dist /dist +(dx * dy)*Ady(Bub0)/dist /dist
    
    Adx(Bub0)=Adx(Bub0)+px1-px2
    Ady(Bub0)=Ady(Bub0)+py1-py2
    
    Adx(Bub1)=Adx(Bub1)-px1+px2
    Ady(Bub1)=Ady(Bub1)-py1+py2
  EndIf
  If d2>0
    ;移动第二个圆到延长线上去。
    dx2=D2 * (Bx(Bub1) -Bx(Bub0)) / Dist
    dy2=D2 * (By(Bub1) -By(Bub0)) / Dist
    Bx(Bub1)=Bx(Bub1)+dx2
    By(Bub1)=By(Bub1)+dy2
    ;//this._pCenter.X -= (float)(dx2 / 2.0);
    ;//this._pCenter.Y -= (float)(dy2 / 2.0);
  EndIf
EndProcedure
Procedure BlitWindow(image)
  hdcTemp = GetDC_(WindowID(0))
  m_hdcMemory = CreateCompatibleDC_(hdcTemp)
  hBitMap = CreateCompatibleBitmap_(hdcTemp,Dw,Dh)
  SelectObject_(m_hdcMemory,hBitMap)
  hdcScreen = GetDC_(WindowID(0))
  GdipCreateFromHDC(m_hdcMemory,@gfx)
  GdipCreateImageAttributes(@attr)
    
  For i=1 To #Count
    If Random(20)<2
       nColors(i,0)= Random(20,0)/10-1
       nColors(i,1)= Random(20,0)/10-1
       nColors(i,2)= Random(20,0)/10-1
    EndIf
    
    ncolor\M40=nColors(i,0)
    ncolor\M41=nColors(i,1)
    ncolor\M42=nColors(i,2)
    ;ncolor\M33=nColors(i,3);//透明度 0-1

    GdipSetImageAttributesColorMatrix(attr,0,#True,ncolor,#NUL,0)
    For j=2 To #Count      
      checkCollision(i,j)
    Next j
    
    ;GdipDrawImageRectI(gfx, image, Bx(i), By(i),D,D);//Can not work well
    GdipDrawImageRectRect(gfx,image,Bx(i),By(i),D,D,0,0,D,D,#UnitPixel,attr,#Null,#Null)
    
    Bx(i)=Bx(i)+Adx(i) : By(i)=By(i)+Ady(i)
    If Bx(i)>dw-D
      Bx(i)=Dw-d
      Adx(i)=-Adx(i)
    EndIf
    If Bx(i)<0
      Bx(i)=0
      Adx(i)=-Adx(i)
    EndIf
    If By(i)>Dh-D
      By(i)=Dh-D
      Ady(i)=-Ady(i)
    EndIf
    If By(i)<0
      By(i)=0
      Ady(i)=-Ady(i)
    EndIf
    If Adx(i)=0
      Adx(i)=6
    EndIf
    If Ady(i)=0
      Ady(i)=6
    EndIf
  Next i
  With sz.SIZE
    \cx =dw;ImageWidth(image)
    \cy =dh;ImageHeight(image)
  EndWith
  With ContextOffset.Point
    \x=0
    \y=0
  EndWith
  With BlendMode.BLENDFUNCTION
    \BlendOp=#AC_SRC_OVER    ;On the top [0]
    \BlendFlags=0
    \SourceConstantAlpha = 255
    \AlphaFormat = #AC_SRC_ALPHA ;every one [1]
  EndWith
  
  UpdateLayeredWindow_(WindowID(0),hdcScreen,0,@sz,m_hdcMemory,@ContextOffset.POINT,$0,@BlendMode,#ULW_ALPHA)
  GdipDisposeImageAttributes(attr)
  GdipDeleteGraphics(gfx)
  GdipReleaseDC(gfx, m_hdcMemory)
  ReleaseDC_(WindowID(0),hdcTemp)
  ReleaseDC_(WindowID(0),hdcScreen)
  DeleteDC_(m_hdcMemory)
  DeleteObject_(hBitMap)
;   Debug hdcScreen
;   Debug hdcTemp
EndProcedure

  

标签:Bub1,Bx,image,Plus,dx,dy,GDI,DrawImage,dist
From: https://www.cnblogs.com/PBprogram/p/16925434.html

相关文章

  • 最全的PyInputPlus模块方法总结
    安装第三方模块    在Windows和macOS中,pip会随着Python自动安装。可以通过命令行窗口输入pip检查是否已经安装。但在Linux中,必须由你单独安装。在UbuntuLi......
  • 提升汽车APP用户体验,火山引擎APMPlus的“独家秘笈”
    随着数字经济时代的到来,以大数据、云计算、人工智能为代表的新技术正在引领各行各业实现数字化转型。对于汽车行业而言,如何帮助企业从容应对发展新趋势,赢得市场机遇,已成为......
  • mybatisplus-plus实现多主键批量保存或更新
    一、依赖<dependencies>......//其他依赖<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boo......
  • SpringBoot整合mybatis plus报错:net.sf.jsqlparser.schema.Column, is available from
     Anattemptwasmadetocallthemethodnet.sf.jsqlparser.schema.Column.withColumnName(Ljava/lang/String;)Lnet/sf/jsqlparser/schema/Column;butitdoesnote......
  • 直播软件搭建,vue3应用elementPlus table并滚动显示
    直播软件搭建,vue3应用elementPlustable并滚动显示1、首先使用了elementplus的table <template> <div>  <el-table   ref="table1"   :data="state......
  • mybatisplus+lombok
       lombok:导入依赖坐标@data包含了除了构造方法之外的所有实体类方法       条件查询:三种方式     查询投影:固定字段 ......
  • 在sqlplus中实现命令的上翻下翻功能
    文章目录​​1、安装rlwrap软件包​​​​2、设置指令的别名​​​​3、获取视频教程​​​​4、版权声明​​在Oracle的sqlplus中,使用SQL语句不太方便,sqlplus没有提供类似......
  • freecplus框架简介
    文章目录​​一、freecplus框架简介​​​​二、freecplus开源许可协议​​​​三、freecplus框架内容​​​​字符串操作​​​​2、xml解析​​​​3、日期时间​​​​4......
  • freecplus框架-MySQL数据库操作
    文章目录​​一、源代码说明​​​​二、概述​​​​三、connection类​​​​四、sqlstatement类​​​​五、程序流程​​​​1、无结果集SQL的程序的流程​​​​2、有......
  • freecplus框架-Oracle数据库操作
    文章目录​​一、源代码说明​​​​二、概述​​​​三、connection类​​​​四、sqlstatement类​​​​五、程序流程​​​​1、无结果集SQL的程序的流程​​​​2、有......