LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

SetUserDataメソッド








image新しいデータを格納しているアンマネージドメモリバッファーへのポインター。
データのバイトの数
指定されたアンマネージドメモリバッファーへのimageのデータを設定します。
構文
public void SetUserData( 
   IntPtr data,
   long size
)
'Declaration
 
Public Sub SetUserData( _
   ByVal data As IntPtr, _
   ByVal size As Long _
) 
'Usage
 
Dim instance As RasterImage
Dim data As IntPtr
Dim size As Long
 
instance.SetUserData(data, size)
public void SetUserData( 
   IntPtr data,
   long size
)
- (BOOL)setUserData:(nullable unsigned char *)userData
       userDataSize:(unsigned long)userDataSize
              error:(NSError **)error
            
public void setUserData(
  byte data[], 
  long size
)
            
 function Leadtools.RasterImage.SetUserData( 
   data ,
   size 
)
public:
void SetUserData( 
   IntPtr data,
   int64 size
) 

パラメーター

データ
image新しいデータを格納しているアンマネージドメモリバッファーへのポインター。
サイズ
データのバイトの数
解説

指定するデータは、コピーされないで、imageによって、imageが破棄されるまで、または、再びこのメソッドを呼び出すまで、代わりにリファレンスをつけられます。

アンマネージ利用者データでRasterImageオブジェクトを準備するために、フラグパラメーターにRasterMemoryFlags.Userを渡している#ctorコンストラクタを呼び出します。

若干の画像処理コマンド(例えばRotateCommandColorResolutionCommand)は、画像データを再配分する必要があります。RasterMemoryFlags.Userでimageを作成して、これらのコマンドにそれを渡すならば、RasterMemoryFlags.Conventionalにimageを変更して、メモリを再配分します。オリジナルのメモリが、もはや使われません。

画像データを管理する役割を果たします。無料でない遺書を破棄しますデータ

サンプル

このサンプルは、特定のピクセルのためにRとG値を入れ替えるために、GetPixelDataとSetPixelDataメソッドを使います。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Controls
Imports Leadtools.Dicom
Imports Leadtools.Drawing
Imports Leadtools.Svg

      
Public Sub SetUserDataExample()
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "UserData.bmp")

   ' Create an image with user defined data
   Dim width As Integer = 40
   Dim height As Integer = 40
   Dim bitsPerPixel As Integer = 24
   Dim size As Integer = width * height * 3
   Dim data1 As IntPtr = Marshal.AllocHGlobal(size)

   ' Load the image
   Dim image As RasterImage = New RasterImage(RasterMemoryFlags.User, width, height, bitsPerPixel, RasterByteOrder.Bgr, _
                                              RasterViewPerspective.TopLeft, Nothing, IntPtr.Zero, 0)

   ' Get a pointer to the internal data and fill it with gray shades
   Dim dataSize As Integer = CInt(image.DataSize)

   Dim buffer As Byte() = New Byte(dataSize - 1) {}
   Dim inc As Boolean = True
   Dim value As Byte = 0
   Dim i As Integer = 0
   Do While i < buffer.Length
      buffer(i + 0) = value
      buffer(i + 1) = value
      buffer(i + 2) = value

      If inc Then
         If value = 255 Then
            inc = False
            value = 254
         Else
            value = value + Convert.ToByte(1)
         End If
      Else
         If value = 0 Then
            inc = True
            value = 1
         Else
            value = value - Convert.ToByte(1)
         End If
      End If
      i += 3
   Loop

   ' Copy this buffer to the image data
   Marshal.Copy(buffer, 0, data1, buffer.Length)

   ' Set the user data
   image.SetUserData(data1, dataSize)

   ' Save the image
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24)

   image.Dispose()
   Marshal.FreeHGlobal(data1)
   codecs.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;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;
