Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add function -newbie question

Status
Not open for further replies.

kbodog

Technical User
Sep 28, 2012
1
HU
Could anyone help me to add the CropImage function to the next program/journal:
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports Microsoft.VisualBasic
Imports NXOpen.BasePart
Imports NXOpen.UF  
Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' JPG_output
' ----------------------------------------------
Dim WorkDir As String 
Dim Work_part As String 
Dim SetupJpg as string
Dim ufs As UFSession = UFSession.GetUFSession()  
SetupJpg =  theSession.Parts.Work.FullPath 'read NX internal variable
SetupJpg = Replace (SetupJpg, "prt", "jpg")
ufs.Disp.CreateImage(SetupJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)  
End Sub
End Module

It may open the SetupJPG again, but I don't know how..

Code:
Public Function CropImage(ByVal img As Image, ByVal backgroundColor As Color, Optional ByVal margin As Integer = 0) As Image
        Dim JPGminX As Integer = img.Width
        Dim JPGminY As Integer = img.Height
        Dim JPGmaxX As Integer = 0
        Dim JPGmaxY As Integer = 0
        Using bmp As New Bitmap(img)
            For y As Integer = 0 To bmp.Height - 1
                For x As Integer = 0 To bmp.Width - 1
                    If bmp.GetPixel(x, y).ToArgb <> backgroundColor.ToArgb Then
                        If x < JPGminX Then
                            JPGminX = x
                        ElseIf x > JPGmaxX Then
                            JPGmaxX = x
                        End If
                        If y < JPGminY Then
                            JPGminY = y
                        ElseIf y > JPGmaxY Then
                            JPGmaxY = y
                        End If
                    End If
                Next
            Next
            Dim rect As New Rectangle(JPGminX - margin, JPGminY - margin, JPGmaxX - minX + 2 * margin + 1, JPGmaxY - JPGminY + 2 * margin + 1)
            Dim cropped As Bitmap = bmp.Clone(rect, bmp.PixelFormat)

            Return cropped
        End Using
    End Function
thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top