70000053 Support of multi page tiff images

Article 70000053
Type Wish
Product Engine
Version 7001
Date Added 9/1/2014 12:00:00 AM
Fixed (10/23/2014 12:00:00 AM)
Submitted by JongKyun Kim

Summary

Is it possible to support multi page tif images ?

Solution

In version 7002 there are two new properties added to the vdImageDef object. These are the FrameCount property and the ActiveFrame property.

ActiveFrame integer: Get/Set the number of page the vdImageDef will be used when draw.

FrameCount integer: Get (readonly) the number of pages the image has.

With the ActiveFrame property the developer/user can choose the page of the image that is going to be rendered in VDF and as this is available only to vdImageDef object you need multiple vdImageDef objects in your document in order to uinsert these as images in the document to display different pages.

Note that only some special TIF images have multiple pages and that editing inside VDF is disabled. Also note that this feature is available only for VDCL/VDML files as other CAD formats are not supporting this feature.

 

See the code and remarks below:

Managed C#:

        private void btnAddMultiPageTif_Click(object sender, EventArgs e)
        {
            // This code will add all pages of a multipage tif image to the document

            string filename = "MultiPage.tif"; // this is a multiple page tif file
            vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument;
            doc.New();
            vdImageDef imgdef = new vdImageDef(doc, "MultiPage");
            imgdef.FileName = filename;
            imgdef.Update();
            vdImage img = null;
            if (imgdef.FrameCount > 1) // it is a multipage tif file
            {
                for (int i = 0; i < imgdef.FrameCount; i++)
                {
                    vdImageDef multipagedef = imgdef.Clone(doc) as vdImageDef; // create a new vdImageDef for each page
                    multipagedef.Name = imgdef.Name + "__" + i.ToString(); // with a unique name
                    multipagedef.ActiveFrame = i;// set the page number for each image def.
                    doc.Images.AddItem(multipagedef);//add it to the image definitions collection
                    img = new vdImage(doc, multipagedef, new gPoint(i * 1.1, 0, 0), 1.0d, 0.0d);
                    doc.Model.Entities.AddItem(img);// add an image for each page
                }
                imgdef.Deleted = true;
            }
            else // this is not a multipage tif file
            {
                doc.Images.AddItem(imgdef);
                img = new vdImage(doc, imgdef, new gPoint(0, 0, 0), 1.0d, 0.0d);
                doc.Model.Entities.AddItem(img);
            }
            doc.CommandAction.Zoom("E", 0, 0);




VDF Wrapper (Visual Basec 6):

            Private Sub Command2_Click()
            Dim img As Vdrawi5.vdImage
            Dim imgdef As Vdrawi5.vdImageDef
            Dim img7 As VectorDraw_Professional.vdImage
            Dim imgdef7 As VectorDraw_Professional.vdImageDef
            Dim multimgdef7 As VectorDraw_Professional.vdImageDef
            Dim I As Integer
            Dim filename As String

                VDraw1.ActiveDocument.New
                filename = "C:\MultiImageTIFF\MultiPage.tif"
                Set imgdef = VDraw1.ActiveDocument.images.Add(filename)
                
                If (imgdef Is Nothing) Then Exit Sub
                Set imgdef7 = imgdef.WrapperObject
                If imgdef7.FrameCount > 1 Then
                    imgdef7.Name = "MultiPage"
                    For I = 0 To imgdef7.FrameCount - 1
                        Set imgdef = VDraw1.ActiveDocument.images.Add(filename)
                        Set multimgdef7 = imgdef.WrapperObject
                        multimgdef7.Name = "MultiPage__" + CStr(I)
                        multimgdef7.ActiveFrame = I
                        Set img = VDraw1.ActiveDocument.CreateInstance(Vdrawi5.OBJ_IMAGE)
                        Set img7 = img.WrapperObject
                        Set img7.ImageDefinition = multimgdef7
                        img.InsertionPoint = Array(1.1 * I, 0, 0)
                        VDraw1.ActiveDocument.entities.AddItem img
                    Next I
                    VDraw1.ActiveDocument.images.Purge
                Else
                    imgdef7.Name = "NoMultipage"
                    Set imgdef7 = imgdef.WrapperObject
                    Set img = VDraw1.ActiveDocument.CreateInstance(Vdrawi5.OBJ_IMAGE)
                    Set img7 = img.WrapperObject
                    Set img7.ImageDefinition = imgdef7
                    img.InsertionPoint = Array(0, 0, 0)
                    VDraw1.ActiveDocument.entities.AddItem img
                End If
            
                VDraw1.CommandAction.Zoom "E", 0, 0
            
            End Sub

Send comments on this topic.