Free Support Forum - aspose.com

Barcode image size not working

I try save image with size 259*151. But its save with other size
using (var generator = new BarcodeGenerator(EncodeTypes.Code128))
{
generator.CodeText = sh;
generator.Parameters.CaptionAbove.Visible = true;
generator.Parameters.CaptionBelow.Visible = true;
generator.Parameters.CaptionAbove.Text = naim;
generator.Parameters.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.None;
generator.Parameters.ImageWidth.Pixels = 259;
generator.Parameters.ImageHeight.Pixels = 151;
generator.Save(path+sh+".png");
}

@mesteruh,
Please note that generator.Parameters.ImageHeight works only with AutoSizeMode.Nearest or Interpolation as shown in the following sample code:

public static void Barcode_221910_A()
{
    using (var generator = new BarcodeGenerator(EncodeTypes.Code128))
    {
        generator.CodeText = "1234567890";
        generator.Parameters.CaptionAbove.Visible = true;
        generator.Parameters.CaptionBelow.Visible = true;
        generator.Parameters.CaptionAbove.Text = "24680";
        generator.Parameters.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.Nearest;
        generator.Parameters.ImageWidth.Pixels = 259;
        generator.Parameters.ImageHeight.Pixels = 151;
        generator.Save("output_Nearest.png");
    }
}
public static void Barcode_221910_B()
{
    using (var generator = new BarcodeGenerator(EncodeTypes.Code128))
    {
        generator.CodeText = "1234567890";
        generator.Parameters.CaptionAbove.Visible = true;
        generator.Parameters.CaptionBelow.Visible = true;
        generator.Parameters.CaptionAbove.Text = "24680";
        generator.Parameters.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.Interpolation;
        generator.Parameters.ImageWidth.Pixels = 259;
        generator.Parameters.ImageHeight.Pixels = 151;
        generator.Save("output_Interpolation.png");
    }
}

With AutoSizeMode.None you should use generator.Parameters.Barcode.BarHeight.Millimeters however it is deprecated and not recommended.
output_Interpolation.png (1.5 KB)
output_Nearest.png (1.5 KB)