Answered by:
Dynamic image creation problems

Question
-
User547880637 posted
Hi there
I have been building a db driven application where users select a base image that has 1-4 pre-determined areas on it for text or images. Users can lay text and images over the top of the base image and when completed, save the image as a JPG to their local system. As there can be 1-4 per base image I created a repeater and on the button1_click method I updated my code to loop through the repeaeter and create the text overlays (You will see this in the code I posted below).
NOW, the the basic text creation and image saving is completed and the code I am using has been tested and works 100%, but since moving the code into a FOR loop for the repeater it seems to have broken and nothing is being done at all. I think that the repeater in the .aspx page is maybe empty after the button1_click and so the for loop is breaking.
I would be grateful for anyones help. Simon
doGlobal.chkClientLogin(Session(
"socGUID"), Application("logSocialite")) Dim sdc As New SocialiteDataContext()TemplateAreasRepeater.DataSource = sdc.SelectTemplateAreas(Request.QueryString("TemplateID"))TemplateAreasRepeater.DataBind()
Dim ReturnTemplate As Template = sdc.SelectTemplate(Request.QueryString("TemplateID")).SingleOrDefault Dim ReturnCategory As Category = sdc.SelectCategory(Request.QueryString("CategoryID")).SingleOrDefaultLabel1.Text = ReturnCategory.CategoryName
Label1.Visible =
TrueLabel2.text = ReturnTemplate.TemplateName
Label2.Visible =
True If Not IsPostBack Then FileSystem.FileCopy(MapPath("~/imgs/templates/preview/" & ReturnTemplate.ImageFile), MapPath("~/imgs/templates/temp/" & Session("socGUID") & ".jpg")) End IfImage1.ImageUrl =
"~/imgs/templates/temp/" & Session("socGUID") & ".jpg"HiddenField1.Value = ReturnTemplate.ImageFile
End Sub '-- CREATE FINAL IMAGE -- Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim bitMapImage As Bitmap = New Bitmap(MapPath("~/imgs/templates/" & HiddenField1.Value)) Dim graphicImage As Graphics = Graphics.FromImage(bitMapImage) Dim Item As RepeaterItem Dim strValues As String = "" For Each Item In TemplateAreasRepeater.Items Dim AreaXPos As Integer = CType(Item.FindControl("HiddenFieldXPos"), HiddenField).ValuestrValues =
"X: " & AreaXPos & "<BR>" 'Dim AreaXPos As Integer = Int32.Parse(TryCast(Item.FindControl("HiddenFieldXPos"), HiddenField).Value) Dim AreaYPos As Integer = CType(Item.FindControl("HiddenFieldYPos"), HiddenField).ValuestrValues = strValues &
"Y: " & AreaYPos & "<BR>" Dim AreaWidth As Integer = CType(Item.FindControl("HiddenFieldWidth"), HiddenField).ValuestrValues = strValues &
"Width: " & AreaWidth & "<BR>" Dim AreaHeight As Integer = CType(Item.FindControl("HiddenFieldHeight"), HiddenField).ValuestrValues = strValues &
"Height: " & AreaHeight & "<BR>" Dim sText As String = CType(Item.FindControl("AdText"), TextBox).TextstrValues = strValues &
"Text: " & sText & "<BR>" Dim sFont As String = CType(Item.FindControl("ddlFont"), DropDownList).SelectedValuestrValues = strValues &
"Font: " & sFont & "<BR>" Dim sFontSize As Integer = CType(Item.FindControl("ddlSize"), DropDownList).SelectedValuestrValues = strValues &
"Size: " & sFontSize & "<BR>" Dim sColour As String = CType(Item.FindControl("ColorPicker1"), CustomControls.ColorPicker).ColorstrValues = strValues &
"Color: " & sColour & "<BR>" Dim solidBrush As New SolidBrush(System.Drawing.ColorTranslator.FromHtml(sColour)) 'Convert hex to brush!!! Dim ddlHAlignment As String = CType(Item.FindControl("ddlHAlignment"), DropDownList).SelectedValuestrValues = strValues &
"Horizontal: " & ddlHAlignment & "<BR>" Dim ddlVAlignment As String = CType(Item.FindControl("ddlHAlignment"), DropDownList).SelectedValuestrValues = strValues &
"Vertical: " & ddlVAlignment & "<BR/><br/>" Dim stringFormat As New StringFormat()stringFormat.Trimming = StringTrimming.EllipsisWord
If ddlHAlignment = "Near" ThenstringFormat.Alignment = StringAlignment.Near
ElseIf ddlHAlignment = "Center" ThenstringFormat.Alignment = StringAlignment.Center
ElseIf ddlHAlignment = "Far" ThenstringFormat.Alignment = StringAlignment.Far
End If If ddlVAlignment = "Near" ThenstringFormat.LineAlignment = StringAlignment.Near
ElseIf ddlVAlignment = "Center" ThenstringFormat.LineAlignment = StringAlignment.Center
ElseIf ddlVAlignment = "Far" ThenstringFormat.LineAlignment = StringAlignment.Far
End If Dim font As New Font(sFont, sFontSize)Dim rect As New Rectangle(AreaXPos, AreaYPos, AreaWidth, AreaHeight)graphicImage.TextRenderingHint = TextRenderingHint.AntiAliasGridFit
graphicImage.DrawString(sText, font, solidBrush, rect, stringFormat)
graphicImage.Dispose()
Next bitMapImage.Save(MapPath("~/imgs/templates/completed/" & Session("socGUID") & ".jpg"), ImageFormat.Jpeg)bitMapImage.Dispose()
DownloadLink.Text =
"<a href=""/imgs/templates/completed/" & Session("socGUID") & ".jpg"">Right click and select 'Save target as...' to save the image to your computer.</a>" DownloadLink.Visible = TrueTuesday, November 18, 2008 5:23 AM
Answers
-
User547880637 posted
Ok guys I have remedied the issue...to get the values of the textboxes and dropdowns I have to actually create new instances of those objects and then set a variable to the values/selectedvalues, like so:
Dim ddlFontSize As DropDownList = Item.findcontrol("ddlSize")sFontSize = ddlFontSize.SelectedValue
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, November 18, 2008 8:36 AM