473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How can save the picture with low quality

Before this topic I save the picture with this code
Expand|Select|Wrap|Line Numbers
  1.   Dim savePath As String = Server.MapPath("picture\")
  2.        If (f1.HasFile) Then
  3.          pnlUpload.Visible = False
  4.          lblMessage.Text = "<embed align=bottom src=""inc/u.swf"" ></embed>"
  5.     Dim fileName As String = f1.FileName
  6. Try
  7.   savePath &= CInt(intPic) & "." & pasvand
  8.  Catch ex As Exception
  9. savePath &= "0." & pasvand
  10.  End Try
  11. f1.SaveAs(savePath)
  12.  Response.Redirect("showaghi.aspx")
  13.  Else
  14. MsgBox("Select Picture please", MsgBoxStyle.OkOnly, "Error")
  15. End If
  16.  
but I can't edit or resize the picture !
how can i resize the picture and also save the picture with low quality
Jan 5 '07 #1
5 1951
radcaesar
759 Expert 512MB
U mean, for reducing the size of the picture ?

:)
Jan 5 '07 #2
thEse code are for save as the picture in an other size

Expand|Select|Wrap|Line Numbers
  1. Private Function SaveImageToDB(ByVal Po As Integer) As Int32
  2.             Dim imgName As String
  3.             Dim imgContentType As String
  4.             Dim imgLen As Int32
  5.             Dim imgbin() As Byte
  6.             Dim imgName2 As String
  7.             Dim imgContentType2 As String
  8.             Dim imgbin2() As Byte
  9.             'check if file is empty
  10.             Dim picup
  11.  
  12.             picup =  Path.GetFileName(BrowsImageProject.Value)
  13.             BrowsImageProject.PostedFile.SaveAs(Server.MapPath("Files/" & picup))
  14.  
  15.             If Not BrowsImageProject.PostedFile Is Nothing Then
  16.                 If BrowsImageProject.PostedFile.FileName.Trim.Length > 0 And BrowsImageProject.PostedFile.ContentLength > 0 Then
  17.                     Dim imgStream As Stream = BrowsImageProject.PostedFile.InputStream()
  18.                     imgLen = BrowsImageProject.PostedFile.ContentLength
  19.                     imgContentType = BrowsImageProject.PostedFile.ContentType
  20.                     imgName = BrowsImageProject.PostedFile.FileName.Substring(BrowsImageProject.PostedFile.FileName.LastIndexOf("\") + 1)
  21.                     Dim imgBinaryData(imgLen) As Byte
  22.                     Dim n As Int32 = imgStream.Read(imgBinaryData, 0, imgLen)
  23.                     imgbin = imgBinaryData
  24.  
  25.                     'Create Thumbnail
  26.                     imgName2 = "Thumb_" & imgName
  27.                     imgContentType2 = imgContentType
  28.                     imgbin2 = createThumnail(imgStream, 100, 70)
  29.  
  30.                     Dim fs As FileStream
  31.                     fs = File.Create(Server.MapPath("Files/Thub" & picup))
  32.                     fs.Write(imgbin2, 0, imgbin2.Length)
  33.                     fs.Close()
  34.                     Dim thubpicup
  35.                     thubpicup = "thub" & picup
  36.                     With New ProjectData
  37.                         Dim dv As New DataView
  38.                         dv = .GetMaxid.Tables(0).DefaultView
  39.                         Dim count
  40.                         count = dv.Item(0).Item(0)
  41.  
  42. 'Sp for insert the name of file into Data Base
  43.                         .InsertTblImgProject(picup, thubpicup)
  44.                     End With
  45.  
  46.                     End If
  47.                 End If
  48.  
  49.  
  50.         End Function
  51.  
  52.  
  53.         'This function creates the Thumbnail image and returns the image created in Byte() format
  54.         Private Function createThumnail(ByVal ImageStream As Stream, ByVal tWidth As Double, ByVal tHeight As Double) As Byte()
  55.             Dim g As System.Drawing.Image = System.Drawing.Image.FromStream(ImageStream)
  56.             Dim thumbSize As New Size
  57.             thumbSize = NewthumbSize(g.Width, g.Height, tWidth, tHeight)
  58.             Dim imgOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
  59.             Dim imgStream As New MemoryStream
  60.             Dim thisFormat = g.RawFormat
  61.             imgOutput.Save(imgStream, thisFormat)
  62.             Dim imgbin(imgStream.Length) As Byte
  63.             imgStream.Position = 0
  64.             Dim n As Int32 = imgStream.Read(imgbin, 0, imgbin.Length)
  65.             g.Dispose()
  66.             imgOutput.Dispose()
  67.             Return imgbin
  68.         End Function
  69.  
  70.         Function NewthumbSize(ByVal currentwidth As Double, ByVal currentheight As Double, ByVal newWidth As Double, ByVal newHeight As Double)
  71.             ' Calculate the Size of the New image 
  72.             Dim tempMultiplier As Double
  73.  
  74.             If currentheight > currentwidth Then ' portrait 
  75.                 tempMultiplier = newHeight / currentheight
  76.             Else
  77.                 tempMultiplier = newWidth / currentwidth
  78.             End If
  79.  
  80.             Dim NewSize As New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier))
  81.             Return NewSize
  82.         End Function
  83.  
  84.  
  85.  
  86.  
