?
Solved

CreateObject("Some.Application")

Posted on 2014-01-13
5
Medium Priority
?
257 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

831 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