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
Contributor
Posts: 11
Registered: ‎12-15-2012
My Device: bb10
My Carrier: yangji

How to get a fixed size picture from Album or camera?

Hi:

   I am working on the function of user's head portrait upload,is there some API to get a fixed size picture?

Or I must write the process to ask Album and camera,and clip by myself?

 

Thanks

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: How to get a fixed size picture from Album or camera?

Hello

 

can you clarify what you mean by "get" please? Do you mean:

 

a) Resize the dimensions of an image file and save it

b) Set the size of the displayed image in your UI without changing the physical dimensions of the image file itself?

c) Something else :-)

 

Thanks

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Contributor
Posts: 11
Registered: ‎12-15-2012
My Device: bb10
My Carrier: yangji

Re: How to get a fixed size picture from Album or camera?

In ios & android,there is a system API to get fixed size(200x200 etc) picture,and we do not care where the pic comes from(from album & camera(front or back)). I do not think bb10 has such API now,right?

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: How to get a fixed size picture from Album or camera?

OK, but I'm still not sure what you want to do with picture. Is it so you can display it as a fixed size? If so, you can constrain the size of an ImageView in Cascades and set scaling ratios so maybe that would help?

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: How to get a fixed size picture from Album or camera?

Actually, you may find that the QImage class does what you want:

 

http://harmattan-dev.nokia.com/docs/library/html/qt4/qimage.html#scaled

 

You need to link with QtGui to work with QImage.

 

See https://developer.blackberry.com/native/reference/cascades/bb__imagedata.html for mention of this.

 

Hope this helps.

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Contributor
Posts: 11
Registered: ‎12-15-2012
My Device: bb10
My Carrier: yangji

Re: How to get a fixed size picture from Album or camera?

Thanks,I was make a user head portrait upload to server,the game based on cocos2-dx,while QImage,cascade will rely on qt,do you know how to integrate aApp.exec() with cocos2d-x?

Developer
Posts: 1,163
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: How to get a fixed size picture from Album or camera?

The Cascades Image class doesn't allow you to actually change the size of an image, just scale it for display. On the other hand, the Qt QImage class does provide this function, but then you have to convert it to a Cascades Image before displaying it. You can do this by copying the pixels into an ImageData and then using that to create a Cascades Image. Use scaled()scaledToWidth, or scaledToHeight() to resize the Qimage to the size you need then you can do something like this to convert from QImage to Cascades Image:

 

Image toNativeImage( QImage* source ) {
    bb::ImageData imageData( bb::PixelFormat::RGBA_Premultiplied, source->width(), source->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 = source->pixel( x, y );
            *dst++ = qRed( srcPixel );
            *dst++ = qGreen( srcPixel );
            *dst++ = qBlue( srcPixel );
            *dst++ = qAlpha( srcPixel );
        }
        dstLine += imageData.bytesPerLine();
    }
    return Image( imageData );
}

 

:

 

 


water_core wrote:

In ios & android,there is a system API to get fixed size(200x200 etc) picture,and we do not care where the pic comes from(from album & camera(front or back)). I do not think bb10 has such API now,right?






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.