When we capture screenshots, we might need to draw some shape over the screenshot to highlight some errors or some object. In such cases, we can use Dot .Net factory wherein we can draw different shapes with different colors. The below code draws rectangle in an image.
Code
Function DrawRectangle(ByVal strImagePath,ByVal inX,ByVal inY,ByVal inHeight,ByVal inWidth,ByVal strColor) Dim oPens,oGraphics,oImage,oBitmap,oRect,oFile Set oImage=DotNetFactory.CreateInstance("System.Drawing.Image","System.Drawing") Set oGraphics=DotNetFactory.CreateInstance("System.Drawing.Graphics","System.Drawing") Set oRect=DotNetFactory.CreateInstance("System.Drawing.Rectangle","System.Drawing",inX,inY,inHeight,inWidth) Set oPens=DotNetFactory.CreateInstance("System.Drawing.Pens","System.Drawing") Set oFile=DotNetFactory.CreateInstance("System.IO.File","") Set oImage=oImage.FromFile(strImagePath) Set oBitmap=DotNetFactory.CreateInstance("System.Drawing.Bitmap","System.Drawing",oImage) Set oGraphics = oGraphics.FromImage(oBitmap) Execute "oGraphics.DrawRectangle oPens."&strColor&", oRect" oImage.Dispose oFile.Delete(strImagePath) oBitmap.Save(strImagePath) Set oPens=Nothing Set oGraphics=Nothing Set oImage=Nothing Set oFile=Nothing Set oBitmap=Nothing Set oRect=Nothing End Function DrawRectangle "C:img.jpg",20,20,40,40,"RED"
Synopsis
The DrawRectangle function requires the following six argument values to be passed.
Argument 1: Image path
Argument 2: X point
Argument 3: Y point
Argument 4: Rectangle Height
Argument 5: Rectangle Width
Argument 6: Color
Note: We can use multiple colors to draw shapes. Refer the below link for different colors.
http://msdn.microsoft.com/en-US/library/system.drawing.pens_members(v=vs.80).aspx
Comments(0)