LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

RasterBufferConverterクラス








メンバ 
サポートをimageデータバッファを変換するために提供します。
オブジェクトモデル
構文
public static class RasterBufferConverter 
'Declaration
 
Public MustInherit NotInheritable Class RasterBufferConverter 
'Usage
 
Dim instance As RasterBufferConverter
public sealed static class RasterBufferConverter 
function Leadtools.RasterBufferConverter()
public ref class RasterBufferConverter abstract sealed 
サンプル

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

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs

      
Public Sub RasterBufferConverterExample()
   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_16bits.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)

   Dim buffer As Byte() = New Byte(srcImage.BytesPerLine - 1) {}

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

   Debug.Assert(destImage.BitsPerPixel = 16)

   ' Process each row from src to dest image
   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)

      destImage.SetRow(i, buffer, 0, destImage.BytesPerLine)
      i += 1
   Loop

   destImage.Release()
   srcImage.Release()

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

   ' Clean up
   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 RasterBufferConverterExample()
{
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");
   string destFileName = Path.Combine(ImagesPath.Path, "Image1_16bits.bmp");
   using (RasterCodecs codecs = new RasterCodecs())
   {
      codecs.ThrowExceptionsOnInvalidImages = true;

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

         // Create a new 16-bit image.
         using (RasterImage destImage = new RasterImage(
            RasterMemoryFlags.Conventional,
            srcImage.Width,
            srcImage.Height,
            16,
            srcImage.Order,
            srcImage.ViewPerspective,
            srcImage.GetPalette(),
            IntPtr.Zero,
            0))
         {

            Assert.IsNotNull(destImage);
            Assert.IsTrue(destImage.BitsPerPixel == 16);

            // Create a buffer large enough to hold one row at a time.
            byte[] buffer = new byte[srcImage.BytesPerLine];

            // Process each row from src to dest image
            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);

               destImage.SetRow(i, buffer, 0, destImage.BytesPerLine);
            }

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

            // Save the destination image back to disk
            codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 16);
         }
      }
   }
}
using Leadtools;
using Leadtools.Codecs;

      
public async Task RasterBufferConverterExample()
{
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   string srcFileName =  @"Assets\Image1.cmp"; 
   string destFileName = @"Image1_16bits.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);

   Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer((uint)srcImage.BytesPerLine);

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

   Assert.IsTrue(destImage.BitsPerPixel == 16);

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

   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);

      destImage.SetRow(i, buffer, 0, 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, 16);

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

public void RasterBufferConverterExample(RasterImage srcImage, Stream destStream)
{
   // srcImage should be 24 bits per pixel.
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   // Load the image, at 24 bit per pixel.
   Debug.Assert(srcImage.BitsPerPixel == 24);

   byte[] buffer  = new byte[srcImage.BytesPerLine];

   // Create a new 16-bit image.
   RasterImage destImage = new RasterImage(
      RasterMemoryFlags.Conventional,
      srcImage.Width,
      srcImage.Height,
      16,
      srcImage.Order,
      srcImage.ViewPerspective,
      srcImage.GetPalette(),
      null,
      0);

   Debug.Assert(destImage.BitsPerPixel == 16);

   // Process each row from src to dest image
   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);

      destImage.SetRow(i, buffer, 0, destImage.BytesPerLine);
   }

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

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

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

Public Sub RasterBufferConverterExample(ByVal srcImage As RasterImage, ByVal destStream As Stream)
   ' srcImage should be 24 bits per pixel.
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True
   ' Load the image, at 24 bit per pixel.
   Debug.Assert(srcImage.BitsPerPixel = 24)

   Dim buffer As Byte() = New Byte(srcImage.BytesPerLine - 1){}

   ' Create a new 16-bit image.
   Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, 16, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), Nothing, 0)

   Debug.Assert(destImage.BitsPerPixel = 16)

   ' Process each row from src to dest image
   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)

      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, 16)

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

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

参照

参照

RasterBufferConverterメンバ
Leadtools名前空間