How to rotate image upon upload?

S

Showjumper

Hi,
I have developed an upload server controls to be reused over a number of
projects. One of the tasks it needs to handle is to rotate an image. I want
to accoplish this by checking the checkbox that is next to the file field.
Once i browse for the file, i check the box to rotate and then upload.
However i am unable to get it to rotate when the box is checked. It only
rotates when i set a boolean (RotateImage) to true. Any ideas on how to go
about rotating by checking the box.?

Also, another question with respect to GDI+ - can i take existing image
(like a gif) and then stamp it on to another image - like a copyright
symbol.
 
T

Teemu Keiski

Hi,

see these GDI articles by Chris Garrett
http://authors.aspalliance.com/chrisg/default.asp?category=9

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

Hi,
I have developed an upload server controls to be reused over a number of
projects. One of the tasks it needs to handle is to rotate an image. I want
to accoplish this by checking the checkbox that is next to the file field.
Once i browse for the file, i check the box to rotate and then upload.
However i am unable to get it to rotate when the box is checked. It only
rotates when i set a boolean (RotateImage) to true. Any ideas on how to go
about rotating by checking the box.?

Also, another question with respect to GDI+ - can i take existing image
(like a gif) and then stamp it on to another image - like a copyright
symbol.
 
S

Showjumper

I had already been through those articles. I know how to rotate the image -
it rotates just fine if a boolean is set in the properties panel. What i
want to do is have it rotate if the checkbox is checked - the checkbox is
next to the file field in the browser. Thats where my problem lies.
 
T

Teemu Keiski

Ok, sorry for that. So you mean you can't read the CheckBox's Checked
property while uploading the image?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


I had already been through those articles. I know how to rotate the image -
it rotates just fine if a boolean is set in the properties panel. What i
want to do is have it rotate if the checkbox is checked - the checkbox is
next to the file field in the browser. Thats where my problem lies.
 
S

Showjumper

Right. This is a server control, btw. Not sure if it makes a difference. I
have the following in upload routine:
If RotateCheck.Checked = True Then
RotateImages()
End If
And in the createchildcontrols i have
AddHandler btnButton.Click, AddressOf SaveImages

The rotate only works if a boolean is set to tru in the property window, not
if the checkbo is checked. Maybe i am missing something obvious.
 
T

Teemu Keiski

Ok,

can you post more complete set of code?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

Right. This is a server control, btw. Not sure if it makes a difference. I
have the following in upload routine:
If RotateCheck.Checked = True Then
RotateImages()
End If
And in the createchildcontrols i have
AddHandler btnButton.Click, AddressOf SaveImages

The rotate only works if a boolean is set to tru in the property window, not
if the checkbo is checked. Maybe i am missing something obvious.
 
S

Showjumper

Here you go. If you need more let me know.

Private Function RotateImage(ByVal SourceImage As String, ByVal DestImage As
String) As Boolean
Dim g As System.Drawing.Image
g = System.Drawing.Image.FromFile(SourceImage)
g.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone)
g.Save(DestImage)
g.Dispose()
g = Nothing
End Function

'My call to function
If RotateCheck.Checked = True Then
RotateImage(context.Server.MapPath(_UploadDirectory & "\") + _fileName,
context.Server.MapPath(_UploadDirectory & "\") + _fileName)
End If

Protected Overrides Sub CreateChildControls()
' Add File Fields
Me.Controls.Add(New LiteralControl("<div align=""" & _align & """ "))
For I = 1 To _NumberFileFields
FileField = New HtmlControls.HtmlInputFile
RotateCheck = New CheckBox
Me.Controls.Add(New LiteralControl("<p>"))
Me.Controls.Add(FileField)
FileField.Size = _FileFieldSize
FileField.Attributes.Add("class", _FileFieldCssClass)
Me.Controls.Add(RotateCheck)
Me.Controls.Add(New LiteralControl("</p>"))
Next
' Add Submit Button
btnButton.Text = _ButtonText
btnButton.CssClass = _SubmitButtonCssClass
AddHandler btnButton.Click, AddressOf SaveImages
Me.Controls.Add(btnButton)
'Add message
Me.Controls.Add(New LiteralControl("<p class=""" & _UploadMsgCssClass &
""">"))
Me.Controls.Add(label1)
Me.Controls.Add(New LiteralControl("</div>"))
End Sub
 
S

Showjumper

I know what the problem is. It works fine if it is only one checkbox on the
page. However i am wanting a checkbox next to each file field to allow each
image to be rotated independlty of the others or not at all. One checkbox on
the page the image is rotated. But it also rotates images that dont need to
be when multiple files are upped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top