setImage

The method I used in my thread named callBack.

public void callback(final String data)
    {
         if (data.startsWith("Exception")) return;  

             byte[] dataArray = data.getBytes();
             bitmap = EncodedImage.createEncodedImage(dataArray, 0,
                     dataArray.length);
             /*
             if (bitmap != null)
             {
                 inform = "";
                 invalidate();
             }*/
             setImage(bitmap); 

     }

When I use thread.run () it is ok. But thread.start () cannot display image and throw an exception to the setImage line. Anyone know the reason? I have confirmed that data are responsible for success because I had printed out the length of the data and compare in two cases. They are the same.

When you call Thread.run (), you simply run the run() method using your own thread call.

Whan you call Thread.start (), you start a separate thread.

You can access the user interface of a thread of non-event. So, you, same no thread you must synchronize with the lock of the event, or place your work in the case where the tail for the treatment by the thread of your event.

See the documentation for the API for UiApplication.invokeLater (). That's what suggests to what you are trying to accomplish.

Tags: BlackBerry Developers

Similar Questions

  • SetImage BitmapField error

    Hi all

    I tried to make an animation of the sprite by BitmapField by setImage() function,

    my image successfully recovered all the time.

    but it pop up the exception when bitmapfield setImage()

    java.lang.IllegalStateEx[0.0] ception: : Screen: View.SplashScreen@97e30a58 Engine:
    
     net.rim.device.a[0.0] pi.ui.UiEngineImpl$UiEngineOldInterfaceAdapter@dee282e2[0.0]
    

    My Code:

    VerticalFieldManager  topManager = new VerticalFieldManager (VerticalFieldManager.FIELD_HCENTER);
    
            int width = Display.getWidth();
            int height = Display.getHeight();
            int logo3s_w = 200;
            int logo3s_h = 130;
            int pocket_w = 220;
            //int pocket_h = 38;
    
            final BitmapField splashField = new BitmapField();
            splashField.setMargin((height - logo3s_h) >> 2, (width - logo3s_w) >> 2 + 100, 0 , 0) ;  //setMargin(int top,int right,int bottom,int left)
            topManager.add(splashField);
    
            final BitmapField splashSecondField = new BitmapField();
            splashSecondField.setMargin(100, (width - pocket_w) >> 2 + 110, 0, 0);
            topManager.add(splashSecondField);
    
            add(topManager);
    
    new Thread(){
                public void run(){
                    System.out.println("--------------------------------Enter splashThread----------------------------------");
                    int frameCount = 0;
                    SplashImage _splashImage = new SplashImage();
                    try{
                        while(frameCount<14){
                            if(_splashImage!=null){
                                System.out.println("-------------------FrameCount: " + frameCount +"-----------------------");
    
                                splashField.setImage(_splashImage.fetchImage("/splash_3s_" + topImageSeq[frameCount] + ".png",true));
                                System.out.println("********************11111111111111");
                                splashSecondField.setImage(_splashImage.fetchImage("/splash_pn_" + bottomImageSeq[frameCount] + ".png", true));
                                System.out.println("*********************22222222222222222");
    
                                try {
                                    Thread.sleep(sleepTimes[frameCount]);
                                } catch (InterruptedException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                                frameCount ++;
    
                            }
    
                        }
                    }catch(Exception e){
                        System.out.println("-----------------------------Splash error---------------------------------: " + e);
                    }
    
                    System.out.println("--------------switch screen------------------------");
    
                    try {
                        screenUtil.switchScreen(new RTSPScreen(true));
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }.start();
    

    To debug on my BOLD 9700 OS 6.0.0.668 device

    It run correctly once and fail, exchange between them.

    I don't know how to fix it. Please help me.

    Thank you all.

    do not use Thread.sleep on the tread of the user interface. your first solution was good, with the exception of the missing invokelater.
    You must combine thread and invokelater, do not use one or the other.

    Another option would be to use the timer/timertask, as long as it is non-blocking.

    Maybe this article is useful:
    http://supportforums.BlackBerry.com/T5/Java-development/display-an-animated-GIF/Ta-p/445014

  • crash in bb::cascades:ImageView:setImage

    no idea about this...

    crush the info:

    End of process 190877883 (mapview) code SIGSEGV = 1 fltno = 11 ip=797774ec(/base/usr/lib/libbbcascades.so.1@_ZN2bb8cascades9ImageView16resetImageSourceEv+0x137) mapaddr = 001774ec. REF = 00000010 = 1 bdslot

    QML:

    ImageView
    {
    ID: myImageView
    objectName: "imageObj.
    visible: false
    scalingMethod: ScalingMethod.AspectFit
    preferredHeight: 768
    preferredWidth: 768
    }

    Button {}

    ...

    onClicked:
    {

    mapViewTest.startGenMapImage ();
    }

    }

    Code:

    Sub MapViewDemo::startGenMapImage()
    {

    ......

    BB:latform::geo:GeoList gList = mapView-> mapData()-> defaultProvider()-> toGeoList();
    BB::Cascades:maps:MapImageGenerator * pMapImgGen = new MapImageGenerator (viewpro, gList);

    Connect (pMapImgGen, SIGNAL (finished(bb::cascades::maps::MapImageGenerator*)),
    This, SLOT (imageIsReady(bb::cascades::maps::MapImageGenerator*)));)

    pMapImgGen_-> start();

    }

    void MapViewDemo::imageIsReady (bb::cascades:maps:MapImageGenerator * pMapImgGen)
    {
    If (! pMapImgGen-> error())
    {
    BB::Cascades:image img (pMapImgGen-> imageData());
    imgView_-> setImage (img);   crushed
    imgView_-> setVisible (true);
    }
    on the other
    {
    qDebug() < "app::generate="" image="" error:"=""> < pmapimggen-=""> error();
    }
    delete pMapImgGen;

    }

    Check "img" and check if the imgView_ is a pointer valid.

  • How do to call the BlackBerry menu form share an Adobe Air application?

    Hello

    I'm looking for a tutorial or demo code that describes how to call the BlackBerry menu sharing an Adobe Air based application.

    I found a tutorial of waterfalls for it - there's one for Adobe Air too?
    - http://bbcascadescode.tumblr.com/post/38998702671/invoke-share-for-bb10

    This is a screenshot of the Action menu:

    Advice welcome!

    Here you go:

    package com.lib.playbook.invocation
    {
        import com.lib.playbook.controls.List;
        import com.lib.playbook.pages.TitlePage;
        import com.lib.playbook.renderers.IconListRenderer;
    
        import flash.events.Event;
        import flash.events.IEventDispatcher;
    
        import qnx.events.InvokeEvent;
        import qnx.events.InvokeQueryTargetEvent;
        import qnx.fuse.ui.core.Action;
        import qnx.fuse.ui.events.ActionEvent;
        import qnx.fuse.ui.events.ListEvent;
        import qnx.invoke.ActionQuery;
        import qnx.invoke.InvokeManager;
        import qnx.invoke.InvokeRequest;
        import qnx.invoke.InvokeTarget;
    
        public class InvokeSearchPage extends TitlePage
        {
            private var request : InvokeRequest = null;
            private var targets : List = new List();
    
            /////////////////////////////////////////////////////////////////////////////////////////
            public function InvokeSearchPage()
            {
                super();
                this.title = 'Search With';
                this.titlebar.dismissAction = new Action( 'Cancel', null, {id:'cancel'} );
                this.titlebar.addEventListener(ActionEvent.ACTION_SELECTED, ActionSelected );
    
                this.targets.cellRenderer = com.lib.playbook.renderers.IconListRenderer;
                this.targets.addEventListener(ListEvent.ITEM_CLICKED, TargetSelected );
                this.targets.rowHeight = 140;
                this.addChild( this.targets );
            }
    
            ///////////////////////////////////////////////////////////////////////////////////////////
            public function filter( request :InvokeRequest ) : void
            {
                this.targets.removeAll();
    
                this.request = request;
    
                //trace( 'filter ' + request.mimeType );
                InvokeManager.invokeManager.addEventListener( InvokeQueryTargetEvent.SUCCESS, TargetsFound );
                InvokeManager.invokeManager.queryInvokeTargets( request.mimeType, request.uri, request.action, request.targetOptions );
            }
    
            ///////////////////////////////////////////////////////////////////////////////////////////
            private function TargetsFound( event : InvokeQueryTargetEvent ) : void
            {
                InvokeManager.invokeManager.removeEventListener(InvokeQueryTargetEvent.SUCCESS, TargetsFound );
                //trace( 'TargetsFound' );
                var action : ActionQuery;
                var target : InvokeTarget;
                for each( action in event.actions )
                {
                    for each( target in action.targets )
                    {
                      this.targets.addItem( { data : target.target, label : target.label, icon : 'file://' + target.icon } );
                    }
                }
            }
    
            ////////////////////////////////////////////////////////////////////
            private function TargetSelected( event :Event ) : void
            {
                if( this.targets.selectedIndex >= 0 )
                {
                  this.request.target = this.targets.selection;
                  InvokeManager.invokeManager.invoke( this.request );
                }
            }
    
            ////////////////////////////////////////////////////////////////////
            private function ActionSelected( event :ActionEvent ) : void
            {
                switch( event.action.data.id )
                {
                    case 'cancel' : this.dispatchEvent( new Event( Event.CANCEL ) ); break;
                }
            }
    
            //////////////////////////////////////////////////////////////////////
            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
            {
                super.updateDisplayList( unscaledWidth, unscaledHeight );
    
                this.targets.setPosition( 10, this.top + 10 );
                this.targets.setActualSize( unscaledWidth - 20, unscaledHeight - this.targets.y - 10 );
            }
        }
    }
    

    And the rendering engine:

    package com.lib.playbook.renderers
    {
    
        import qnx.fuse.ui.display.Image;
        import qnx.fuse.ui.listClasses.CellRenderer;
    
        public class IconListRenderer extends CellRenderer
        {
    
            private var icon    :Image = new Image();
    
            /////////////////////////////////////////////////////////////////////////
            public function IconListRenderer()
            {
                super();
            }
    
            ///////////////////////////////////////////////////////////////
            override protected function onAdded():void
            {
                super.onAdded();
                this.addChild( this.icon );
            }
    
            ///////////////////////////////////////////////////////////////
            override protected function onRemoved():void
            {
                super.onRemoved();
                this.removeChild( this.icon );
            }
    
            /////////////////////////////////////////////////////////////////////////////////////
            override protected function drawLabel(unscaledWidth:Number, unscaledHeight:Number):void
            {
                super.drawLabel( unscaledWidth, unscaledHeight );
    
                if( this.data )
                {
    
                    if( this.data.hasOwnProperty( 'icon' ) && this.data.icon != null )
                    {
                        this.icon.setImage( this.data.icon );
                        this.icon.setPosition( 10, 15 );//( unscaledHeight - this.icon.height ) / 2 );
                    }
                    else
                    {
                        this.icon.setImage( null );
                    }
    
                }
    
                this.label.x = 140;
                this.label.width = unscaledWidth - this.label.x - 20;
            }
        }
    }
    

    references com.lib.playbook our our inner classes, but you should get the approach to apply.

  • ImageView expected to auto-sense orientation

    A few comments to the people of the API:

    Shouldn't the ImageView read the EXIF of a JPEG image and automatic image rotation? And so by default, shouldn't there not a property such as 'autoOrient' or 'function' that this happens?

    Seen developers manually read the EXIF data, manually turn the images, etc., seems to be a waste of developer time.

    Follow-up question: if I do it manually and you end up with a QImage, how to recognize an ImageView to use a QImage? Is this possible?

    And one last question followed: what type is the property of 'image' of the ImageView?  He says it's a QVariant, but is not very useful.  Can we set this property, or is read-only?  Overall, I think that the "image" property documentation could use some improvements.

    Thank you

    Daniel

    Understood that through:

    http://supportforums.BlackBerry.com/T5/Cascades-development/rotation-and-translation-cuts-the-image/...

    ... my container was not big enough. I have change the container that has the ImageView to fill the page, and which prevented the cropping. I'm glad it was something simple.

    Here is a very rough code incase it is useful to someone else:

    #include 
    #include 
    #include 
    #include 
    
    ...
    
    // Gets called when the root container is resized, so that we can track
    // how large it is.
    void PhotosModel::updateContainerSize(qreal width, qreal height)
    {
        // Is this the initial call to updateContainerSize, or did
        // the size of the container change because of an orientation
        // change?
        bool initOrReInit = (containerWidth != (int)width);
    
        containerWidth = width;
        containerHeight = height;
    
        if (initOrReInit && imageLoadedFlag)
        {
            // When we tried to load this, we didn't yet know the width of the
            // screen. Now that we do, display the image.
            qDebug() << "Delayed image load";
            loadImage(photos.at(curPhoto).absoluteFilePath());
        }
    }
    
    void PhotosModel::loadImage(QString file)
    {
        imageLoadedFlag = true;
    
        // If the screen hasn't loaded yet and we don't know how wide
        // the container is, then hold off until we do.
        if (containerWidth == 0)
        {
            qDebug() << "Can't display image yet";
            return;
        }
    
        int width = -1;
        int height = -1;
        bool xyFlip = false;
    
        ExifLoader* loader = exif_loader_new();
        exif_loader_write_file(loader, file.toStdString().c_str());
        ExifData* data = exif_loader_get_data(loader);
    
        imageView->setRotationZ(0);
    
        int desiredRotation = 0;
    
        if (data != NULL)
        {
            //exif_data_dump(data);
    
            // Treating this as int* seems to result in corruption / bad behavior.
            // I think orientation is supposed to be a 'short int', which I would have
            // thought would be 2 bytes, but short int * doesn't seem to be consistent
            // either. So far char* seems to work.
            char* orientationPtr = (char *) GetExifValue(data, EXIF_TAG_ORIENTATION);
    
            if (orientationPtr != NULL)
            {
                //int orientation = *orientationPtr;
    
                int orientation = orientationPtr[0];
    
                // 1 -> OK
                // 3 -> Rotate 180
                // 6 -> CC 90
                // 8 -> C 90
    
                qDebug() << "Orientation: " << orientation;
    
                if (orientation == 3)
                {
                    desiredRotation = -180;
                }
                // NOTE: Also doing this for orientation == 0, because I have
                //       a photo with orientation 0 that seems to need this.
                //       Confused. Picasa seems to know that the image needs
                //       this rotation.
                else if (orientation == 6 || orientation == 0)
                {
                    desiredRotation = 90;
                    xyFlip = true;
                }
                else if (orientation == 8)
                {
                    desiredRotation = -90;
                    xyFlip = true;
                }
                else
                {
                    desiredRotation = 0;
                }
    
                //qDebug() << "Width: " << width << ", Height: " << height;
            }
    
            long* widthPtr = (long *) GetExifValue(data, EXIF_TAG_PIXEL_X_DIMENSION);
            if (widthPtr != NULL)
            {
                width = (int)*widthPtr;
            }
    
            long* heightPtr = (long *) GetExifValue(data, EXIF_TAG_PIXEL_Y_DIMENSION);
            if (heightPtr != NULL)
            {
                height = (int)*heightPtr;
            }
        }
    
        if (width == -1 || height == -1)
        {
            // Trouble. We don't know how large the photo is.
            // For now we'll just show nothing. Will this ever happen? How can we
            // fail more gracefully?
            imageView->setVisible(false);
            ErrorHelpers::showDialog("Missing EXIF Data", "The EXIF data for this image doesn't indicate its width/height, and so it cannot be displayed.");
        }
        else
        {
            imageView->setVisible(true);
        }
    
        int virtualContainerWidth;
        int virtualContainerHeight;
    
        if (xyFlip)
        {
            qDebug() << "xyFlip";
            virtualContainerWidth = containerHeight;
            virtualContainerHeight = containerWidth;
        }
        else
        {
            virtualContainerWidth = containerWidth;
            virtualContainerHeight = containerHeight;
        }
    
        qDebug() << "virtualContainerWidth: " << virtualContainerWidth;
        qDebug() << "virtualContainerHeight: " << virtualContainerHeight;
    
        float imageAspect = (float)width / (float)height;
    
        qDebug() << "imageAspect: " << imageAspect;
    
        float screenAspect = (float)virtualContainerWidth / (float)virtualContainerHeight;
    
        qDebug() << "screenAspect: " << screenAspect;
    
        int imageScreenWidth;
        int imageScreenHeight;
    
        if (imageAspect > screenAspect)
        {
            // Image is wider than screen aspect wise, so X will be limiting dimension.
            if (width > virtualContainerWidth)
            {
                imageScreenWidth = virtualContainerWidth;
            }
            else
            {
                imageScreenWidth = width;
            }
            // Better to round here?
            imageScreenHeight = (int)((float)imageScreenWidth / imageAspect);
    
            qDebug() << "Limited by X";
            qDebug() << "imageScreenWidth: " << imageScreenWidth;
            qDebug() << "imageScreenHeight: " << imageScreenHeight;
        }
        else
        {
            // Image is taller than screen aspect wise, to Y will be limiting dimension.
            if (height > virtualContainerHeight)
            {
                imageScreenHeight = virtualContainerHeight;
            }
            else
            {
                imageScreenHeight = height;
            }
            // Better to round here?
            imageScreenWidth = (int)((float)imageScreenHeight * imageAspect);
    
            qDebug() << "Limited by Y";
            qDebug() << "imageScreenWidth: " << imageScreenWidth;
            qDebug() << "imageScreenHeight: " << imageScreenHeight;
        }
    
        int imageX;
        int imageY;
        imageX = (int)((float)containerWidth / 2.0f - (float)imageScreenWidth / 2.0f);
        imageY = (int)((float)containerHeight / 2.0f - (float)imageScreenHeight / 2.0f);
    
        qDebug() << "imageX: " << imageX;
        qDebug() << "imageY: " << imageY;
    
        imageView->setPreferredWidth(imageScreenWidth);
        imageView->setPreferredHeight(imageScreenHeight);
    
        AbsoluteLayoutProperties* layoutProperties = new AbsoluteLayoutProperties();
    
        layoutProperties->setPositionX(imageX);
        layoutProperties->setPositionY(imageY);
    
        imageView->setLayoutProperties(layoutProperties);
    
        qDebug() << "desiredRotation: " << desiredRotation;
    
        imageView->setRotationZ(desiredRotation);
    
        imageView->setImage(QUrl("file://" + file));
    }
    
    void* PhotosModel::GetExifValue(ExifData* data, ExifTag tag)
    {
        for (int i = 0; i < EXIF_IFD_COUNT; i++)
        {
            ExifContent* content = data->ifd[i];
            ExifEntry* entry = exif_content_get_entry(content, tag);
            if (entry != NULL)
            {
                return entry->data;
            }
        }
    
        return NULL;
    }
    

    ... and some related QML...

    Page {
        Container {
            id: rootContainer
            objectName: "rootContainer"
            background: Color.Black;
            layout: DockLayout {
            }
            horizontalAlignment: HorizontalAlignment.Fill
            verticalAlignment: VerticalAlignment.Fill
    
            attachedObjects: [
                // This handler is tracking the layout frame of the button.
                LayoutUpdateHandler {
                    id: handler
                    onLayoutFrameChanged: {
                        photosModel.updateContainerSize(layoutFrame.width, layoutFrame.height);
                    }
                }
            ]
    
            Container {
                layout: AbsoluteLayout {}
                horizontalAlignment: HorizontalAlignment.Fill
                verticalAlignment: VerticalAlignment.Fill
    
                ImageView {
                    id: imageView
                    objectName: "imageView"
    
                    scalingMethod: ScalingMethod.Fill
    
                    //scalingMethod: ScalingMethod.AspectFit
    
                    preferredWidth: 1
                    preferredHeight: 1
    
                    layoutProperties: AbsoluteLayoutProperties {
                        positionX: 1
                        positionY: 1
                    }
    
                    // Tried this, but the image is still animating into place.
                    loadEffect: ImageViewLoadEffect.None
    
                    attachedObjects: [
                        ImplicitAnimationController {
                            enabled: false
                        }
                    ]
                }
            }
    

    It is an amount disappointing nonsense to be caused by the ImageView doesn't Autodetect not the EXIF orientation flag. Please improve this BlackBerry.

  • Integration of ImageView and Qimage

    A large part of this issue has been discussed here:

    http://supportforums.BlackBerry.com/T5/Cascades-development/imageView-Cascades-noob-question/TD-p/17...

    Basically, the suggested correct way of converting a QImage ImageView is this one:

    PixelBufferData pbd (PixelBufferData::RGBA_PRE,yourQImage.width(),yourQImage.height(),yourQImage.width(),yourQImage.bits());
    
    yourImageView->setImage(pbd);
    

    Then there was someone by specifying the format must be probably BGR instead of RGB, which could be done with OpenGL or like this:

    image.rgbSwapped();
    

    Here is my code I have a problem with:

    PixelBufferData pbd(PixelBufferData::RGBA_PRE, orgPattern.width(), orgPattern.height(),  orgPattern.width(),  orgPattern.rgbSwapped().bits());
    m_patternFrame->setImage(pbd);
    

    orgPattern is a QImage loaded from a file path that is sure to exist. m_patternFrame is a pointer to the ImageView.

    I know that m_patternFrame is a pointer valid because if I call its method setImageSource by the way I created the QImage, it displays this image. But when I run this code, it is printed in the console:

    Context: Cannot find the node target with id %d 906.

    Sometimes the number is different. When I tried again, it was 563. The application is not cursh or gel, but nothing happens with the framework, it is still empty.

    Can anyone provide any help with this problem?

    Thanks for starting a new thread and referring to another thread.  Allows us to provide you with a timely response.

    Before dive us into this too far, what is the width and height?  (We are within the limits, I guess?)

    And can you try to make the setImage in 2 steps: first to create the Image of the PDB rather than implicitly and test! image.isNull)

    Stuart

  • How to convert the Qbytearray into image in cascades

    Hi guys,.

    How can I convert a Qbytearray in image, so that I can show to imageView.Any the code examples will be useful

    Concerning

    Rakesh Shankar.P

    Thanks for your help, I was able to retrieve image

     QImage swapped;
         qDebug()<<"data"<setImage(image);     container->add(testImage);
    

    Concerning

    Rakesh Shankar.P

  • image zoom

    Hello

    In my application, I want to implement ZoomIn, ZoomOut image.but image is zoomin' more than the size of the screen, then I want to move the image.but I can move the image vertically but not horizontally.my problem, I had vertical scrolling.but I have not not Mindprint a horizontal scrolling. I've written below the image display code.

    EncodedImage image = EncodedImage.createEncodedImage (data, 0,
    Data.Length);

    int divisor = Fixed32.toFP (100);

    multiplier int = Fixed32.toFP (i);    I appreciate this is changed to zoom in and zoonout accoring

    int fixedX = Fixed32.toFP (1);
       
    fixedX = Fixed32.div (fixedX, divisor);
          
    fixedX = Fixed32.mul (fixedX, multiplier);

    int fixedY = Fixed32.toFP (1);
    fixedY = Fixed32.div (fixedY, divisor);
    fixedY = Fixed32.mul (fixedY, multiplier);

    image = image.scaleImage32 (fixedX, fixedY);

    BitmapField bitmapField = new BitmapField() {}
    protected boolean trackwheelClick (int status, int time) {}
    zoomIn();
    Returns true;
    }
    };
    bitmapField.setImage (image);
    Return bitmapField;

    I appreciate is changed accoring to zoom in and zoom out is pressed. Is there a solution to move the donkey left right (horizontal) posiotiions of the image.

    I suspect that this will help you:

    -Creates a scrolling image field
    Article number: DB-00681
    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

  • BB10 camera image returns null bitmap

    I use the Invoke method to open the camera and take a picture, and then close the map given by jtegen.

    When I put the Image, I don't get an error, but the information is zero.

    The event data are back with a location of the image.

    What step am I missing?

    private function CardClosed( event:CardCloseEvent ) : void
    {
        trace( 'card closed ' + event.reason + ' ' + event.data );
        InvokeManager.invokeManager.removeEventListener( CardCloseEvent.CARD_CLOSED, CardClosed );
    
        if( event.reason == 'save' && event.data != '' )
        {
            trace("data : " + event.data);
            // example data value : '/accounts/1000/removable/sdcard/camera/IMG_00000131.jpg'
            imgCapture = new Image();
            imgCapture.setImage( "file://" + event.data );
    
            decodeBitmapData(imgCapture.bitmapData, stage.stageWidth, stage.stageHeight);
        }
    }
    

    I wanted to just note that I tried to put the image by using the following text:

    • "file://" + event.data
    • "file:/". "+ event.data
    • Event.Data

    Same result for all 3 channels.

    I thought about it.  Not everything works, but I'm capturing the image.

    I just need to add the loader to get the image and then place this content in the image.

    private function CardClosed( event:CardCloseEvent ) : void
    {
        trace( 'card closed ' + event.reason + ' ' + event.data );
        InvokeManager.invokeManager.removeEventListener( CardCloseEvent.CARD_CLOSED, CardClosed );
    
        if( event.reason == 'save' && event.data != '' )
        {
            trace("request length" + cameraRequest.data.length);
    
            imgCaptureLoader = new flash.display.Loader();
            imgCaptureLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageCapture);
            imgCaptureLoader.load(new URLRequest('file://' + event.data ));
        }
    }       
    
    private function onImageCapture( event:Event ):void {
        imgCapture = new Image();
        imgCapture.visible = false;
        try {
            imgCapture.setImage( imgCaptureLoader.content );
            decodeBitmapData(imgCapture.bitmapData, stage.stageWidth, stage.stageHeight);
        } catch (e:*) {
            trace(" load error: " + e);
        }
    }
    
  • How to define upskin and downskin

    Hai, I need to know how to set upskin and downskin on the list... I tried this

    package com.cellapp.list.skin
    {
        import flash.display.Sprite;
        import flash.geom.Rectangle;
    
        import qnx.fuse.ui.display.Image;
        import qnx.fuse.ui.listClasses.CellRenderer;
        import qnx.fuse.ui.text.Label;
        import qnx.fuse.ui.text.TextAlign;
        import qnx.fuse.ui.text.TextFormat;
    
        public class ListSkin extends CellRenderer
        {
            /*UPSKIN*/
            protected var upSkin:Sprite;
    
            /*DOWNSKIN*/
            protected var downSkin:Sprite;
    
            /*SELECTEDSKIN*/
            protected var selectedSKin:Sprite;
    
            protected var gridRect:Rectangle;
    
            public function ListSkin ()
            {
                super();
    
                gridRect = new Rectangle(0,0, 768, 100);
    
            }
    
            override public function set data(value:Object):void
            {
                // TODO Auto Generated method stub
                super.data = value.data;
                updateUI();
    
                try{
                    upSkin          =   new Sprite();
                    upSkin.graphics.beginFill(0x000000);
                    upSkin.graphics.drawRect(0,0,768, 100);
                    upSkin.graphics.endFill();
                    upSkin.alpha    =   1;
                    upSkin.scale9Grid   =   gridRect;
    
                    downSkin            =   new Sprite();
                    downSkin.graphics.beginFill(0x000000);
                    downSkin.graphics.drawRect(0,0,768, 100);
                    downSkin.graphics.endFill();
                    downSkin.alpha  =   1;
                    downSkin.scale9Grid = gridRect;
                }
                catch(e:Error)
                {
                    trace("EEEE : " , e.message);
                }
    
            }   
    
            private function updateUI():void
            {
                trace("here");
                var img:Image = new Image();
                img.setImage(data.img);
                img.alpha               =   data.alpha;
                img.x = 568;
                img.y = 20;
    
                /*var backGround:Image          =   new Image();
                backGround.setImage(data.background);
                backGround.setPosition(0,0);*/
    
                var textFormat:TextFormat       = new TextFormat();
                textFormat.color                =   0x000000;
                textFormat.align                =   TextAlign.LEFT;
                textFormat.italic               =   true;
                textFormat.size                 =   47;
    
                var oneLable:Label              =   new Label();
                oneLable.alpha                  =   1;
                oneLable.text                   =   data.text;
                oneLable.x                      =   30;
                oneLable.y                      =   15;
                oneLable.format                 =   textFormat;
                oneLable.width                  =   768;
                oneLable.height                 =   100;            
    
                //addChild(img1);
            //  addChild(backGround);
                addChild(oneLable);
                addChild(img);
    
            }       
    
            override public function set state(value:String):void
            {
                // TODO Auto Generated method stub
                super.state = value;
    
                try
                {
                    trace("VALUE ", value);
                    if(value=="up")
                    {
                        setSkin(upSkin);
                    }
                    else
                    {
                        if(value=="down")
                        {
                            setSkin(downSkin);
                        }
                        else
                        {
    
                        }
                    }
                }
                catch(e:Error)
                {
                    trace("VALERR : ",  e.message);
                }
    
            }
    
        }
    }
    

    Any help is appreciated

    Thanks in advance...

    Hello!

    «"" You're almost here!»»»

    I see that in these two sprites (upSkin and downSkin), the color is black (0x000000) so you will not see the change.

    In addition, there is no function setSkin (at least it is not in the latest version of the SDK). So, I used sprites as a backdrop. In the service of the State (that you evaluate correctly), you must add the upSkin sprite when the State is in PLACE (by default) and also you must change for downSkin when the State of the cell is out of SERVICE.

    Something like this:

    override public function set state(value:String):void
    {
        super.state = value;
        if(value=="up")
        {                 upSkin = new Sprite();                 upSkin.graphics.beginFill(0x000000);                 upSkin.graphics.drawRect(0,0,768, 100);                 upSkin.graphics.endFill();                 upSkin.alpha = 1;                 addChild(upSkin);
            }        else if(value=="down")        {                 downSkin = new Sprite();
             downSkin.graphics.beginFill(0x01A8DF);
             downSkin.graphics.drawRect(0,0,768, 100);
             downSkin.graphics.endFill();
             downSkin.alpha = 1;                 addChild(downSkin);       }}
    

    In this way, you will see the background color change when you select a cell in the list.

    I hope it will work for you.

  • Strange behavior of ListView

    Hello
    I use following code:

     ListView {       id: listView listItemComponents: ListItemComponent {           Container {               id: listItemContainer               property string packageId: ListItemData.packageId               property variant packageDetailsPage               layout: AbsoluteLayout { }               WebImageView               {                   preferredHeight: 290                   preferredWidth: 751                   url: ListItemData.url;              }          }     }
    

    code for WebImageView:

    webimageview. HPP

    #ifndef WEBIMAGEVIEW_H_
    #define WEBIMAGEVIEW_H_
    
    #include 
    #include 
    #include 
    #include 
    using namespace bb::cascades;
    
    class WebImageView: public bb::cascades::ImageView {
        Q_OBJECT
        Q_PROPERTY (QUrl url READ url WRITE setUrl NOTIFY urlChanged)
        Q_PROPERTY (float loading READ loading NOTIFY loadingChanged)
    
    public:
        WebImageView();
        const QUrl& url() const;
        double loading() const;
    
        public Q_SLOTS:
        void setUrl(const QUrl& url);
        void clearCache();
    
        private Q_SLOTS:
        void imageLoaded();
        void dowloadProgressed(qint64,qint64);
    
        signals:
        void urlChanged();
        void loadingChanged();
    
    private:
        static QNetworkAccessManager * mNetManager;
        static QNetworkDiskCache * mNetworkDiskCache;
        QUrl mUrl;
        float mLoading;
    
        bool isARedirectedUrl(QNetworkReply *reply);
        void setURLToRedirectedUrl(QNetworkReply *reply);
    };
    
    #endif /* WEBIMAGEVIEW_H_ */
    

    webimageview.cpp

    #include "WebImageView.h"
    #include 
    #include 
    //#include 
    #include 
    
    using namespace bb::cascades;
    
    QNetworkAccessManager * WebImageView::mNetManager = new QNetworkAccessManager();
    //QNetworkDiskCache * WebImageView::mNetworkDiskCache = new QNetworkDiskCache();
    
    WebImageView::WebImageView() {
        // Initialize network cache
        //mNetworkDiskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
    
        // Set cache in manager
        //mNetManager->setCache(mNetworkDiskCache);
    
        // Set defaults
    
        mLoading = 0;
    }
    
    const QUrl& WebImageView::url() const {
        return mUrl;
    }
    
    void WebImageView::setUrl(const QUrl& url) {
        // Variables
    
            mUrl = url;
            mLoading = 0;
            qDebug()<<"url:: "<get(request);
    
            // Connect to signals
            QObject::connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded()));
            QObject::connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(dowloadProgressed(qint64,qint64)));
    
            emit urlChanged();
    
    }
    
    double WebImageView::loading() const {
        return mLoading;
    }
    
    void WebImageView::imageLoaded() {
        // Get reply
        QNetworkReply * reply = qobject_cast(sender());
        QObject::disconnect(reply, SIGNAL(finished()), this, SLOT(imageLoaded()));
        QObject::disconnect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(dowloadProgressed(qint64,qint64)));
        if (reply->error() == QNetworkReply::NoError) {
            if (isARedirectedUrl(reply)) {
                setURLToRedirectedUrl(reply);
                return;
            } else {
                QByteArray imageData = reply->readAll();
                setImage(Image(imageData));
            }
        }
        // Memory management
        reply->deleteLater();
    }
    
    bool WebImageView::isARedirectedUrl(QNetworkReply *reply) {
        QUrl redirection = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        return !redirection.isEmpty();
    }
    
    void WebImageView::setURLToRedirectedUrl(QNetworkReply *reply) {
        QUrl redirectionUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        QUrl baseUrl = reply->url();
        QUrl resolvedUrl = baseUrl.resolved(redirectionUrl);
    
        setUrl(resolvedUrl.toString());
    }
    
    void WebImageView::clearCache() {
        //mNetworkDiskCache->clear();
    }
    
    void WebImageView::dowloadProgressed(qint64 bytes, qint64 total) {
        mLoading = double(bytes) / double(total);
    
        emit loadingChanged();
    }
    

    I use ListDataModel. and code above works fine and the loading of the images. But when there are more than 100 items in a list it shows the bad images in some WebImageView. When you scroll through random images change. I checked the url property of webImageView to the point where bad image is loaded, but there the right url.

    in this connection, blackberry says that view list follows MVC architecture, and QObject belonged to ListView objects are deleted when scrolling out of the area visible to the element to which they belong, or when the ListView itself is deleted. What is the cause of my problem? If not, this what's wrong with this code? Help, please...

    nik005 wrote:

    @ekke Yes. If I scroll slowly, it works fine.

    THX.

    Then, it's the same reason.

    as soon as I have a small reproducible application to create a problem, I'll add this thread and let you know

  • display image in ImageView of C++ QImage

    Hello

    I'm strunglling to view an image in QML ImageView of QImage in C++. I did a lot of gogling and reading posts in the forum but without success.

    I have the code in c ++

    bb::ImageData fromQImage(const QImage &qImage)
    {
        qDebug() << QString::number(qImage.format());
        bb::ImageData imageData(bb::PixelFormat::RGBA_Premultiplied, qImage.width(), qImage.height());
    
        unsigned char *dstLine = imageData.pixels();
        for (int y = 0; y < imageData.height(); y++) {
            unsigned char * dst = dstLine;
            for (int x = 0; x < imageData.width(); x++) {
                QRgb srcPixel = qImage.pixel(x, y);
                *dst++ = qRed(srcPixel);
                *dst++ = qGreen(srcPixel);
                *dst++ = qBlue(srcPixel);
                *dst++ = qAlpha(srcPixel);
            }
            dstLine += imageData.bytesPerLine();
        }
    
        return imageData;
    }
    
    Image ApplicationUI::getImage() const {
    
        QString appFolder(QDir::homePath());
        appFolder.chop(4);
        QString src=appFolder + "app/native/assets/images/Help.PNG";
        QImage img(src);
    
        bb::ImageData cstmImg = fromQImage( img );
        return cstmImg;
    }
    

    and then in QML I use it like this

                ImageView {
                    id: test
                    horizontalAlignment: HorizontalAlignment.Center
                    verticalAlignment: VerticalAlignment.Center
                    attachedObjects: [
                        ImageTracker {
                            id: imgTracker
                            imageSource: ""
                            onStateChanged: {
                                if (state == ResourceState.Loaded)
                                {
                                    test.image = _app.getImage()
                                }
                            }
                        }
                    ]
                }
    

    but I have nothing on the screen.

    What I am doing wrong?

    Thank you

    Well, I found a solution to display the image. Maybe this can help someone.

    I don't know if it's the right way to do it but it worked for me.

    In the constructor of the Application, I used this code

    ImageView * setImg = root->findChild("testImg1");
    setImg->setImage(getImage());
    

    and in main.qml, I put these lines

    ImageView {
                    id: test
                    objectName: "testImg1"
                    horizontalAlignment: HorizontalAlignment.Center
                    verticalAlignment: VerticalAlignment.Center
                }
    

    It will not work for any custom or pushed qml qmls.

  • Photos poorly oriented when pulled from filepicker

    In my application I allow users to take a photo or select an image using the filepicker.  But when she shows the images in an imageView that they appear on the side and never in the correct position, no matter if they were taken without focus lock, or whatever.  When I invoke the display of images, howeverm images are always perfectly oriented.

    Is there anything I can do in my code to accommodate for this?  Orientation is off differently isn't tlike it's always oritented left, sometimes it's to the right, sometimes it is upside down, sometimes it's to the left.

    Hello

    I know exactly what is happening - I'm working on an app photo from last year, and I had the same problem.

    When the camera takes a photo, it adds some EXIF metadata in the JPEG file that indicates its "focus".

    In my opinion, the BB should add an ImageView option such as "autoOrient" so that it would automatically read and the picture rotates as appropriate before posting, but I don't think such a property exists. Thus, all the developers who want to display pictures must add this logic to their App (inefficient or what?)

    The good news is that there is a sample application that shows how to do this.  Take a look at the sample application "photobomber.

    I'll copy and paste the relevant code here:

    QImage PhotoBomberApp::getRotateImage(const QString imageFilePath)
    {
        //Load the image using QImage.
        QImage image = QImage(imageFilePath);
    
        ExifData *exifData = 0;
        ExifEntry *exifEntry = 0;
        int exifOrientation = 1;
    
        // Since the image will loose its exif data when its opened in a QImage
        // it has to be manually rotated according to the exif orientation.
        exifData = exif_data_new_from_file(imageFilePath.toLatin1().data());
    
        // Locate the orientation exif information.
        if (exifData != NULL) {
            for (int i = 0; i < EXIF_IFD_COUNT; i++) {
                exifEntry = exif_content_get_entry(exifData->ifd[i], EXIF_TAG_ORIENTATION);
    
                // If the entry corresponds to the orientation it will be a non zero pointer.
                if (exifEntry) {
                    exifOrientation = exif_get_short(exifEntry->data, exif_data_get_byte_order(exifData));
                    break;
                }
            }
        }
    
        // A transform will be used to rotate the image according to device and exif orientation.
        QTransform transform;
    
        qDebug() << "Exif data:" << exifOrientation;
    
        // It's a bit tricky to get the correct orientation of the image. A combination of
        // the way the the device is oriented and what the actual exif data says has to be used
        // in order to rotate it in the correct way.
        switch(exifOrientation) {
            case 1:
                // 0 degree rotation
                break;
            case 3:
                // 180 degree rotation
                transform.rotate(180);
                break;
            case 6:
                // 90 degree rotation
                transform.rotate(90);
                break;
            case 8:
                // 270 degree rotation
                transform.rotate(270);
                break;
            default:
                // Other orientations are mirrored orientations, do nothing.
                break;
        }
    
        // Perform the rotation of the image before its saved.
        image = image.transformed(transform);
    
        return image;
    }
    

    This code returns you a QImage, so you can or may not know how, then take that and display them in an ImageView. Incase it's useful, here's an example of my application relating to this code:

    QImage thisQImage = getRotateImage(...);
    
    bb::ImageData imageData = bb::ImageData::fromPixels(thisQImage.rgbSwapped().bits(), bb::PixelFormat::RGBX, thisQImage.width(), thisQImage.height(), thisQImage.bytesPerLine());
    
    bb::cascades::Image cascadesImage = imageData;
    
    imageView->setImage(cascadesImage);
    

    A final caveat is that doing each of these conversions between types of image data takes a little time, and so if you do it in the main thread of the application, you might or might not slow down the user interface.  I tried to move my loading image in another thread when it is possible, although I found (I think) the conversion in bb::cascades:Image does not work correctly if this isn't in the main thread, so I don't have this part and call setImage in the main thread.

    Hope that helps. Here the answer was simpler.

  • Example of path of application?

    I tried to load an image, and I get URL not found error.

    I use background.setImage ("image.png");

    I have the image in the folder of the project and in the src folder.

    Is there something that I am missing?

    Thank you

    Chris S

    Can you post a snippet of code, if your code is not so much owner to avoid to post publicly?

    For example, to load an image to a local directory file app using a URLRequest object is current:

    myURLRequest = new URLRequest("app:///");
    

    Some people like to separate their assets in separate directories, then you might have a path like

    App:///assets/images/image.PNG.

    You create a URLRequest object as above and then use the method of a Loader object for

    load the URL and once it loaded successfully, access the ContentLoaderInfo.content property of the

    Object Loader.

  • can't see the image captured using the camera

    I captured a picture and now I am trying to display this image, it is very difficult for me to do.

    I created imageTracker and when the image is loaded I am made aware of this in onStateChange, but when I try to display the loaded image is always empty, I changed the imageView size and it will indeed smaller on screen, but still a Virgin.

    I know the name of the file that I give to the imagetracker is ok (adding file://) because if I change it to something other code onStateChange is not called.

    I've been to this simple task for a few hours now so someone help me please if you can.

    void App::onStateChanged(bb::cascades::ResourceState::Type state)
    {
        if(state == bb::cascades::ResourceState::Loaded)
        {
            mImage = ImageView::create();
            mImage->setImage(mImageTracker->image());
            mImage->setMaxWidth(500);
            mImage->setMaxHeight(500);
    
            Page *page = new Page();
    
                page->setContent(mImage);
    
                mRoot->pop();
                mRoot->push(page);
        }
    }
    

    http://supportforums.BlackBerry.com/T5/Cascades-development/imageView-Cascades-noob-question/TD-p/17...

    This thread has code examples on image resizing using QImage.

Maybe you are looking for