标签: image-resizing

如何将C#中的图像大小调整为某个硬盘大小?

如何将图像中的图像大小调整为C#到某个硬盘大小,如2MiB?有没有比试验和错误更好的方法(当然,即使它是近似的).

尝试在网络上找到解决方案时要搜索的任何特定关键字?

c# image-manipulation image image-processing image-resizing

10
推荐指数
3
解决办法
7132
查看次数

PHP GD调整透明图像的大小,给出黑色边框

我试图用PHP缩小PHP中的一些透明图像,每当我这样做时,周围都会添加一个奇怪的黑色边框.

之前 之前

在此输入图像描述

<?php
    $image = imagecreatefromstring(file_get_contents('logo.png'));
    $width = imagesx($image);
    $height = imagesy($image);

    $newWidth = $width - 1;
    $newHeight = $height - 1;
    $output = imagecreatetruecolor($newWidth, $newHeight);
    imagecolortransparent($output, imagecolorallocatealpha($output, 0, 0, 0, 127));
    imagealphablending($output, false);
    imagesavealpha($output, true);
    imagecopyresampled($output, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

    header('Content-Type: image/png');
    imagepng($output);
?>
Run Code Online (Sandbox Code Playgroud)

似乎如果我将新维度的代码更改为旧维度(删除- 1),则不会出现黑色边框.因此调整大小会导致问题.

有谁知道什么可能是错的?

编辑:我刚刚意识到它只发生在imagecopyresampled和不发生imagecopyresized.但是,imagecopyresampled提供了更好的视觉效果,如果可能的话我想让它工作.

php gd image-resizing

10
推荐指数
1
解决办法
2538
查看次数

根据UIView/CGRect的大小将图像裁剪为正方形

我有一个AVCaptureSession的实现,我的目标是让用户拍照并只保存红色方框边框内的图像部分,如下所示:

UIViewController与AVCaptureSession的实现

AVCaptureSession previewLayer(相机)从(0,0)(左上角)跨越到相机控制条的底部(包含快门的视图上方的条形图).我的导航栏和控制栏是半透明的,因此相机可以显示.

我正在使用[captureSession setSessionPreset:AVCaptureSessionPresetPhoto];以确保保存到相机胶卷的原始图像就像Apple的相机一样.

用户将能够以纵向,左右横向拍摄照片,因此裁剪方法必须考虑到这一点.

到目前为止,我已尝试使用此代码裁剪原始图像:

DDLogVerbose(@"%@: Image crop rect: (%f, %f, %f, %f)", THIS_FILE, self.imageCropRect.origin.x, self.imageCropRect.origin.y, self.imageCropRect.size.width, self.imageCropRect.size.height);

// Create new image context (retina safe)
UIGraphicsBeginImageContextWithOptions(CGSizeMake(self.imageCropRect.size.width, self.imageCropRect.size.width), NO, 0.0);

// Create rect for image
CGRect rect = self.imageCropRect;

// Draw the image into the rect
[self.captureManager.stillImage drawInRect:rect];

// Saving the image, ending image context
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
Run Code Online (Sandbox Code Playgroud)

然而,当我看到相机胶卷中的裁剪图像时,似乎它刚刚压缩了原始图像,而不是像我想的那样丢弃图像的顶部和底部.它还会在"裁剪"图像的顶部产生53像素的空白区域,这可能是因为我的y位置CGRect.

这是我的日志输出CGRect:

 Image crop rect: (0.000000, 53.000000, 320.000000, 322.000000)
Run Code Online (Sandbox Code Playgroud)

这也描述了superview中红色边框视图的框架.

我有什么关键吗? …

crop uiimage image-resizing ios cgrect

10
推荐指数
2
解决办法
9985
查看次数

创建可调整大小的视图,在 FLUTTER 中从角落和侧面捏合或拖动时调整大小

在此处输入图片说明

我目前正在开发一个 ScreenView,它具有可拖动和可调整大小的视图,如上图所示,带有角和边。我现在遇到的问题是我想通过角落里的触摸手势来调整视图的大小。因此,我想到了一个点,将其添加到选择视图中,可以拖动它来调整所选视图的大小。答案更新了!!

Resizable-Widget ReactNative Demo: React Native PLUGIN 示例

修改后的可行示例:

  import 'package:flutter/material.dart';

  class ResizeWidget extends StatefulWidget {
    @override
    _ResizeWidgetState createState() => _ResizeWidgetState();
  }

  class _ResizeWidgetState extends State<ResizeWidget> {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: Scaffold(
          backgroundColor: Colors.black,
          body: Container(
            // padding: EdgeInsets.only(top: 50),
            child: ResizebleWidget(
              child: Container(
                padding: EdgeInsets.all(10),
                child: Text(
                  'Waao!! you can really dance.',
                  style: TextStyle(
                      color: Colors.white,
                      fontStyle: FontStyle.italic,
                      fontSize: 18),
                ),
              ),
            ),
          ),
        ),
      );
    }
  }

  class ResizebleWidget extends StatefulWidget {
    ResizebleWidget({this.child}); …
Run Code Online (Sandbox Code Playgroud)

resize image-resizing window-resize flutter flutter-layout

10
推荐指数
1
解决办法
6488
查看次数

如何在调整图像大小时填充白色背景

目前的背景是黑色的.如何将颜色改为白色?

    #assuming the mime type is correct
    switch ($imgtype) {
        case 'image/jpeg':
            $source = imagecreatefromjpeg($source_image);
            break;
        case 'image/gif':
            $source = imagecreatefromgif($source_image);
            break;
        case 'image/png':
            $source = imagecreatefrompng($source_image);
            break;
        default:
            die('Invalid image type.');
    }

    #Figure out the dimensions of the image and the dimensions of the desired thumbnail
    $src_w = imagesx($source);
    $src_h = imagesy($source);


    #Do some math to figure out which way we'll need to crop the image
    #to get it proportional to the new size, then crop or adjust as …
Run Code Online (Sandbox Code Playgroud)

php gd resize-image image-resizing

9
推荐指数
1
解决办法
3万
查看次数

如何使用sorl-thumbnail调整源大小?

我正在网上搜索我的问题,但无论如何也找不到明确的答案者.

基本上,我想使用sorl并希望在模型保存时间内调整源图像的大小以将其大小调整为640x480大小,这样我就不会最终在磁盘上存储用户原始的2.5 MB文件.然后我将使用templatetags从我的源代码中创建常规缩略图,如sorl中所述.

我遇到了几个来源引用使用的ThumbnailField模型字段应该在sorl.thumbnail.fields中可用.请点击此处链接.但是,在我从主干中获取最新的sorl副本时,我看不到任何ThumbnailField或ImageWithThumbnailsField.我在模型中导入它的尝试失败了.我看到这些参考文献虽然陈旧但想知道我是否可以用最新的sorl实现相同的目标.

另一方面,sorl文档仅指示来自sorl.thumbnail(参见此处)的ImageField ,它没有任何大小参数来控制源大小调整.

顺便说一下,我看到easy_thumbnail提供了这个功能,它带有一个输入参数source_resize.

任何帮助将不胜感激!

摘要

我接受了下面的答案,但我觉得对这个用例的自然索引支持非常有用 - 即将resize_source参数添加到sorl的ImageField以允许调整源图像的大小.以下是为什么它在该领域有用的两个因素:

  1. 如果您的应用程序不需要它,则不要存储用户的巨大原始图像.节省磁盘空间.

  2. 如果您没有特定的极高质量原因,请不要花费额外的CPU来重新调整来自巨大源图像的缩略图.为了避免这种情况,可以将模板中的嵌套标签写入较小尺寸图像的缩略图中,但它很快就会变得烦人.

django thumbnails image-resizing sorl-thumbnail

9
推荐指数
2
解决办法
6015
查看次数

Gnuplot:在不调整绘图大小的情况下添加关键外部图

在gnuplot中,我可以使用此命令将键放在绘图外:

set key outside;
set key right top;
Run Code Online (Sandbox Code Playgroud)

但是,如此页面所示,键的放置将自动调整绘图区域的大小,使得生成的图像的大小保持不变.是否有一种简单的方法可以保持绘图区域相同,无论我将键放在绘图区域外的哪个位置?

plot gnuplot image-resizing

9
推荐指数
1
解决办法
2万
查看次数

问:我如何调整图像大小并保持其比例?

此Qt 示例显示如何调整对话框中包含的图像的大小,以便在调整对话框大小时,图像会相应地拉伸.

如何以相同的方式调整图像大小,而不会扭曲图像/保持其比例相同?

当然,如果对话框的宽高比与图像的宽高比不同,我会得到一个"灰色"区域.
我找到了Qt::KeepAspectRatio枚举,但没有使用它的功能.

更新:这是我正在尝试的代码:

QImage image(path);
QImage image2 = image.scaled(200, 200, Qt::KeepAspectRatio);
QLabel *plotImg = new QLabel;
plotImg->setScaledContents(true);
plotImg->setPixmap(QPixmap::fromImage(image2));
Run Code Online (Sandbox Code Playgroud)

调整标签大小时,图像不会保持恒定的宽高比.重新调整后它会失去解决方案.

c++ qt image image-resizing

9
推荐指数
1
解决办法
3万
查看次数

为什么OpenCV cv2.resize提供的答案不同于MATLAB imresize?

我正在将MATLAB代码传输到python并尝试使用OpenCV函数缩小图像cv2.resize,但是我得到了与MATLAB输出不同的结果.

为了确保我的代码在调整大小之前没有做错,我在两个函数上都使用了一个小例子并比较了输出.

我首先在Python和MATLAB中创建了以下数组并对其进行了上采样:

Python - NumPy和OpenCV

    x = cv2.resize(np.array([[1.,2],[3,4]]),(4,4), interpolation=cv2.INTER_LINEAR)
    print x

    [[ 1.    1.25  1.75  2.  ]
     [ 1.5   1.75  2.25  2.5 ]
     [ 2.5   2.75  3.25  3.5 ]
     [ 3.    3.25  3.75  4.  ]]
Run Code Online (Sandbox Code Playgroud)

MATLAB

    x = imresize([1,2;3,4],[4,4],'bilinear')

    ans =

    1.0000    1.2500    1.7500    2.0000
    1.5000    1.7500    2.2500    2.5000
    2.5000    2.7500    3.2500    3.5000
    3.0000    3.2500    3.7500    4.0000
Run Code Online (Sandbox Code Playgroud)

然后我拿出答案并将它们调整回原来的2x2大小.

蟒蛇:

    cv2.resize(x,(2,2), interpolation=cv2.INTER_LINEAR)

    ans = 

     [[ 1.375,  2.125],
      [ 2.875,  3.625]]
Run Code Online (Sandbox Code Playgroud)

MATLAB:

    imresize(x,[2,2],'bilinear')

    ans =

      1.5625    2.1875
      2.8125    3.4375 …
Run Code Online (Sandbox Code Playgroud)

matlab opencv numpy image-processing image-resizing

9
推荐指数
1
解决办法
5134
查看次数

调整文件系统中的JPEG图像大小

有没有办法调整JPEG图像文件(从文件系统到文件系统)而不删除元数据(就像ImageMagicks 一样convert in.jpg -resize 50% out.jpg)?

我发现我调整发现.jpg文件的唯一方法是BitmapFactory.decodeStreamBitmap.compress,它看起来像一个很大的开销,如果我需要手动传输图像元数据.

android jpeg image-resizing

9
推荐指数
1
解决办法
536
查看次数