放大图片铺满屏幕代码片段

                // 获取屏幕宽高
                DisplayMetrics displayMetrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

                BitmapDrawable bitmapDrawable = (BitmapDrawable) iv_image.getDrawable();
                final Bitmap bitmap = bitmapDrawable.getBitmap();

                int bitmapWidth = bitmap.getWidth();
                int bitmapHeight = bitmap.getHeight();
                int w = displayMetrics.widthPixels;
                int h = displayMetrics.heightPixels;
                Log.d("Standard", "w: " + w + ",h: " + h);
                scaleWidth = ((float) w) / bitmapWidth;
                scaleHeight = ((float) h) / bitmapHeight;
                Log.d("Standard", "scaleWidth: " + w + ",scaleHeight: " + h);

                iv_image.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Matrix matrix = new Matrix();
                        matrix.postScale(scaleWidth, scaleHeight);

                        Bitmap newBitmap = Bitmap.createBitmap(bitmap,
                                0, 0,
                                bitmap.getWidth(), bitmap.getHeight(),
                                matrix, true);
                        iv_image.setImageBitmap(newBitmap);
                    }
                });
``` #pragma once #include "esvtkgenericwidgets_global.h" #include <QWidget> #include <QResizeEvent> #include <QShowEvent> #include "QVTKOpenGLNativeWidget.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h" #include "vtkCornerAnnotation.h" #include "vtkEventQtSlotConnect.h" #include "vtkImageData.h" #include "vtkLegendScaleActor.h" extern ESVTKGENERICWIDGETS_EXPORT QString Global_VTK_TextFontFilePath; class esLoupeBrowser; class ESVTKGENERICWIDGETS_EXPORT esVTKWidgetBase : public QWidget { Q_OBJECT public: enum class WindowFillType//注意:windowSize需要在窗口展示后才有值 { NoFill=-1, //不铺满 FillMin,//自适应长宽中小的 FillMax,//自适应长宽中大的 FillHeight,//高铺满 FillWidth//宽铺满 }; esVTKWidgetBase(QWidget *parent=NULL); ~esVTKWidgetBase(); QVTKOpenGLNativeWidget*GetVtkWidget(); virtual void SetCustomWinId(int customWinId); virtual int GetCustomWinId(); protected: //bool eventFilter(QObject *watched, QEvent *event); virtual void showEvent(QShowEvent *) override; /*********************************************************************** //基础信息 ***********************************************************************/ public: virtual void UpdateShow(); virtual void ClearShow(); virtual void ResetCamera(WindowFillType fillType= WindowFillType::FillMin) = 0; vtkRenderWindow*GetRenderWindow(); vtkRenderWindowInteractor* GetInteractor(); vtkRenderer*GetRender(); //vtkRenderer*GetBackRender(); bool GetWidgetActiveFlag(); bool GetIsShowFlag(); void SetInteractorStyle(vtkInteractorObserver*style); private slots: void WidgetActive_Slot(); private: void InitBase(); /*********************************************************************** //边角信息 ***********************************************************************/ public: void SetAnnotationVisibility(bool flag); bool GetAnnotationVisibility(); void SetAnnotationText(int i, QString text); QString GetAnnotationText(int i); void SetAnnotationFontFilePath(QString path); virtual void SetSliceOrienInfoVisibility(bool flag); private: void InitCornerInfo(); /*********************************************************************** //放大镜 ***********************************************************************/ public: void SetLoupeBrowserEnabled(bool flag); void SetLoupeBrowserSize(int width, int height); void SetLoupeBrowserScaleRatio(double x,double y); private: void InitLoupeBrowser(); /*********************************************************************** //截图 ***********************************************************************/ public: static vtkImageData*ScreenShot(vtkRenderWindow*renderWindow); static void ScreenShot(vtkRenderWindow*renderWindow, QString filePath); /*********************************************************************** //比例尺 ***********************************************************************/ public: void SetLegendScaleVisibility(bool flag); bool GetLegendScaleVisibility(); private: void InitLegendScale(); protected: vtkLegendScaleActor* m_legendScaleActor; /*********************************************************************** //缩放比例 ***********************************************************************/ public: static double GetFillWindowScale(vtkCamera*camera,int sliceOrien, int dims[3], int windowSize[2], double spacing[3], WindowFillType fillType); static void GetPlaneAxisId(int sliceOrien, int planeAxisId[2]);//0:[1,2] 1:[0,2] 2:[0,1] //double GetScale(); signals: void mouseEvent(QMouseEvent* event); void WidgetActive_Signal(); protected: int m_customWinId; vtkRenderer*m_render; //vtkRenderer*m_backrender; QVTKOpenGLNativeWidget*m_vtkWidget; vtkCornerAnnotation*m_cornerAnnotation; vtkEventQtSlotConnect*m_slotConnect; bool m_widgetActiveFlag; bool m_IsShowFlag; esLoupeBrowser*m_loupeBrowser; vtkInteractorObserver*m_interactorStyle; bool m_resetCameraLater; WindowFillType m_resetCameraFillType; };```帮我分析一下这段代码
最新发布
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值