asp.net - Is it OK to use WPF assemblies in a web app? -
i have asp.net mvc 2 app targeting .net 4 needs able resize images on fly , write them response.
i have code , works. using system.drawing.dll.
however, want enhance code not resizing image, dropping 24bpp down 4bit grayscale. not, life of me, find code on how system.drawing.dll.
but did find bunch of wpf stuff. working/sample code (runs in linqpad).
// load original 24 bit image var bitmapimage = new bitmapimage(); bitmapimage.begininit(); bitmapimage.urisource = new uri(@"c:\temp\resized\18_appa2_015.png", urikind.absolute); //bitmapimage.decodepixelwidth = 600; bitmapimage.endinit(); // create destination image var formatconvertedbitmap = new formatconvertedbitmap(); formatconvertedbitmap.begininit(); formatconvertedbitmap.source = bitmapimage; formatconvertedbitmap.destinationformat = pixelformats.gray4; formatconvertedbitmap.endinit(); // encode , dump image disk var encoder = new pngbitmapencoder(); encoder.frames.add(bitmapframe.create(formatconvertedbitmap)); using (var filestream = file.create(@"c:\temp\resized\18_appa2_015_s2.png")) { encoder.save(filestream); } it uses system.xaml.dll, windowsbase.dll, presentationcore.dll, , presentationframework.dll. namespaces used are: system.windows.controls, system.windows.media, , system.windows.media.imaging.
is there problem using these namespaces in web application? doesn't seem right.
if knows how drop bit depth without wpf stuff (which barely understand, btw) thrilled see too.
no problem. can use wpf image manipulation within asp.net web site. i've used wpf behind scenes within web site several times before, , works great.
the 1 issue did run many parts of wpf insist calling threads sta threads. if web site uses mta threads instead error telling wpf needs sta threads. fix this, use stathreadpool class posted in this answer.
Comments
Post a Comment