黑莓级联中的图像旋转问题
Image rotation issue in blackberry cascades
我有一个应用程序,用户可以在其中拍摄并保存他们的个人资料照片。我正在使用 github 中的 https://github.com/RileyGB/BlackBerry10-Samples/tree/master/WebImageViewSample 样本将 url 中的图像加载到我的视图中,它工作正常。问题是当我从 ios 保存个人资料图片并在黑莓中查看个人资料图片时,它看起来向左旋转了 90 度。但相同的 url 在 ios 和 android 中加载正常。下面是从 iOS 中截取的示例图像的 link,它可以正确加载 ios 和 android,但在黑莓中向左移动了 90 度。它适用于从黑莓或 android 拍摄的其他图像。有没有什么办法解决这一问题?感谢任何帮助
http://oi57.tinypic.com/2hzj2c4.jpg
下面是在qml中加载这张图片的示例代码
Page {
Container {
layout: DockLayout {
}
WebImageView {
id: webViewImage
url: "http://oi57.tinypic.com/2hzj2c4.jpg"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
visible: (webViewImage.loading == 1.0)
}
ProgressIndicator {
value: webViewImage.loading
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
visible: (webViewImage.loading < 1.0)
}
}
actions: [
ActionItem {
title: "Clear Cache"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
webViewImage.clearCache();
webViewImage.url = "http://oi57.tinypic.com/2hzj2c4.jpg";
}
}
]
}
我能够通过添加 EXIF 库并在 webimageview 中添加附加功能来解决这个问题 class
QByteArray WebImageView::getRotateImage(QByteArray imageFile)
{
//Load the image using QImage.
// A transform will be used to rotate the image according to device and exif orientation.
QTransform transform;
QImage image;
image.loadFromData((unsigned char*)imageFile.data(),imageFile.length(),"JPG");
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_data((unsigned char*)imageFile.data(),(unsigned int)imageFile.size());
// 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;
}
}
}
// 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
return imageFile;
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);
QImage img =image;
QByteArray arr;
QBuffer buf(&arr);
buf.open(QIODevice::WriteOnly);
img.save(&buf, "PNG");
buf.close();
return arr;
}
我有一个应用程序,用户可以在其中拍摄并保存他们的个人资料照片。我正在使用 github 中的 https://github.com/RileyGB/BlackBerry10-Samples/tree/master/WebImageViewSample 样本将 url 中的图像加载到我的视图中,它工作正常。问题是当我从 ios 保存个人资料图片并在黑莓中查看个人资料图片时,它看起来向左旋转了 90 度。但相同的 url 在 ios 和 android 中加载正常。下面是从 iOS 中截取的示例图像的 link,它可以正确加载 ios 和 android,但在黑莓中向左移动了 90 度。它适用于从黑莓或 android 拍摄的其他图像。有没有什么办法解决这一问题?感谢任何帮助
http://oi57.tinypic.com/2hzj2c4.jpg
下面是在qml中加载这张图片的示例代码
Page {
Container {
layout: DockLayout {
}
WebImageView {
id: webViewImage
url: "http://oi57.tinypic.com/2hzj2c4.jpg"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
visible: (webViewImage.loading == 1.0)
}
ProgressIndicator {
value: webViewImage.loading
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
visible: (webViewImage.loading < 1.0)
}
}
actions: [
ActionItem {
title: "Clear Cache"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
webViewImage.clearCache();
webViewImage.url = "http://oi57.tinypic.com/2hzj2c4.jpg";
}
}
]
}
我能够通过添加 EXIF 库并在 webimageview 中添加附加功能来解决这个问题 class
QByteArray WebImageView::getRotateImage(QByteArray imageFile)
{
//Load the image using QImage.
// A transform will be used to rotate the image according to device and exif orientation.
QTransform transform;
QImage image;
image.loadFromData((unsigned char*)imageFile.data(),imageFile.length(),"JPG");
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_data((unsigned char*)imageFile.data(),(unsigned int)imageFile.size());
// 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;
}
}
}
// 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
return imageFile;
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);
QImage img =image;
QByteArray arr;
QBuffer buf(&arr);
buf.open(QIODevice::WriteOnly);
img.save(&buf, "PNG");
buf.close();
return arr;
}