Solved

CreateObject("Some.Application")

Posted on 2014-01-13
5
247 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

10 Experts available now in Live!

Get 1:1 Help Now