Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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]

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
-- 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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...