Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Does Silverlight 1.1 support calling components in System.Drawing namespace ?
12 replies. Latest Post by jrpowers on March 13, 2008.
(0)
kentliu
Member
10 points
9 Posts
05-18-2007 5:19 AM |
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
Participant
1084 points
249 Posts
05-18-2007 10:06 AM |
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.
05-20-2007 10:52 PM |
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 Po...
46 points
23 Posts
05-21-2007 1:24 AM |
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/
FileGeneratorhttp://www.codeplex.com/reflectoraddins
HTH,Billy
Kevin Gallo
4 points
2 Posts
05-21-2007 2:52 AM |
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?
05-21-2007 9:40 PM |
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; }
05-22-2007 2:54 AM |
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
72 points
26 Posts
09-21-2007 5:43 PM |
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
1102 points
338 Posts
09-21-2007 11:46 PM |
jrpowers: I'll open it up soon as an open source project. Until then, check it out.
Please do, it looks rather interesting!
jasonxz
1752 points
530 Posts
09-22-2007 9:47 AM |
I'm very impressed jr. I can't wait to see the source code on this one.
jjy2
354 points
155 Posts
09-24-2007 2:49 PM |
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
09-24-2007 3:05 PM |
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... )
03-13-2008 5:24 PM |
If you're still interested in checking out this image library (which is now Silverlight 2.0 ready), check out our open source page.