Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3186
QR Bar Code to Image
posted

I am trying to save a QR Bar Code as an image and not having much luck.  Anyone have a small sample of code to do so?  New to WPF and what I have found on the web so far doesn't seem to work for me.

Also if you have any insight into printing that would be great also.

Thanks,

Nick

Parents
  • 60
    posted

    Hi Nick,

    for example if you have one "Save" button then you should implement the following code:

     

     

     

     

    private

     

     

     

     

    void btnSave_Click(object sender, RoutedEventArgs e)

    {

     

     

    WriteableBitmap bitmap = new WriteableBitmap((int)BarCode.ActualWidth,

    (int)BarCode.ActualHeight);

    bitmap.Render(BarCode,

     

     

    new TranslateTransform

    () { X = 0, Y = 0 });

    bitmap.Invalidate();

    SaveToDisk(bitmap);

     

    }

     

     

     

    private void SaveToDisk(WriteableBitmap bitmap)

    {

     

     

     

     

     

     

     

    var

     

     

     

    ms = new MemoryStream();

     

     

     

    Microsoft.Win32.SaveFileDialog saveFileDialog =

     

    new Microsoft.Win32.SaveFileDialog();

    saveFileDialog.DefaultExt =

     

    "png";

    saveFileDialog.Filter =

     

    "PNG Files (*.png)|*.png";

    saveFileDialog.FilterIndex = 1;

    if (saveFileDialog.ShowDialog() == true

    )

    {

     

     

     

    using (Stream stream = saveFileDialog.OpenFile())

    {

     

     

     

    StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8);

    }

    I hope it will help you.

    Vania

Reply Children