using Leadtools.Drawing;
using Leadtools.Controls;
using Leadtools.Svg;

      
public void SetUserDataExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string destFileName = Path.Combine(ImagesPath.Path, "UserData.bmp");

   // Create an image with user defined data
   int width = 40;
   int height = 40;
   int bitsPerPixel = 24;
   int size = width * height * 3;
   IntPtr data1 = Marshal.AllocHGlobal(size);

   // Load the image
   RasterImage image = new RasterImage(
      RasterMemoryFlags.User,
      width,
      height,
      bitsPerPixel,
      RasterByteOrder.Bgr,
      RasterViewPerspective.TopLeft,
      null,
      IntPtr.Zero,
      0);

   // Get a pointer to the internal data and fill it with gray shades
   long dataSize = image.DataSize;

   byte[] buffer = new byte[dataSize];
   bool inc = true;
   byte value = 0;
   for(int i = 0; i < buffer.Length; i += 3)
   {
      buffer[i + 0] = value;
      buffer[i + 1] = value;
      buffer[i + 2] = value;

      if(inc)
      {
         if(value == 255)
         {
            inc = false;
            value = 254;
         }
         else
            value++;
      }
      else
      {
         if(value == 0)
         {
            inc = true;
            value = 1;
         }
         else
            value--;
      }
   }

   // Copy this buffer to the image data
   Marshal.Copy(buffer, 0, data1, buffer.Length);

   // Set the user data
   image.SetUserData(data1, dataSize);

   // Save the image
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24);

   image.Dispose();
   Marshal.FreeHGlobal(data1);
   codecs.Dispose();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Dicom;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Examples;
using Leadtools.Windows.Media;

public void SetUserDataExample(Stream destStream)
{
   // Create an image with user defined data
   int width = 40;
   int height = 40;
   int bitsPerPixel = 24;
   // Create a user image
   RasterImage image = new RasterImage(
      RasterMemoryFlags.User,
      width,
      height,
      bitsPerPixel,
      RasterByteOrder.Bgr,
      RasterViewPerspective.TopLeft,
      null,
      null,
      0);

   // Create a data buffer for the image data
   // and fill the pixel values (gradient)
   int size = width * height * 3;
   byte[] buffer = new byte[size];

   bool inc = true;
   byte value = 0;
   for (int i = 0; i < buffer.Length; i += 3)
   {
      buffer[i + 0] = value;
      buffer[i + 1] = value;
      buffer[i + 2] = value;

      if (inc)
      {
         if (value == 255)
         {
            inc = false;
            value = 254;
         }
         else
            value++;
      }
      else
      {
         if (value == 0)
         {
            inc = true;
            value = 1;
         }
         else
            value--;
      }
   }

   // Set the user data of the image
   image.CopyData(buffer, buffer.Length);

   // Save the image
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, destStream, RasterImageFormat.Bmp, 24);

   image.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Dicom
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media

Public Sub SetUserDataExample(ByVal destStream As Stream)
   ' Create an image with user defined data
   Dim width As Integer = 40
   Dim height As Integer = 40
   Dim bitsPerPixel As Integer = 24
   ' Create a user image
   Dim image As RasterImage = New RasterImage(RasterMemoryFlags.User, width, height, bitsPerPixel, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, Nothing, Nothing, 0)

   ' Create a data buffer for the image data
   ' and fill the pixel values (gradient)
   Dim size As Integer = width * height * 3
   Dim buffer As Byte() = New Byte(size - 1){}

   Dim inc As Boolean = True
   Dim value As Byte = 0
   Dim i As Integer = 0
   Do While i < buffer.Length
      buffer(i + 0) = value
      buffer(i + 1) = value
      buffer(i + 2) = value

      If inc Then
         If value = 255 Then
            inc = False
            value = 254
         Else
            value += 1
         End If
      Else
         If value = 0 Then
            inc = True
            value = 1
         Else
            value -= 1
         End If
      End If
      i += 3
   Loop

   ' Set the user data of the image
   image.CopyData(buffer, buffer.Length)

   ' Save the image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, destStream, RasterImageFormat.Bmp, 24)

   image.Dispose()
End Sub
必要条件

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

参照

参照

RasterImageクラス
RasterImageメンバ