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
selvaraman
Posts: 29
Registered: ‎09-07-2012
My Device: 9900

Crop the image in bb10

Hi,

 

I want to crop the largest image in bb10.How can i achieve this? any help would be appreciated..

 

thanks,

Developer
rlvl
Posts: 55
Registered: ‎02-17-2013
My Device: Z10 LE

Re: Crop the image in bb10

In Image view there will be certain QML properties such as scaling method. Perhaps they will help

Contributor
selvaraman
Posts: 29
Registered: ‎09-07-2012
My Device: 9900

Re: Crop the image in bb10

I need to crop the image and upload to server, when i send to server without crop the image it won't send as like original image, some data's are truncated or something happen unnecessarily. When i received it from server some pixels are not displaying..

Developer
rlvl
Posts: 55
Registered: ‎02-17-2013
My Device: Z10 LE

Re: Crop the image in bb10

Are you using QML? 

Contributor
selvaraman
Posts: 29
Registered: ‎09-07-2012
My Device: 9900

Re: Crop the image in bb10

yes, but send the image data to server using c++ code.

Developer
rlvl
Posts: 55
Registered: ‎02-17-2013
My Device: Z10 LE

Re: Crop the image in bb10

Ok, perhaps u can crop it using qml.. And then allow C code to take over

For cropping in qml u can do the following: put the image in Rectangle and set Rectangle’s clip property to true. you will have  to properly position Image with x and y properties.

Found the solution online, but seems legit!

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Crop the image in bb10

Hi,

 

QImage can be used for this:

QImage image("initial_image.jpg");
QImage copy;
copy = image.copy( 0, 0, 128, 128); 
copy.save("cropped_image.jpg");

QImage's contents can also be saved to QByteArray for sending them over network.

 

QImage can be converted to ImageView for displaying.

 


Andrey Fidrya, @zmeyc on twitter
New Contributor
rajuttam
Posts: 6
Registered: ‎03-03-2013
My Device: BB10

Re: Crop the image in bb10

Can anyone please post the code snippet for cropping the image in BB10?

 

Thanks in advance.

Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Crop the image in bb10

Here is how I crop a cover image into a thumbnail:

 

QString tempPath = getAbsoluteTemporaryFolderPath() + filename;
QString thumbnailPath = comic->getThumnailPath();
QImageReader coverImageReader(tempPath);
QImage coverImage = coverImageReader.read();
qDebug() << "DataManager:: cover image width is " << coverImage.width();
if(coverImage.width() > 0)
{
    qDebug() << "DataManager:: size of cover is " << coverImage.numBytes() << " bytes";
    QImage result = coverImage.scaled(COVERWIDTH, COVERHEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    result.save(thumbnailPath, "PNG", 50);
    qDebug() << "DataManager:: saved thumbnail to " << thumbnailPath;
}
else
{
    qDebug() << "DataManager:: could not load temporary fullsize image";
}

 

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
New Contributor
rajuttam
Posts: 6
Registered: ‎03-03-2013
My Device: BB10

Re: Crop the image in bb10

Hi Zezke,

 

Thanks for the code. Actually my requirement is something different. I have a large image of size suppose 1600x1200. I have to place it inside a container of size  200 x 300 . So i want to crop the image from (0,0) position till (200, 300). 

 

All the APIs provided in Qt/ QML scaling method are not supporting to do this. How to achieve this?

 

Thanks,

Uttam