Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
jessica99327
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
Accepted Solution

Unable to set picture from gallery as background

Hi all,

I was able to open the gallery to choose picture but wasn't able to set the selected image as background.

Everytime i choose a picture, the default picture will set to white.

Below is my code, can anyone figure out where goes wrong?

Thanks in advance.

 

Container {
            

            background: recipeBackground.imagePaint

            attachedObjects: [
                ImagePaintDefinition {
                    id: recipeBackground
                    imageSource: "asset:///images/bg.jpg"
                    repeatPattern: RepeatPattern.XY
                }
            ]
            Container {
                layout: DockLayout {

                }
                opacity: 1.0
                visible: true
                horizontalAlignment: HorizontalAlignment.Center
                background: Color.Transparent
                leftPadding: 0.0
                ImageView {
                    imageSource: "asset:///images/header.jpg"
                    preferredHeight: 150.0
                    opacity: 0.9

                }
                Container {
                    verticalAlignment: VerticalAlignment.Center
                    horizontalAlignment: HorizontalAlignment.Fill

                    layout: StackLayout {
                        orientation: LayoutOrientation.LeftToRight

                    }
                    leftPadding: 200.0
                    Label {
                        text: "Testing"
                        preferredHeight: 100.0
                        verticalAlignment: VerticalAlignment.Center
                        horizontalAlignment: HorizontalAlignment.Center
                        textStyle {
                            base: SystemDefaults.TextStyles.MediumText
                            color: Color.White
                        }
                    }
                    ImageButton {
                        verticalAlignment: VerticalAlignment.Top
                        horizontalAlignment: HorizontalAlignment.Left
                        leftMargin: 150.0
                        defaultImageSource: "asset:///images/Settings.png"
                        
                        onClicked:{
                            picker.open()

                        }

                    }

                    attachedObjects: [
                        FilePicker {
                            id: picker
                            property string selectedFile
                            title: qsTr("File Picker")
                            mode: FilePickerMode.Picker
                            type: FileType.Picture
                            viewMode: FilePickerViewMode.GridView
                            onFileSelected: {
                                selectedFile = selectedFiles[0]
                                recipeBackground.imageSource = selectedFiles[0]
                            }
                        }
                    ]

                }
            }

 

Developer
laurentC
Posts: 268
Registered: ‎02-05-2010
My Device: Blackberry Z10

Re: Unable to set picture from gallery as background

Same for me :No:

 

I can see in this example in the documentation 

FilePicker {
                id:filePicker
                type : FileType.Picture
                title : "Select Picture"
                directories : ["/accounts/1000/shared/misc"]
                onFileSelected : {
                    console.log("FileSelected signal received : " + selectedFiles);
 
                    //make sure to prepend "file://" when using as a source for an ImageView or MediaPlayer
                    myImageView.imageSource = "file://" + selectedFiles[0];
 
                }
            }
 
But even if I add "file://", I get the white screen...
Twitter : @LaurentKP
My apps
Developer
laurentC
Posts: 268
Registered: ‎02-05-2010
My Device: Blackberry Z10

Re: Unable to set picture from gallery as background

Well we just have to add the access_shared permission in bar-descriptor.xml and it works !!!

Twitter : @LaurentKP
My apps
Retired
garydev
Posts: 83
Registered: ‎10-10-2012
My Device: Z30

Re: Unable to set picture from gallery as background

Jessica - please confirm that the solution LaurentC posts below works for you. Thank you.