ajay raju

ajay raju

  • NA
  • 397
  • 0

how to save resized image in windows applications?

Oct 13 2010 8:54 AM


hi,
 i developing one windows application in that application i load the image into picturebox and after that i resize the image image and next save the resized image.

 i write a code for resize image is

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim image As Image = New Bitmap(ofd_Image.FileName)
        Dim [Delegate] As New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
        pb_image.Image = image.GetThumbnailImage(200, 150, [Delegate], IntPtr.Zero)
    End Sub

    Private Function ThumbnailCallback() As Boolean
        Return False
    End Function

and i write a code for save image is:

Dim fs As FileStream
    Dim br As BinaryReader
    Dim bw As BinaryWriter
    Dim photo() As Byte
    Dim save_ThumbimgPath As String = "D:\test.jpg"
fs = New FileStream(pb_image.ImageLocation, FileMode.Open, FileAccess.Read)
       br = New BinaryReader(fs)
       ReDim photo(fs.Length)
       photo = br.ReadBytes(fs.Length)
       br.Close()
       fs = New FileStream(save_ThumbimgPath, FileMode.Create, FileAccess.Write)
       bw = New BinaryWriter(fs)
       bw.Write(photo)
       fs.Close()
       bw.Close()
 MessageBox.Show("image saved successfully")


my problem is how to link with these 2 block of code. means
pb_image.ImageLocation is take original image location, so it save the original image dimensions. not to save 200 X 150 dimensions of image.

Please give me a solution

Thanks.

Answers (2)