且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从帧缓冲区字节有效地制作裁剪的位图图像。

更新时间:2023-11-13 09:28:04


问题,当然,是"裁剪"的未初始化 - 例如,它不知道像素格式,因此它甚至无法判断每个像素的字节数。  这些值是只读的;使用"cropped.BeginInit()"不允许你设置

The problem, of course, is "cropped" is not initialized - it doesn't know the pixel format, for example, so it can't even tell how many bytes per pixel.  These values are read-only; using "cropped.BeginInit()" does not allow you to set them.

如果你继承CroppedBitmap并创建一个不需要源的自定义构造函数,那么您可以在初始化期间(Source对象)访问CroppedBitmap基础,并且可以调用
创建 ()在该实例上,传入必需的参数(您将包含在自定义构造函数签名中)。无论是否提高性能,都必须通过实验来确定
。我没有使用过这两个类,但它看起来大致如下:

If you subclass CroppedBitmap and create a custom constructor that does not require a source, then you have access to the CroppedBitmap base during initialisation (a Source object) and you could call .Create() on that instance, passing in the required parameters (which you would include in your custom constructor signature). Whether that improves the performance or not would have to be determined by experiment. I haven't used either of those classes, but it would look roughly like:

Public Class MyCroppedBitmap(Int32, Int32, Double, Double, PixelFormat, BitmapPalette, IntPtr, Int32, Int32, Int32Rect)
    Inherits CroppedBitmap
    MyBase.Create(Int32, Int32, Double, Double, PixelFormat, BitmapPalette, IntPtr, Int32, Int32)
    SourceRect = Int32Rect
End Class