Solved

CreateObject("Some.Application")

Posted on 2014-01-13
5
248 Views
Last Modified: 2014-01-29
What is the equivalent code of CreateObject in C# ?

Dim obj as Object
obj = CreateObject("Some.Application")
0
Comment
Question by:VBdotnet2005
5 Comments
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39777918
The equivalent would be to import the correct reference library, and then a line of code something like this:

someapplicationLib.someapplicationClass = new someapplicationLib.someapplicationClass();
0
 

Author Comment

by:VBdotnet2005
ID: 39777929
I want to convert this to C#.  Link
Public Sub resizeimG(ByVal Source As String)
        Dim jpeg
        jpeg = CreateObject("Persits.Jpeg")
        If Path.GetExtension(sourcefile) = ".jpg" Then
            Dim fn As New FileInfo(sourcefile)
            If fn.Length > 75000 Then
                jpeg.Open(sourcefile)
                If jpeg.width > 600 Then
                    jpeg.PreserveAspectRatio = True
                    jpeg.Width = 600
                    jpeg.Save(sourcefile)
                    jpeg = Nothing
                End If
            End If
        End If
    End Sub
0
 
LVL 40
ID: 39777998
Unfortunately, I do not have the time to translate the code, but I can give you a fast rundown.

Do not use CreateObject or any equivalent, because it uses an external software and is dependent on the file extensions associations on the computer on which it is run. The software that will be launched will be different from one computer to another, and you cannot assume that it will have a PreserveAspectRatio property for instance. On my computer, it would launch Paint Shop Pro, that does not have the behavior expected from the code.

the FileInfo part is OK, it gives information about the file size.

For everything else, use a Bitmap object to get the size and an resize the image, using the information given at http://tech.pro/tutorial/620/csharp-tutorial-image-editing-saving-cropping-and-resizing
0
 
LVL 19

Accepted Solution

by:
Ken Butters earned 500 total points
ID: 39779396
Looks to me like what you want to use here is the image class. (System.Drawing.Image)

What your routine looks like it is doing is reading JPG files and resizing them to a max of 600.

Here is a reference for image class:

http://msdn.microsoft.com/en-us/library/System.Drawing.Image_methods(v=vs.110).aspx


Something like this should do the trick.

(Note... I did not test this...this is just to use as a guide.)

Image newImage = Image.FromFile("SampImag.jpg");

if (image.width > 600) {
   resizePct = 600 / (float) image.width;
   image.width = 600;
   image.height = image.height * resizePct;
}
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39806683
If you still have that COM component installed on your machine then you can continue to use CreateObject in VB.NET.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now