LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

CalculateConvertSizeメソッド








入力イメージデータのピクセルの幅。
入力イメージデータのBitsPerPixel。
目的の出力画像データのピクセルの幅。
目的の出力画像データのBitsPerPixel。
出力バッファのために必要とされるサイズを計算します。
構文
public static int CalculateConvertSize( 
   int inWidth,
   int inBitsPerPixel,
   int outWidth,
   int outBitsPerPixel
)
'Declaration
 
Public Shared Function CalculateConvertSize( _
   ByVal inWidth As Integer, _
   ByVal inBitsPerPixel As Integer, _
   ByVal outWidth As Integer, _
   ByVal outBitsPerPixel As Integer _
) As Integer
'Usage
 
Dim inWidth As Integer
Dim inBitsPerPixel As Integer
Dim outWidth As Integer
Dim outBitsPerPixel As Integer
Dim value As Integer
 
value = RasterBufferConverter.CalculateConvertSize(inWidth, inBitsPerPixel, outWidth, outBitsPerPixel)
public static int CalculateConvertSize( 
   int inWidth,
   int inBitsPerPixel,
   int outWidth,
   int outBitsPerPixel
)
 function Leadtools.RasterBufferConverter.CalculateConvertSize( 
   inWidth ,
   inBitsPerPixel ,
   outWidth ,
   outBitsPerPixel 
)
public:
static int CalculateConvertSize( 
   int inWidth,
   int inBitsPerPixel,
   int outWidth,
   int outBitsPerPixel
) 

パラメーター

inWidthな
入力イメージデータのピクセルの幅。
inBitsPerPixel
入力イメージデータのBitsPerPixel。
outWidthな
目的の出力画像データのピクセルの幅。
outBitsPerPixel
目的の出力画像データのBitsPerPixel。

戻り値

必須の出力バッファのバイトのサイズ。
解説
imageデータ変換のために出力バッファの必須のサイズを計算するために、このメソッドを使います。
サンプル

このサンプルは24ビット/ピクセルでimageをロードして、4ビット/ピクセルで新しいimageを作成して、それから24ビット/ピクセルから4ビット/ピクセルにデータを変換するために、Convertメソッドを使います。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs

      
Public Sub CalculateConvertSizeExample()
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_4bits.bmp")

   ' Load the image, at 24 bit per pixel.
   Dim srcImage As RasterImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)
   Debug.Assert(srcImage.BitsPerPixel = 24)

   ' Create a new 4-bit image.
   Dim destImage As RasterImage = New RasterImage( _
                                  RasterMemoryFlags.Conventional, _
                                  srcImage.Width, _
                                  srcImage.Height, _
                                  4, _
                                  srcImage.Order, _
                                  srcImage.ViewPerspective, _
                                  srcImage.GetPalette(),
                                  IntPtr.Zero, _
                                  0)
   Debug.Assert(destImage.BitsPerPixel = 4)

   Dim bufferSize As Integer = RasterBufferConverter.CalculateConvertSize( _
      srcImage.Width, srcImage.BitsPerPixel, destImage.Width, destImage.BitsPerPixel)

   ' Allocate the buffer in unmanaged memory
   Dim buffer As IntPtr = Marshal.AllocHGlobal(bufferSize)

   ' Process each row from srcImage to destImage.
   srcImage.Access()
   destImage.Access()

   Dim i As Integer = 0
   Do While i < srcImage.Height
      srcImage.GetRow(i, buffer, srcImage.BytesPerLine)
      RasterBufferConverter.Convert(buffer, srcImage.Width, srcImage.BitsPerPixel, destImage.BitsPerPixel, srcImage.Order, _
                                    destImage.Order, Nothing, Nothing, 0, 8, 0, RasterConvertBufferFlags.None)
      destImage.SetRow(i, buffer, destImage.BytesPerLine)
      i += 1
   Loop

   destImage.Release()
   srcImage.Release()

   ' Save the destination image back to disk
   codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 4)

   ' Clean up
   Marshal.FreeHGlobal(buffer)
   srcImage.Dispose()
   destImage.Dispose()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;

      
