Rank: Newbie
Groups: Member
Joined: 8/9/2012(UTC) Posts: 7
Thanks: 2 times
|
Hello, My requirement is to save the coordinates, height, width, z-index and angle of all the images which we added in the canvas. And then using that saved information regenerate the image back on the canvas for editing purpose (like change the height, width etc of any image and save them). I am successfully getting and saving the all required information like (coordinates, height, width, z-index and angle) in my database. But I am facing problem in regenerating image back on the canvas for editing purpose. I am using following code for this. Code:// using this code to get the required information of all images and saving them in the database on save button click
protected void renderBtn_Click(object sender, EventArgs e)
{
var imageList = photoLabel.GetVObjects();
int counter = 0;
foreach (var image in imageList)
{
counter++;
int width = Convert.ToInt32(image.Bounds.Width.ToString().Split('.')[0].ToString());
int height = Convert.ToInt32(image.Bounds.Height.ToString().Split('.')[0].ToString());
int y_coordinate = Convert.ToInt32(image.Bounds.Top.ToString().Split('.')[0].ToString());
int x_coordinate = Convert.ToInt32(image.Bounds.Left.ToString().Split('.')[0].ToString());
double angle = image.Transform.Angle;
int zindex = counter;
}
}
Code:// calling this function on page load
protected void fillCavnaswithSavedImage()
{
using (SqlConnection con = new SqlConnection(DB.GetDBConn()))
{
//getting the saved record of all the four images from the database
string queryprod = "select * from ProductAttributeDesign where productid=" + ProductID + " order by zindex";
SqlDataAdapter sqldaprod = new SqlDataAdapter(queryprod, con);
DataSet dsprod = new DataSet();
sqldaprod.Fill(dsprod, "prod");
foreach (DataRow dr in dsprod.Tables[0].Rows)
{
float angle = 0;
float.TryParse(Convert.ToString(dr["attrAngle"]), out angle);
string id = imageName.Trim().GetHashCode().ToString();
addVObject(id, Convert.ToInt32(dr["productheight"]), Convert.ToInt32(dr["productwidth"]), Convert.ToInt32(dr["producttop"]), Convert.ToInt32(dr["productleft"]), angle);
}
}
}
Code:protected void addVObject(string id, int height, int width, int top, int left, float angle)
{
ImageVObjectData objVObject = CreateImageVObject(id);
ImageVObject vo = new ImageVObject();
objVObject.ApplyState(vo);
vo.BeginUpdate();
//proportional resize only
vo.SupportedActions &= ~VObjectAction.Rotate;
// vo.Angle = angle;
Aurigma.GraphicsMill.AjaxControls.VectorObjects.Math.RotatedRectangleF r = vo.Rectangle;
r.Angle = angle;
r.Height = height;
r.Width = width;
r.Location = new Aurigma.GraphicsMill.AjaxControls.VectorObjects.Math.PointF(left, top);
vo.Rectangle = r;
vo.EndUpdate();
photoLabel.AddVObject(vo, "Main");
}
Code:[System.Web.Services.WebMethod]
public static ImageVObjectData CreateImageVObject(string imageId)
{
string productID = HttpContext.Current.Session["DesignProductid"].ToString();
string fileName = Array.Find(Directory.GetFiles(_ProductFolder, productID + "*.jpg"),
delegate(string s) { return s.GetHashCode().ToString() == imageId; });
if (fileName == null)
fileName = Array.Find(Directory.GetFiles(_ProductFolder, productID + "*.png"),
delegate(string s) { return s.GetHashCode().ToString() == imageId; });
if (fileName == null)
fileName = Array.Find(Directory.GetFiles(_AttributeFolder, "*.png"),
delegate(string s) { return s.GetHashCode().ToString() == imageId; });
ImageVObject vo = new ImageVObject(new FileInfo(fileName));
//proportional resize to "defaultImageSize"x"defaultImageSize"
Aurigma.GraphicsMill.AjaxControls.VectorObjects.Math.RotatedRectangleF r = vo.Rectangle;
float dx = defaultImageSize / r.Width;
float dy = defaultImageSize / r.Height;
float d = dx < dy ? dx : dy;
r.Width = d * r.Width;
r.Height = d * r.Height;
r.Location = new Aurigma.GraphicsMill.AjaxControls.VectorObjects.Math.PointF(2, 2);
vo.Rectangle = r;
vo.FillColor = System.Drawing.Color.Transparent;
//proportional resize only
vo.SupportedActions &= ~VObjectAction.ArbitraryResize;
// Create thumbnail to show in the layers list
vo.Tag = GenerateThumbnail(fileName);
string[] name = fileName.Split('\\');
string imageName = name[name.Length - 1].ToString();
imagdata im = new imagdata();
im.name_new = vo.Tag.ToString().Split('=')[1];
im.name_Old = imageName;
if (HttpContext.Current.Session["imagedata"] == null)
{
List<imagdata> imgdata = new List<imagdata>();
imgdata.Add(im);
HttpContext.Current.Session["imagedata"] = imgdata;
}
else
{
List<imagdata> imgdata = (List<imagdata>)HttpContext.Current.Session["imagedata"];
imagdata ac = (from c in imgdata where c.name_Old.ToLower() == imageName.ToLower() select c).FirstOrDefault();
if (ac != null)
{
ac.name_new = vo.Tag.ToString().Split('=')[1];
}
else
{
imgdata.Add(im);
}
HttpContext.Current.Session["imagedata"] = imgdata;
}
return new ImageVObjectData(vo);
}
Please help me in this. thanks Manish gupta Edited by user Tuesday, January 8, 2013 11:36:26 PM(UTC)
| Reason: One code was missed by me. Manish Gupta attached the following image(s):
|