Before this topic I save the picture with this code -
Dim savePath As String = Server.MapPath("picture\")
-
If (f1.HasFile) Then
-
pnlUpload.Visible = False
-
lblMessage.Text = "<embed align=bottom src=""inc/u.swf"" ></embed>"
-
Dim fileName As String = f1.FileName
-
Try
-
savePath &= CInt(intPic) & "." & pasvand
-
Catch ex As Exception
-
savePath &= "0." & pasvand
-
End Try
-
f1.SaveAs(savePath)
-
Response.Redirect("showaghi.aspx")
-
Else
-
MsgBox("Select Picture please", MsgBoxStyle.OkOnly, "Error")
-
End If
-
but I can't edit or resize the picture !
how can i resize the picture and also save the picture with low quality
5 1951
U mean, for reducing the size of the picture ?
:)
thEse code are for save as the picture in an other size -
Private Function SaveImageToDB(ByVal Po As Integer) As Int32
-
Dim imgName As String
-
Dim imgContentType As String
-
Dim imgLen As Int32
-
Dim imgbin() As Byte
-
Dim imgName2 As String
-
Dim imgContentType2 As String
-
Dim imgbin2() As Byte
-
'check if file is empty
-
Dim picup
-
-
picup = Path.GetFileName(BrowsImageProject.Value)
-
BrowsImageProject.PostedFile.SaveAs(Server.MapPath("Files/" & picup))
-
-
If Not BrowsImageProject.PostedFile Is Nothing Then
-
If BrowsImageProject.PostedFile.FileName.Trim.Length > 0 And BrowsImageProject.PostedFile.ContentLength > 0 Then
-
Dim imgStream As Stream = BrowsImageProject.PostedFile.InputStream()
-
imgLen = BrowsImageProject.PostedFile.ContentLength
-
imgContentType = BrowsImageProject.PostedFile.ContentType
-
imgName = BrowsImageProject.PostedFile.FileName.Substring(BrowsImageProject.PostedFile.FileName.LastIndexOf("\") + 1)
-
Dim imgBinaryData(imgLen) As Byte
-
Dim n As Int32 = imgStream.Read(imgBinaryData, 0, imgLen)
-
imgbin = imgBinaryData
-
-
'Create Thumbnail
-
imgName2 = "Thumb_" & imgName
-
imgContentType2 = imgContentType
-
imgbin2 = createThumnail(imgStream, 100, 70)
-
-
Dim fs As FileStream
-
fs = File.Create(Server.MapPath("Files/Thub" & picup))
-
fs.Write(imgbin2, 0, imgbin2.Length)
-
fs.Close()
-
Dim thubpicup
-
thubpicup = "thub" & picup
-
With New ProjectData
-
Dim dv As New DataView
-
dv = .GetMaxid.Tables(0).DefaultView
-
Dim count
-
count = dv.Item(0).Item(0)
-
-
'Sp for insert the name of file into Data Base
-
.InsertTblImgProject(picup, thubpicup)
-
End With
-
-
End If
-
End If
-
-
-
End Function
-
-
-
'This function creates the Thumbnail image and returns the image created in Byte() format
-
Private Function createThumnail(ByVal ImageStream As Stream, ByVal tWidth As Double, ByVal tHeight As Double) As Byte()
-
Dim g As System.Drawing.Image = System.Drawing.Image.FromStream(ImageStream)
-
Dim thumbSize As New Size
-
thumbSize = NewthumbSize(g.Width, g.Height, tWidth, tHeight)
-
Dim imgOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
-
Dim imgStream As New MemoryStream
-
Dim thisFormat = g.RawFormat
-
imgOutput.Save(imgStream, thisFormat)
-
Dim imgbin(imgStream.Length) As Byte
-
imgStream.Position = 0
-
Dim n As Int32 = imgStream.Read(imgbin, 0, imgbin.Length)
-
g.Dispose()
-
imgOutput.Dispose()
-
Return imgbin
-
End Function
-
-
Function NewthumbSize(ByVal currentwidth As Double, ByVal currentheight As Double, ByVal newWidth As Double, ByVal newHeight As Double)
-
' Calculate the Size of the New image
-
Dim tempMultiplier As Double
-
-
If currentheight > currentwidth Then ' portrait
-
tempMultiplier = newHeight / currentheight
-
Else
-
tempMultiplier = newWidth / currentwidth
-
End If
-
-
Dim NewSize As New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier))
-
Return NewSize
-
End Function
-
-
-
-
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"
oh i am sorry
i am understand all things
i change your function : - ' in the main
-
f1.SaveAs(savePath)
-
Dim img As Drawing.Bitmap
-
img = createThumnail(savePath, 50, 50)
- Private Function createThumnail(ByVal ImagePath As String, ByVal tWidth As Double, ByVal tHeight As Double) As Drawing.Bitmap
-
Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(ImagePath)
-
Dim thumbSize As New Drawing.Size
-
thumbSize = NewthumbSize(g.Width, g.Height, tWidth, tHeight)
-
Dim imgOutput As New Drawing.Bitmap(g, thumbSize.Width, thumbSize.Height)
-
Return imgOutput
-
End Function
thanks again
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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.
|
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...
|
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)...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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,...
| |