颤音:放大&放大堆栈中的图像

发布于 2025-02-10 08:03:21 字数 3105 浏览 2 评论 0原文

我正在使用一堆图像,并且在另一个图像上具有透明的图像,该图像可作为框架。现在,我想缩小并缩小后面图像。

我正在使用InteractiveViewer,它仅适用于前图。我需要为背部图像做同样的事情。

这是一个例子。

我想缩放大象图像,这是我在堆栈中的第一个元素。 这是我的代码。

body: Container(
        padding: EdgeInsets.all(12.0),
        margin: EdgeInsets.fromLTRB(0, 0, 0, 60),
        child: Center(
            child: Column(children: [
          Expanded(
            flex: 10,
            child: RepaintBoundary(
              key: scr,
              child: ClipRect(
                clipBehavior: Clip.hardEdge,
                child: Stack(
                  children: <Widget>[
                    Padding(
                      padding: const EdgeInsets.only(
                          left: 67.5, right: 67, top: 9, bottom: 9),
                      child: Column(
                        children:  <Widget>[
                          pikedFile == null ? Container(
                          ):InteractiveViewer(
                                panEnabled: false, // Set it to false
                                boundaryMargin: EdgeInsets.all(100),
                                minScale: 0.5,
                                maxScale: 2,
                                child: Image(image: FileImage(pikedFile!)) // Back Image
                              ),
                        ],
                      ),
                    ),
                    Center(
                      child: Image(image: AssetImage(getResource())), //Front Image
                    ),
                  ],
                ),
              ),
            ),
          ),
          Expanded(
              flex: 3,
              child: Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: TextButton.icon(
                      icon: const Icon(Icons.camera_alt), // Your icon here
                      label: const Text("Camera"), // Your text here
                      onPressed: () {
                        _openCamera();
                      },
                    ),
                  ),
                  Expanded(
                    flex: 1,
                    child: TextButton.icon(
                      icon: const Icon(Icons.photo), // Your icon here
                      label: const Text("Gallery"), // Your text here
                      onPressed: () {
                        _openGallery();
                      },
                    ),
                  ),
                  Expanded(
                    flex: 1,
                    child: TextButton.icon(
                      icon: const Icon(Icons.share_sharp), // Your icon here
                      label: const Text("Share"), // Your text here
                      onPressed: () {
                        _shareScreenShot();
                      },
                    ),
                  ),
                ],
              ))
        ])),
      ),

I am using stack of images and I have a transparent image over another image which works as a frame. Now I want to zoom in and zoom out the back image.

I am using InteractiveViewer, which is only working for front image only. I need to do same for back image.

Here is an example.
enter image description here

I want to zoom the elephant image, which is my first element in Stack.
Here is my code.

body: Container(
        padding: EdgeInsets.all(12.0),
        margin: EdgeInsets.fromLTRB(0, 0, 0, 60),
        child: Center(
            child: Column(children: [
          Expanded(
            flex: 10,
            child: RepaintBoundary(
              key: scr,
              child: ClipRect(
                clipBehavior: Clip.hardEdge,
                child: Stack(
                  children: <Widget>[
                    Padding(
                      padding: const EdgeInsets.only(
                          left: 67.5, right: 67, top: 9, bottom: 9),
                      child: Column(
                        children:  <Widget>[
                          pikedFile == null ? Container(
                          ):InteractiveViewer(
                                panEnabled: false, // Set it to false
                                boundaryMargin: EdgeInsets.all(100),
                                minScale: 0.5,
                                maxScale: 2,
                                child: Image(image: FileImage(pikedFile!)) // Back Image
                              ),
                        ],
                      ),
                    ),
                    Center(
                      child: Image(image: AssetImage(getResource())), //Front Image
                    ),
                  ],
                ),
              ),
            ),
          ),
          Expanded(
              flex: 3,
              child: Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: TextButton.icon(
                      icon: const Icon(Icons.camera_alt), // Your icon here
                      label: const Text("Camera"), // Your text here
                      onPressed: () {
                        _openCamera();
                      },
                    ),
                  ),
                  Expanded(
                    flex: 1,
                    child: TextButton.icon(
                      icon: const Icon(Icons.photo), // Your icon here
                      label: const Text("Gallery"), // Your text here
                      onPressed: () {
                        _openGallery();
                      },
                    ),
                  ),
                  Expanded(
                    flex: 1,
                    child: TextButton.icon(
                      icon: const Icon(Icons.share_sharp), // Your icon here
                      label: const Text("Share"), // Your text here
                      onPressed: () {
                        _shareScreenShot();
                      },
                    ),
                  ),
                ],
              ))
        ])),
      ),

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

骄傲 2025-02-17 08:03:21

根据我的理解
您想与堆栈中的底部小部件进行交互,如果是这种情况,则忽略指针可以为您提供帮助。

只需将上面的小部件用像这样的忽略堆栈中的堆栈中。

Stack(
children:[
  Container(color:Colors.red) // this is where you want to interact and 
                            //this containerbottom of the stack.
  IgnorePointer(
          ignoring: true,
          Container(color:Colors.blue)// top container
   )
 ])

As per my understanding
You want to interact with the bottom widget in the stack, if this is the case then Ignore pointer can help you.

Just wrap the above widgets in the stack with IgnorePointer just like this.

Stack(
children:[
  Container(color:Colors.red) // this is where you want to interact and 
                            //this containerbottom of the stack.
  IgnorePointer(
          ignoring: true,
          Container(color:Colors.blue)// top container
   )
 ])
送舟行 2025-02-17 08:03:21

尝试用InteractiveViewer小部件将堆栈小部件包装。

 InteractiveViewer(
   child:Stack(), 
           )

try wrapping the stack widget with the InteractiveViewer widget.

 InteractiveViewer(
   child:Stack(), 
           )
季末如歌 2025-02-17 08:03:21

除了使用 ignorepointer 忽略与图像的互动和底部帧将更好地显示在多个设备屏幕上(甚至在肖像和景观模式上)。您可以使用定位将2张图像放在顶级右上和左下。

查看 nofollow noreferrer“ 。

例如,使用下面的裁剪框架:

左上框架底部右框架
”“

结果是:

Zoom-Injuarm缩放
肖像​/I.SSTATIC.NET/PIQKQ.JPG“ alt =“ formal Protait”>
景观““正常景观”https://i.sstatic.net/trv0y.png“ rel =” nofollow noreferrer“>

Besides using IgnorePointer to ignore interaction with the image, cropping both the top and bottom frames would be better for displaying on multiple device screens (and even on portrait and landscape mode). You can use Positioned to place the 2 images on the top-right and bottom-left.

Check out the live demo on DartPad (Use the mouse wheel to zoom-in/zoom-out).

For example, using the cropped frames below:

Top-left frameBottom-Right frame
Top-left frameBottom-right frame

The result is the following:

Zoom-inNormalZoom-out
PortraitZoom-in portraitNormal portraitZoom-out portrait
LandscapeZoom-in landscapeNormal landscapeZoom-out landscape
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文