JumpyNET Posted May 27, 2011 Posted May 27, 2011 What I do here is I 1) load an image file 2) blurr the image 3) pass the image to a third party component (which will save the image inside a pdf file) that accepts System.Drawing.Image, but does not do any post processing like compressing it, and the resulting big file size suggest that the file is saved as a bmp file. (If pass an unblurred image the third party component it saves the image in the original image format and results in the same small file size as the original image.) So my question is how do I compress the blurred image without making a temporary copy of it to a hard disk? [Vb] Dim Filter As New AForge.Imaging.Filters.GaussianBlur(0.1, 4) Dim SourceImg As System.Drawing.Bitmap = AForge.Imaging.Image.FromFile("E:\Small.png") Dim BlurredImage As System.Drawing.Bitmap = Filter.Apply(SourceImg) Dim Compressed As New System.IO.FileStream("?") BlurredImage.Save(Compressed, System.Drawing.Imaging.ImageFormat.Png) Me.BackgroundImage = Bitmap.FromStream(Compressed) [/code] Quote
Administrators PlausiblyDamp Posted May 27, 2011 Administrators Posted May 27, 2011 When you are saving the Image using BlurredImage.Save the first parameter can be any Stream derived class not just a FileStream. You could do something like Dim Filter As New AForge.Imaging.Filters.GaussianBlur(0.1, 4) Dim SourceImg As System.Drawing.Bitmap = AForge.Imaging.Image.FromFile("E:\Small.png") Dim BlurredImage As System.Drawing.Bitmap = Filter.Apply(SourceImg) Dim data() as Byte Dim Compressed As New System.IO.MemoryStream(data) BlurredImage.Save(Compressed, System.Drawing.Imaging.ImageFormat.Png) Me.BackgroundImage = Bitmap.FromStream(Compressed) which should work. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JumpyNET Posted May 27, 2011 Author Posted May 27, 2011 -- the first parameter can be any Stream derived class not just a FileStream. -- I had no idea there was such a thing as a MemoryStream. Thanks a lot! Seems to work nicely without the buffer in the MemoryStream() constructor. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.