←Select platform

Netscape Method

Summary
Creates an array of RasterColor objects that represent the Netscape Fixed palette.
Syntax
C#
C++/CLI
Java
Python
public static RasterColor[] Netscape() 
public static RasterColor[] netscape(); 
public: 
static array<RasterColor>^ Netscape();  
def Netscape(self): 
Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
 
 
public void NetscapePaletteExample() 
{ 
	string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
	string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Netscape.bmp"); 
 
	RasterCodecs codecs = new RasterCodecs(); 
	codecs.ThrowExceptionsOnInvalidImages = true; 
 
	// Load the source image as 8 bits/pixel 
	RasterImage srcImage = codecs.Load(srcFileName, 8, CodecsLoadByteOrder.Rgb, 1, 1); 
 
	// Get the netscape palette 
	RasterColor[] netscapePalette = RasterPalette.Netscape(); 
 
	// Create the new palletized image. 
	RasterImage destImage = new RasterImage( 
	   RasterMemoryFlags.Conventional, 
	   srcImage.Width, 
	   srcImage.Height, 
	   8, 
	   srcImage.Order, 
	   srcImage.ViewPerspective, 
	   netscapePalette, 
	   IntPtr.Zero, 
	   0); 
 
	// Set the dithering method. 
	srcImage.DitheringMethod = RasterDitheringMethod.StevensonArce; 
 
	srcImage.Access(); 
	destImage.Access(); 
 
	// Initialize the dithering process. 
	srcImage.StartDithering(netscapePalette, 256); 
 
	// Allocate the output buffer for 8-bit data. 
	byte[] inBuffer = new byte[srcImage.Width * 3];  // Buffer to hold the input row. 
	byte[] outBuffer = new byte[srcImage.Width];      // Buffer to hold the output row. 
 
	// Use DitherLine method to process each row in the image. 
	for (int i = 0; i < srcImage.Height; i++) 
	{ 
		srcImage.GetRow(i, inBuffer, 0, srcImage.BytesPerLine); 
		srcImage.DitherLine(inBuffer, 0, outBuffer, 0); 
		destImage.SetRow(i, outBuffer, 0, destImage.BytesPerLine); 
	} 
 
	// End the dithering process. 
	srcImage.StopDithering(); 
 
	destImage.Release(); 
	srcImage.Release(); 
 
	// Save the destination image 
	codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 8); 
 
	// Cleanup 
	srcImage.Dispose(); 
	destImage.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.codecs.*; 
 
 
public void netscapePaletteExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp"); 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1_Netscape.bmp"); 
 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.setThrowExceptionsOnInvalidImages(true); 
 
   // Load the source image as 8 bits/pixel 
   RasterImage srcImage = codecs.load(srcFileName, 8, CodecsLoadByteOrder.RGB, 1, 1); 
 
   // Get the netscape palette 
   RasterColor[] netscapePalette = RasterPalette.netscape(); 
 
   // Create the new palletized image 
   RasterImage destImage = new RasterImage( 
         RasterMemoryFlags.CONVENTIONAL.getValue(), 
         srcImage.getWidth(), 
         srcImage.getHeight(), 
         8, 
         srcImage.getOrder(), 
         srcImage.getViewPerspective(), 
         netscapePalette, 
         new byte[0], 
         0); 
 
   // Set the dithering method 
   srcImage.setDitheringMethod(RasterDitheringMethod.STEVENSON_ARCE); 
 
   srcImage.access(); 
   destImage.access(); 
 
   // Initialize the dithering process 
   srcImage.startDithering(netscapePalette, 256); 
 
   // Allocate the output buffer for 8-bit data. 
   byte[] inBuffer = new byte[srcImage.getWidth()]; // Buffer to hold the input row. 
   byte[] outBuffer = new byte[srcImage.getWidth()]; // Buffer to hold the output row. 
 
   // Use DitherLine method to process each row in the image. 
   for (int i = 0; i < srcImage.getHeight(); i++) { 
      srcImage.getRow(i, inBuffer, 0, srcImage.getBytesPerLine()); 
      srcImage.ditherLine(inBuffer, 0, outBuffer, 0); 
      destImage.setRow(i, outBuffer, 0, destImage.getBytesPerLine()); 
   } 
 
   // End the dithering process 
   srcImage.stopDithering(); 
 
   destImage.release(); 
   srcImage.release(); 
 
   // Save the destination image 
   codecs.save(destImage, destFileName, RasterImageFormat.BMP, 8); 
   assertTrue("Image unsuccessfully saved", new File(destFileName).exists()); 
   System.out.printf("Command ran successfully, image saved to %s\n", destFileName); 
 
   // Cleanup 
   srcImage.dispose(); 
   destImage.dispose(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.5.22
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.