Jan 5 '07 #3
tanks a lot
it's so nice
Jan 6 '07 #4
tanks a lot
it's so nice
but i have some problem
for example
the compiler said
BrowsImageProject , File , ... : is not declared
ProjectData, ... : is not defined
how can i correct this Error
and also i just have path of picture
for example "c:\file\pic\1.gif" or "c:\file\pic\3.jpg"
Jan 6 '07 #5
oh i am sorry
i am understand all things
i change your function :
Expand|Select|Wrap|Line Numbers
  1. ' in the main
  2.  f1.SaveAs(savePath)
  3.  Dim img As Drawing.Bitmap
  4.  img = createThumnail(savePath, 50, 50)
Expand|Select|Wrap|Line Numbers
  1. Private Function createThumnail(ByVal ImagePath As String, ByVal tWidth As Double, ByVal tHeight As Double) As Drawing.Bitmap
  2.         Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(ImagePath)
  3.         Dim thumbSize As New Drawing.Size
  4.         thumbSize = NewthumbSize(g.Width, g.Height, tWidth, tHeight)
  5.         Dim imgOutput As New Drawing.Bitmap(g, thumbSize.Width, thumbSize.Height)
  6.         Return imgOutput
  7.     End Function
thanks again
Jan 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sandra Lambrechts | last post by:
We are using Crystal Report .Net to create our reports. We have inserted a picture on the Crystal Report, but when we export the report to a pdf-file to print the report, the quallity of our...
5
by: Shahar Golan | last post by:
In my site I show low quality pictures. When someone right clicks an image and selects 'Save Picture As...', I wish to let him save the high quality picture. I 10Q 4NE IDa.
1
by: Sean | last post by:
i am writing a class that visual demonstrates the result of changing the quality of a jpeg. the intention is to do this by saving the file and a selected quality, then reloading it to get an idea of...
6
by: charsh | last post by:
Hi, I using the code below to draw a text in a pictureBox1. //Start--------------------------------------------------------------- private void button1_Click(object sender, System.EventArgs e)...
2
by: Michael Lehar | last post by:
Hallo I have a pictureBox with a picture loaded from file, then I draw some lines on the picture, and then I want to save the new picture. Befor I can draw lines I have to create a Graphics...
1
by: Sam Jost | last post by:
Bitmap.Save() does crash very often on Saving jpg's. It seems to dislike pictures on a random basis, but when it dislikes a picture there is no way around it. Take for example the picture...
1
by: Fredrik Melin | last post by:
Hi, If I do a copy of a jpg picture to the clipboard. Then I do PictureBox1.Image = CType(IData.GetData(DataFormats.Bitmap), Bitmap) Then I save the Picture from the picturebox as jpeg. ...
4
by: Peter Proost | last post by:
Hi group I've got a bitmap with a white background in a picturebox and I do some drawing on this bitmap but when I save the bitmap as .jpg there's some quality loss, nothing you can see if you just...
2
by: zheng | last post by:
ÇçÌì I have a word document and it has a picture object, I want save the picture object as other single picture file by C# program. I have a idea, by clipboard, copy the picture to clipboard, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.