public void CalculateConvertSizeExample()
{
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");
   string destFileName = Path.Combine(ImagesPath.Path, "Image1_4bits.bmp");
   using (RasterCodecs codecs = new RasterCodecs())
   {
      codecs.ThrowExceptionsOnInvalidImages = true;

      // Load the image, at 24 bit per pixel.
      RasterImage srcImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);
      Assert.IsNotNull(srcImage);
      Assert.IsTrue(srcImage.BitsPerPixel == 24);

      // Create a new 4-bit image.
      using (RasterImage destImage = new RasterImage(
         RasterMemoryFlags.Conventional,
         srcImage.Width,
         srcImage.Height,
         4,
         srcImage.Order,
         srcImage.ViewPerspective,
         srcImage.GetPalette(),
         IntPtr.Zero,
         0))
      {
         Assert.IsNotNull(destImage);
         Assert.IsTrue(destImage.BitsPerPixel == 4);

         int bufferSize = RasterBufferConverter.CalculateConvertSize(
            srcImage.Width,
            srcImage.BitsPerPixel,
            destImage.Width,
            destImage.BitsPerPixel);

         // Allocate the buffer in unmanaged memory
         IntPtr buffer = Marshal.AllocHGlobal(bufferSize);
         Assert.IsFalse(buffer == IntPtr.Zero);

         // Process each row from srcImage to destImage.
         srcImage.Access();
         destImage.Access();

         for (int i = 0; i < srcImage.Height; i++)
         {
            srcImage.GetRow(i, buffer, srcImage.BytesPerLine);
            RasterBufferConverter.Convert(
               buffer,
               srcImage.Width,
               srcImage.BitsPerPixel,
               destImage.BitsPerPixel,
               srcImage.Order,
               destImage.Order,
               null,
               null,
               0,
               8,
               0,
               RasterConvertBufferFlags.None);
            destImage.SetRow(i, buffer, destImage.BytesPerLine);
         }

         destImage.Release();
         srcImage.Release();

         // Save the destination image back to disk
         codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 4);

         // Clean up
         Marshal.FreeHGlobal(buffer);
      }
   }
}
using Leadtools;
using Leadtools.Codecs;

      
public async Task CalculateConvertSizeExample()
{
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName = @"Image1_4bits.bmp";

   // Load the image, at 24 bit per pixel.
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   ILeadStream loadStream = LeadStreamFactory.Create(loadFile);
   RasterImage srcImage = await codecs.LoadAsync(loadStream, 24, CodecsLoadByteOrder.Bgr, 1, 1);
   Assert.IsTrue(srcImage.BitsPerPixel == 24);

   // Create a new 4-bit image.
   RasterImage destImage = new RasterImage(
      RasterMemoryFlags.Conventional,
      srcImage.Width,
      srcImage.Height,
      4,
      srcImage.Order,
      srcImage.ViewPerspective,
      srcImage.GetPalette());
   Assert.IsTrue(destImage.BitsPerPixel == 4);

   int bufferSize = RasterBufferConverter.CalculateConvertSize(
      srcImage.Width,
      srcImage.BitsPerPixel,
      destImage.Width,
      destImage.BitsPerPixel);

   // Allocate the buffer in unmanaged memory
   IntPtr buffer = Marshal.AllocHGlobal(bufferSize);

   // Process each row from srcImage to destImage.
   srcImage.AccessData();
   destImage.AccessData();

   for(int i = 0; i < srcImage.Height; i++)
   {
      srcImage.GetRow(i, buffer, srcImage.BytesPerLine);
      RasterBufferConverter.Convert(
         buffer,
         srcImage.Width,
         srcImage.BitsPerPixel,
         destImage.BitsPerPixel,
         srcImage.Order,
         destImage.Order,
         null,
         null,
         0,
         8,
         0,
         RasterConvertBufferFlags.None);
      destImage.SetRow(i, buffer, destImage.BytesPerLine);
   }

   destImage.ReleaseData();
   srcImage.ReleaseData();

   // Save the destination image back to disk
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(destImage, saveStream, RasterImageFormat.Bmp, 4);

   // Clean up
   Marshal.FreeHGlobal(buffer);
   srcImage.Dispose();
   destImage.Dispose();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;

public void CalculateConvertSizeExample(RasterImage srcImage, Stream destStream)
{
   // srcImage should be 24 bits per pixel.
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   // Create a new 4-bit image.
   RasterImage destImage = new RasterImage(
      RasterMemoryFlags.Conventional,
      srcImage.Width,
      srcImage.Height,
      4,
      srcImage.Order,
      srcImage.ViewPerspective,
      srcImage.GetPalette(),
      null,
      0);
   Debug.Assert(destImage.BitsPerPixel == 4);

   int bufferSize = RasterBufferConverter.CalculateConvertSize(
      srcImage.Width,
      srcImage.BitsPerPixel,
      destImage.Width,
      destImage.BitsPerPixel);

   // Allocate the buffer
   byte[] buffer = new byte[bufferSize];

   // Process each row from srcImage to destImage.
   srcImage.Access();
   destImage.Access();

   for(int i = 0; i < srcImage.Height; i++)
   {
      srcImage.GetRow(i, buffer, 0, srcImage.BytesPerLine);
      RasterBufferConverter.Convert(
         buffer,
         0,
         srcImage.Width,
         srcImage.BitsPerPixel,
         destImage.BitsPerPixel,
         srcImage.Order,
         destImage.Order,
         null,
         null,
         0,
         8,
         0,
         RasterConvertBufferFlags.None);
      destImage.SetRow(i, buffer, 0, destImage.BytesPerLine);
   }

   destImage.Release();
   srcImage.Release();

   // Save the destination image back to disk
   codecs.Save(destImage, destStream, RasterImageFormat.Bmp, 4);

   // Clean up
   srcImage.Dispose();
   destImage.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs

Public Sub CalculateConvertSizeExample(ByVal srcImage As RasterImage, ByVal destStream As Stream)
   ' srcImage should be 24 bits per pixel.
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True
   ' Create a new 4-bit image.
   Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, 4, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), Nothing, 0)
   Debug.Assert(destImage.BitsPerPixel = 4)

   Dim bufferSize As Integer = RasterBufferConverter.CalculateConvertSize(srcImage.Width, srcImage.BitsPerPixel, destImage.Width, destImage.BitsPerPixel)

   ' Allocate the buffer
   Dim buffer As Byte() = New Byte(bufferSize - 1){}

   ' Process each row from srcImage to destImage.
   srcImage.Access()
   destImage.Access()

   Dim i As Integer = 0
   Do While i < srcImage.Height
      srcImage.GetRow(i, buffer, 0, srcImage.BytesPerLine)
      RasterBufferConverter.Convert(buffer, 0, srcImage.Width, srcImage.BitsPerPixel, destImage.BitsPerPixel, srcImage.Order, destImage.Order, Nothing, Nothing, 0, 8, 0, RasterConvertBufferFlags.None)
      destImage.SetRow(i, buffer, 0, destImage.BytesPerLine)
      i += 1
   Loop

   destImage.Release()
   srcImage.Release()

   ' Save the destination image back to disk
   codecs.Save(destImage, destStream, RasterImageFormat.Bmp, 4)

   ' Clean up
   srcImage.Dispose()
   destImage.Dispose()
End Sub
必要条件

ターゲットプラットホーム

参照

参照

RasterBufferConverterクラス
RasterBufferConverterメンバ