Differences Between GDI And WPF (from http://www.leadtools.com)

BasicConcepts    

The Windows Presentation Foundation (WPF) is fundamentally different from the Graphics Device Interface (GDI) and GDI+, requiring that many aspects of programming be approached in a different way. This topic briefly outlines the major differences.

Windows

Applications built using the GDI/GDI+ API use many windows, and reside under a parent window (MDI). Applications built in WPF have one window.

Unit of Measure

Applications built with a GDI/GDI+ API use the hardware pixel as the unit of measure. In these applications, as the resolution of the display device increases, the resulting image decreases. Applications built in WPF use the device-independent unit (1/96-inch) as the unit of measure. When the DPI of the system is 96, the two are equivalent.

Control Positioning

Applications built with GDI+ use absolute positioning. When the parent is resized the child elements do not get resized along with it. Applications built in WPF can use absolute, dynamic or data-bound positioning. With either absolute or dynamic positioning the controls are positioned relative to the parent element.

Image Basis

Images formed in GDI/GDI+ are pixel-based, raster images. Those formed in WPF can be scaleable, vector images.

Rendering Engine

Both GDI and GDI+ are built on Win32. GDI is based on the concept of a device context, where applications obtain handles to the device context, and use the handles in order to interact with the device. GDI+ is a wrapper around GDI that creates a C++ Graphics object. WPF, on the other hand, is built on DirectX which means that it can take advantage of hardware acceleration when performing its drawing operations.

Rendering Mode

With GDI and GDI+, rendering uses immediate rendering: the application repaints the area that becomes invalidated. In WPF, rendering uses retained rendering: the application keeps track of the drawing information but the system performs the painting.

Painting

With GDI and GDI+, clipping is used to determine the bounds of the area that has become invalidated and needs to be painted. In WPF, painting is performed from back to front and components paint over each other.

Pens and Brushes

GDI and GDI+ use the concept of a current brush and a current pen. In WPF, the brush and pen must be passed with each drawing call.

Paint Region Optimization

Paint region optimization is an important part of painting with GDI or GDI+. In WPF it is not considered.

Events

GDI and GDI+ use events and eventhandler delegates using subscription/notification. WPF uses bubbling, tunneling, and direct event notification, and the event travels up and down the VisualTree.

Video and Audio

Direct support for video and audio is not provided by GDI+ or Windows Forms, but must be obtained through a media player like Windows Media Player. WPF supports video and audio directly.

The following table summarizes these differences in rendering:

FeatureWindows Forms (using GDI/GDI+)WPF
DLLs usedSystem.dll
System.Drawing.dll
System.Windows.Forms.dll
WindowsBase.dll
PresentationCore.dll
PresentationFoundation.dll
WindowsMany windowsOne window
UnitsHardware pixelsDevice-independent unit (1/96-inch)
Control positioningAbsoluteAbsolute, Dynamic, Data-bound
Image is formed byClosely spaced rows of dots (raster-based)Mathematical equations (vector-based)
Rendering engineDirectShowDirectX (Direct3D) Media Foundation
ModeImmediate - the application repaints the area that becomes invalidatedRetained - the application keeps the drawing information and the system does the repainting
PaintingClipping: bounds determined and painting occurs thereRendering performed from back to front: components paint over each other
Pen and brushCurrent pen and current brushAppropriate pen or brush provided with each drawing call
Painting regionMinimize the region to be paintedDo not need to minimize
EventsEventsRoutedEvents
Video and AudioRequires a player like Windows Media PlayerBuilt-in support

The Windows Presentation Foundation (WPF) is different from the Graphics Device Interface (GDI) and GDI+ APIs in two major areas: as a renderer, and as a framework.

As a renderer, WPF enables you to use:

  • Animations - animate properties with WPF's built-in support for timing and screen repainting.
  • Gradients - blend colors along an axis to add highlights, shadows and 3D effects.
  • Antialiasing - improve the look of diagonals and curves by antialiasing.
  • Scalability - scale the entire user interface instead of individual drawings.
  • Translucency - increase useable screen area by employing translucency.
  • Device independence - using device independent units means that WPF applications will scale automatically to the dpi being used by the system.

 

As a framework, WPF enables you to use:

  • XAML - eliminate creating mock-ups in Visio or PowerPoint. Using XAML it is possible to create the user-interface for an application directly so it is ready to be coded with the business logic.
  • Styles and templates - use styles on any UI element to maintain visual consistency.
  • Data binding - bind elements so they can present or interact with data.
  • A tool to localize your application - although with Windows Forms it is possible to use either Winres.exe or Visual Studio .NET to localize a form, in WPF you can use the LocBaml tool.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是将IterativeContractionAndMerging库中的ICM.m文件的全部MATLAB代码转换为Python的代码: ``` import numpy as np from scipy import ndimage def ICM(im, num_iter=10, min_region_size=10, merge_criterion=0.5): """ Iterative Contraction and Merging algorithm for image segmentation. Args: im (numpy.ndarray): Input image to be segmented. num_iter (int): Number of iterations to run the algorithm. min_region_size (int): Minimum region size for stopping the merging process. merge_criterion (float): Threshold for merging regions based on the similarity measure. Returns: numpy.ndarray: Segmented image. Raises: TypeError: If the input image is not a numpy array. ValueError: If the number of iterations or minimum region size is not a positive integer. """ # Check input arguments if not isinstance(im, np.ndarray): raise TypeError("Input image must be a numpy array.") if not isinstance(num_iter, int) or num_iter <= 0: raise ValueError("Number of iterations must be a positive integer.") if not isinstance(min_region_size, int) or min_region_size <= 0: raise ValueError("Minimum region size must be a positive integer.") # Initialize segmentation labels labels = np.zeros(im.shape, dtype=np.int32) label_count = 0 # Initialize similarity matrix sim_mat = np.zeros((1, label_count), dtype=np.float64) # Run ICM algorithm for specified number of iterations for i in range(num_iter): # Find all connected components in the binary image cc = ndimage.label(labels == 0)[0] if cc.max() == 0: # No connected components found, stop the algorithm break # Merge regions based on similarity criterion for j in range(1, cc.max() + 1): # Extract region j from the image region = (cc == j).astype(np.uint8) # Compute similarity measure between region and existing labels sim_vec = np.zeros((1, label_count), dtype=np.float64) for k in range(label_count): # Compute similarity using sum of absolute differences sim_vec[0, k] = np.sum(np.abs(im[labels == k] - im[cc == j])) # Check if any existing label is similar to the region if sim_vec.max() >= merge_criterion * region.sum(): # Merge region with most similar label labels[cc == j] = sim_vec.argmax() else: # Create new label for the region label_count += 1 labels[cc == j] = label_count sim_mat = np.append(sim_mat, sim_vec, axis=0) # Remove small regions for k in range(1, label_count + 1): if np.sum(labels == k) < min_region_size: labels[labels == k] = 0 sim_mat = np.delete(sim_mat, k, axis=1) label_count -= 1 return labels ``` 请注意,该转换可能需要根据您的用例进行微调。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值