Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Loading images using a macro

Hi Everyone,

I'm fairly new to qlikview and with one project under my belt I'm looking at a new one which is a lot more challenging.

Basically the document will need to retrieve images from a file store on the network based on the criteria set in the list boxes. I can't load the images into the document as there could potentially be thousands of images. I've started playing around to prove this can be done and decided that a macro is the only approach. So far I can click on a value in a listbox and then push a button, this triggers a macro which goes and retrieives the image and displays it in a container for me which is great. I can also do this for multiple images as well now, but I have 2 problems...

1. I don't know the syntax to set the Image Strech to Keep Aspect (cant seem to find it anywhere for Foreground image

2. The 2nd, 3rd pics that I load are very blurry and lose quality, if I load the images without a container the quality is perfect

Below is the Macro I have so far:

sub OpenPics_Cont

IMG_PATH = "C:\Users\Public\Pictures\Sample Pictures\"

Set ContainerObj = ActiveDocument.Sheets("Main").CreateContainer

set ContProp=ContainerObj.GetProperties

set LB = ActiveDocument.GetSHeetObject("LB01")

pg=LB.GetPossibleValues

    for i=lbound(pg) to ubound(pg)

        set mytext=ActiveDocument.ActiveSheet.CreateTextObject

        prop=mytext.GetProperties

        prop.Layout.ImageRepresentation.Presentation = 1

        prop.Layout.Text.v = "='" & IMG_PATH & pg(i) & ".jpg'"

        mytext.SetProperties prop

        ContProp.ContainedObjects.Add

        ContProp.SingleObjectMode=1

        ContProp.SingleObjectStyle=1

        ContProp.ShowObjectTypeIcons=true

        ContProp.ContainedObjects.Item(i).Id =prop.Layout.Frame.ObjectId

        ContProp.ContainedObjects.Item(i).Text.v = pg(i)

        ContainerObj.SetProperties ContProp

        mytext.close

    next

end sub

Does anyone have any idea's how I might be able to adjust the aspect of the image and why the image quality is so bad.

1 Solution

Accepted Solutions
isaiah82
Creator III
Creator III

When you say text box I assume you mean a popup window (e.g. you've got a button with action = "Show Information"?)  Or are you actually showing the image inside of a textbox?  Moot point though really; I don't think you'll be able to cycle through the possible values without a macro, although that's not to completely say something couldn't be done.

Instead you can create a table box (or straight/pivot table) and adding your field with Info as a dimension.  Then pick "Info as Image" in Advanced Field Settings (this is on the Presentation tab in table box properties.)  Remember to wrap text a few lines.  -Isaiah

View solution in original post

10 Replies
Not applicable
Author

Hi,

Let's try this for image stretching

sub Stretch

set bu=ActiveDocument.GetSheetObject("BU01")

set prop=bu.GetProperties

prop.BkImageSettings.ImageStyle.StretchMode=1 'fill

bu.SetProperties prop

end sub

Let me know it works or not

Regards...

isaiah82
Creator III
Creator III

Have you looked into the INFO functionality built in to QV?  This allows you to link external files to a field value.  Check the help file for the topic "Info"   -Isaiah

Not applicable
Author

@ravikumar_ajzaas - no this didnt work, Im beginning to wonder whether the property is available through the APi to stretch the image for a foreground picture.

I guess the alternative is to display a link to the image which will open in a browser page or something but I'd prefer to open the Image in qlikview.

Any suggestions?

Not applicable
Author

@Isiah Weed - I didnt want to use this functionality, wouldnt this make a copy of the image and store it in the qlikview document, maybe I misunderstood how this works? The document is likely to be reloaded twice/thrice a day and will the amount of data will get large quite rapidly.

isaiah82
Creator III
Creator III

With INFO LOAD you only embed the images in the QVW if you use the BUNDLE prefix.  "Regular" INFO LOAD links to the file externally and it is only opened when called.  I have the same issue as you; I would never be able to embed all of the images into my QVW for size constraints.  Try the info load (no bundle) in a small test file and I think you'll be presently surprised.  -Isaiah

Not applicable
Author

Thanks Isaiah, I'll give this a try with the example I already have. I'll let you know how I get on with this.

Not applicable
Author

Just got back to this now... I tried the info load for the pictures and it works. Thanks a lot. Though it appears Im restricted to viewing one image at a time in a textbox. Which is no big deal the user can see the possible images related to the their criteria in the picture listbox and click each one as they wish, but oout of interest is it possible to view multiple images in multiple textboxes without the use of macros?

isaiah82
Creator III
Creator III

When you say text box I assume you mean a popup window (e.g. you've got a button with action = "Show Information"?)  Or are you actually showing the image inside of a textbox?  Moot point though really; I don't think you'll be able to cycle through the possible values without a macro, although that's not to completely say something couldn't be done.

Instead you can create a table box (or straight/pivot table) and adding your field with Info as a dimension.  Then pick "Info as Image" in Advanced Field Settings (this is on the Presentation tab in table box properties.)  Remember to wrap text a few lines.  -Isaiah

Not applicable
Author

Yes i meant pop up boxes, opened by a macro. I'll give the table box method a try first though.