Skip to main content

Microsoft Silverlight

Unanswered Question Does Silverlight 1.1 support calling components in System.Drawing namespace ?RSS Feed

(0)

kentliu
kentliu

Member

Member

10 points

9 Posts

Does Silverlight 1.1 support calling components in System.Drawing namespace ?

Hi, I am using vs 2005 to write Silverlight 1.1 program and try to call System.Drawing.Image.FromStream (the stream has been loaded by OpenDialog.SelectedFile.OpenRead successful).

But I found that once my program add any code calling System.Drawing components, the Silverlight would not work.  And after I remark any code calling System.Drawing, it works again.

Is this a limit for alpha version or in the feature it would not support calling System.Drawing components ?

Please help, thanks!

Dave Relyea
Dave Relyea

Participant

Participant

1084 points

249 Posts

Microsoft

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

Silverlight uses a subset of the .Net framework, to reduce the download size. This means that some things simply aren't there. It may be possible to include .Net 3.0 assemblies as references, and build successfully against them, but running will not work. Sounds like System.Drawing (or at least the class that you are trying to use) is something that isn't there. I can't check right now, but you can use Reflector to look at the Silverlight assemblies to find out exactly what is and what is not there.

kentliu
kentliu

Member

Member

10 points

9 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

So, if I wish to use the GDI+ to drawing something on the fly in client / resize the picture on the fly, then it would be impossible ? 

If yes, what a pity. 

I think if add feature to call GDI+ to Silverlight, it would be more better and more closer to be the "Flash killer".

Billy Porter
Billy Po...

Member

Member

46 points

23 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

You could actually use Reflector + the FileGenerator plugin to dump the entire source code of the System.Drawing namespace to disk. Then you could use just the classes (and any dependencies they might have) to create a lightweight version of the desired assembly that your code can build + run against. Links below: 

Reflector:
http://www.aisto.com/roeder/dotnet/

FileGenerator
http://www.codeplex.com/reflectoraddins

HTH,
Billy

Kevin Gallo
Kevin Gallo

Member

Member

4 points

2 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

Silverlight provides a much faster graphics and media stack more in line with WPF than with GDI+.  Is there functionality in GDI+ that you would like that Silverlight or WPF do not provide?

kentliu
kentliu

Member

Member

10 points

9 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

Yes, I wish to do something such as resize the picture and upload it (such as msn space does), currently we are using the ActiveX control (written by c++) in our intranet application, this control is using GDI+ to do the resize works.  I simply thought converting it to C# and compile it in the Silverlight 1.1 Alpha project would be OK (sure, need to add System.Drawing reference), but failed.  After search the components in Silverlight 1.1, I thought maybe there is no way to do the thing I wished by using components in Silverlight 1.1, so I posted the question and request for help.

I thought, GDI+ provides many powerful features, and seems not all are supported in Silverlight 1.1 Alpha, so I wish in the feature version of Silverlight 1.1 would provide System.Drawing (wrapper of GDI+) to make Silverlight become real "Flash killer".

If you know how to do the same thing in Silverlight 1.1 Alpha, please help me out, thanks!

Following is the snipped c# code :

...  Image imgSource = Image.FromFile(.....); Image imgTarget = scaleByPercent(imgSource, 50); ...
         private System.Drawing.Image scaleByPercent(System.Drawing.Image imgPhoto, int Percent)
        {
            float nPercent = ((float)Percent / 100);

            int sourceWidth = (int)imgPhoto.Width;
            int sourceHeight = (int)imgPhoto.Height;
            int sourceX = 0;
            int sourceY = 0;

            int destX = 0;
            int destY = 0;
            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);

            System.Drawing.Bitmap bmPhoto =
                new System.Drawing.Bitmap(destWidth, destHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            System.Drawing.Graphics grPhoto = System.Drawing.Graphics.FromImage(bmPhoto);
            grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            grPhoto.DrawImage(imgPhoto,
                new System.Drawing.Rectangle(destX, destY, destWidth, destHeight),
                new System.Drawing.Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                System.Drawing.GraphicsUnit.Pixel);

            grPhoto.Dispose();
            return bmPhoto;
        }

 

kentliu
kentliu

Member

Member

10 points

9 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

Billy Porter, I've tried your suggestion, but after add single line "System.Drawing.Image imgSource = System.Drawing.Image.FromFile(fileName);", then I need to add many many files in System.Drawing, mscorlib, System.Configuration, System dll, and already has added about hundred files and still not end, and I also got the "Error 7 Unsafe code may only appear if compiling with /unsafe" compiling error (even I've added the /unsafe parameter in build option of project property page).

Seems your suggestion would not work, do you have any other good ideas ?

jrpowers
jrpowers

Member

Member

72 points

26 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

You might be interested in fluxify.  It resizes images client-side with Silverlight

I'll open it up soon as an open source project.  Until then, check it out.

party42
party42

Participant

Participant

1102 points

338 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

jrpowers:

I'll open it up soon as an open source project.  Until then, check it out.

 

 

Please do, it looks rather interesting! 

Regards,
Nathan Brouwer

http://www.nathanbrouwer.nl

jasonxz
jasonxz

Participant

Participant

1752 points

530 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

I'm very impressed jr.  I can't wait to see the source code on this one.

jjy2
jjy2

Member

Member

354 points

155 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

jrpowers:

You might be interested in fluxify.  It resizes images client-side with Silverlight

I'll open it up soon as an open source project.  Until then, check it out.

Is this available yet (source code)? it looks cool Yes

jrpowers
jrpowers

Member

Member

72 points

26 Posts

Re: Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

Source isn't available yet but keep checking back on the blog and bugging us.  We've been fixing bugs and improving performance.  There's also a semi-secret feature: if you've got Firefox, try Shift-clicking a photo.  (IE doesn't support the data URI spec so the feature's on the down-low until I figure out a workaround... )

jrpowers
jrpowers

Member

Member

72 points

26 Posts

Re: Does Silverlight 1.1 support calling components in System.Drawing namespace ?

If you're still interested in checking out this image library (which is now Silverlight 2.0 ready), check out our open source page. 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities