Solved

CreateObject("Some.Application")

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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