Background: I am working on an ASP.net project that basically fills out a form from user input. The generated form (for reasons which I have no control over) must be a JPEG or TIFF. So the user fills out the web form, which takes all of
the input values and meges them into a blank image (jpeg) of the form. Using System.Drawing, it merges all of the text onto the form at designated Points. The points are defined as variables which are modified at runtime to compensate for the resolution
of the image (in case it get modified/re-generated at a different dpi). All of this is working fine.
Problem: Currently I have a Sub that determines the dpi of the master image, then adjusts the Points accordingly. However, there are ~50 variables that have to be adjusted. So currently I have the Sub go thru each point variable and manually
adjust the X & Y values. I have been working on a Sub that will iterate thru all of the Point variables and do adjustment. Here's a functional sample of what I have working:
Imports System.Drawing
Partial Class test
Inherits System.Web.UI.Page
Private var0 As String = "text0"
Private var1 As Point = New Point(10, 10)
Private var2 As Point = New Point(10, 20)
Private var3 As Point = New Point(20, 10)
Private var4 As Point = New Point(20, 20)
Private var5 As Point = New Point(50, 50)
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim x As test = New test
For Each y In x.GetType.GetFields(Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
If y.FieldType = GetType(Point) Then
Label1.Text &= "Old: " & y.GetValue(x).ToString() & " - "
Dim pt As Point = y.GetValue(x)
pt.X += 1
pt.Y -= 1
y.SetValue(x, pt)
Label1.Text &= "New: " & y.GetValue(x).ToString() & "<br/>"
End If
Next
End Sub
End Class
This works...sort of. It allows me to grab each variable and modify it, but only in the
instance. The original variable in the class is unchanged. Which means that when the program gets to the point where it's drawing text to the image, the points are unmodified.
So, my basic question is: Is it possible to modify the original variable using this sort of process? If not, is the best way to use these modified values to declare the new class instance at a global level, then have the Sub that draws the text use the
instance versions of the variables?
I realize that I could define all of the points in an array which would be easy to loop thru and update, but I've named each point variable something meaningful to correspond to the related text to be drawn.
The original variable in the class is unchanged. Which means that when the program gets to the point where it's drawing text to the image, the points are unmodified.
So, my basic question is: Is it possible to modify the original variable using this sort of process?
Is this a matter of loosing state (since the web is stateless) and you just need to persist the original object in Session so that any changes you make to it will persist as well? If this is a matter of storing an object in Session and then retrieving it
later, look to the following code:
'Add values to a Session Variable
Session.Add("Point_X", x)
Session.Add("Point_Y", y)
And the code for pulling them back out later:
Dim x As Test = DirectCast(Session(Point_X), Test)
eacrittenden
0 Points
1 Post
Iteration of class variables
Sep 23, 2011 10:32 PM|LINK
Background: I am working on an ASP.net project that basically fills out a form from user input. The generated form (for reasons which I have no control over) must be a JPEG or TIFF. So the user fills out the web form, which takes all of the input values and meges them into a blank image (jpeg) of the form. Using System.Drawing, it merges all of the text onto the form at designated Points. The points are defined as variables which are modified at runtime to compensate for the resolution of the image (in case it get modified/re-generated at a different dpi). All of this is working fine.
Problem: Currently I have a Sub that determines the dpi of the master image, then adjusts the Points accordingly. However, there are ~50 variables that have to be adjusted. So currently I have the Sub go thru each point variable and manually adjust the X & Y values. I have been working on a Sub that will iterate thru all of the Point variables and do adjustment. Here's a functional sample of what I have working:
Imports System.Drawing Partial Class test Inherits System.Web.UI.Page Private var0 As String = "text0" Private var1 As Point = New Point(10, 10) Private var2 As Point = New Point(10, 20) Private var3 As Point = New Point(20, 10) Private var4 As Point = New Point(20, 20) Private var5 As Point = New Point(50, 50) Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load Dim x As test = New test For Each y In x.GetType.GetFields(Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic) If y.FieldType = GetType(Point) Then Label1.Text &= "Old: " & y.GetValue(x).ToString() & " - " Dim pt As Point = y.GetValue(x) pt.X += 1 pt.Y -= 1 y.SetValue(x, pt) Label1.Text &= "New: " & y.GetValue(x).ToString() & "<br/>" End If Next End Sub End ClassThis works...sort of. It allows me to grab each variable and modify it, but only in the instance. The original variable in the class is unchanged. Which means that when the program gets to the point where it's drawing text to the image, the points are unmodified.
So, my basic question is: Is it possible to modify the original variable using this sort of process? If not, is the best way to use these modified values to declare the new class instance at a global level, then have the Sub that draws the text use the instance versions of the variables?
I realize that I could define all of the points in an array which would be easy to loop thru and update, but I've named each point variable something meaningful to correspond to the related text to be drawn.
Any input would be greatly appreciated.
E
atconway
All-Star
16846 Points
2756 Posts
Re: Iteration of class variables
Sep 30, 2011 01:18 PM|LINK
In reference to these comments:
Is this a matter of loosing state (since the web is stateless) and you just need to persist the original object in Session so that any changes you make to it will persist as well? If this is a matter of storing an object in Session and then retrieving it later, look to the following code:
'Add values to a Session Variable Session.Add("Point_X", x) Session.Add("Point_Y", y)And the code for pulling them back out later: