mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Followup b8bc181, don't create unnecessary temporary image
This commit is contained in:
parent
09192ee982
commit
c38ff519e2
@ -131,12 +131,23 @@ class QgsImageOperation
|
||||
*/
|
||||
static void flipImage( QImage &image, FlipType type );
|
||||
|
||||
/** Calculates the non-transparent region of an image.
|
||||
* @param image source image
|
||||
* @param minSize minimum size for returned region, if desired. If the
|
||||
* non-transparent region of the image is smaller than this minimum size,
|
||||
* it will be centered in the returned rectangle.
|
||||
* @param center return rectangle will be centered on the center of the original image if set to true
|
||||
* @note added in QGIS 2.9
|
||||
* @see cropTransparent
|
||||
*/
|
||||
static QRect nonTransparentImageRect( const QImage & image, const QSize& minSize = QSize(), bool center = false );
|
||||
|
||||
/** Crop any transparent border from around an image.
|
||||
* @param image source image
|
||||
* @param minSize minimum size for cropped image, if desired. If the
|
||||
* cropped image is smaller than the minimum size, it will be centered
|
||||
* in the returned image.
|
||||
* @param center croped image will be centered on the center of the original image
|
||||
* @param center cropped image will be centered on the center of the original image if set to true
|
||||
* @note added in QGIS 2.9
|
||||
*/
|
||||
static QImage cropTransparent( const QImage & image, const QSize& minSize = QSize(), bool center = false );
|
||||
|
@ -793,7 +793,7 @@ void QgsImageOperation::flipImage( QImage &image, QgsImageOperation::FlipType ty
|
||||
runLineOperation( image, flipOperation );
|
||||
}
|
||||
|
||||
QImage QgsImageOperation::cropTransparent( const QImage &image, const QSize &minSize, bool center )
|
||||
QRect QgsImageOperation::nonTransparentImageRect( const QImage &image, const QSize &minSize, bool center )
|
||||
{
|
||||
int width = image.width();
|
||||
int height = image.height();
|
||||
@ -838,7 +838,13 @@ QImage QgsImageOperation::cropTransparent( const QImage &image, const QSize &min
|
||||
ymin = qMax( 0, height / 2 - dy );
|
||||
ymax = qMin( height, height / 2 + dy );
|
||||
}
|
||||
return image.copy( xmin, ymin, xmax - xmin, ymax - ymin );
|
||||
|
||||
return QRect( xmin, ymin, xmax - xmin, ymax - ymin );
|
||||
}
|
||||
|
||||
QImage QgsImageOperation::cropTransparent( const QImage &image, const QSize &minSize, bool center )
|
||||
{
|
||||
return image.copy( QgsImageOperation::nonTransparentImageRect( image, minSize, center ) );
|
||||
}
|
||||
|
||||
void QgsImageOperation::FlipLineOperation::operator()( QRgb *startRef, const int lineLength, const int bytesPerLine )
|
||||
|
@ -162,12 +162,23 @@ class CORE_EXPORT QgsImageOperation
|
||||
*/
|
||||
static void flipImage( QImage &image, FlipType type );
|
||||
|
||||
/** Calculates the non-transparent region of an image.
|
||||
* @param image source image
|
||||
* @param minSize minimum size for returned region, if desired. If the
|
||||
* non-transparent region of the image is smaller than this minimum size,
|
||||
* it will be centered in the returned rectangle.
|
||||
* @param center return rectangle will be centered on the center of the original image if set to true
|
||||
* @note added in QGIS 2.9
|
||||
* @see cropTransparent
|
||||
*/
|
||||
static QRect nonTransparentImageRect( const QImage & image, const QSize& minSize = QSize(), bool center = false );
|
||||
|
||||
/** Crop any transparent border from around an image.
|
||||
* @param image source image
|
||||
* @param minSize minimum size for cropped image, if desired. If the
|
||||
* cropped image is smaller than the minimum size, it will be centered
|
||||
* in the returned image.
|
||||
* @param center croped image will be centered on the center of the original image
|
||||
* @param center cropped image will be centered on the center of the original image if set to true
|
||||
* @note added in QGIS 2.9
|
||||
*/
|
||||
static QImage cropTransparent( const QImage & image, const QSize& minSize = QSize(), bool center = false );
|
||||
|
@ -163,28 +163,19 @@ QSize QgsSymbolV2LegendNode::minimumIconSize() const
|
||||
if ( mItem.symbol() && mItem.symbol()->type() == QgsSymbolV2::Marker )
|
||||
{
|
||||
QScopedPointer<QgsRenderContext> context( createTemporaryRenderContext() );
|
||||
QPixmap pix = QPixmap::fromImage(
|
||||
QgsImageOperation::cropTransparent(
|
||||
QgsSymbolLayerV2Utils::symbolPreviewPixmap(
|
||||
mItem.symbol(),
|
||||
QSize( 512, 512 ),
|
||||
context.data() ).toImage(),
|
||||
mIconSize,
|
||||
true ) );
|
||||
minSz = pix.size();
|
||||
minSz = QgsImageOperation::nonTransparentImageRect(
|
||||
QgsSymbolLayerV2Utils::symbolPreviewPixmap( mItem.symbol(), QSize( 512, 512 ), context.data() ).toImage(),
|
||||
mIconSize,
|
||||
true ).size();
|
||||
}
|
||||
else if ( mItem.symbol() && mItem.symbol()->type() == QgsSymbolV2::Line )
|
||||
{
|
||||
QScopedPointer<QgsRenderContext> context( createTemporaryRenderContext() );
|
||||
QPixmap pix = QPixmap::fromImage(
|
||||
QgsImageOperation::cropTransparent(
|
||||
QgsSymbolLayerV2Utils::symbolPreviewPixmap(
|
||||
mItem.symbol(),
|
||||
QSize( mIconSize.width(), 512 ),
|
||||
context.data() ).toImage(),
|
||||
mIconSize,
|
||||
true ) );
|
||||
minSz = pix.size();
|
||||
minSz = QgsImageOperation::nonTransparentImageRect(
|
||||
QgsSymbolLayerV2Utils::symbolPreviewPixmap( mItem.symbol(), QSize( mIconSize.width(), 512 ),
|
||||
context.data() ).toImage(),
|
||||
mIconSize,
|
||||
true ).size();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user