Skip to content

Commit

Permalink
fix: gerando imagem em bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertorp authored and GustavoSabel committed Nov 27, 2023
1 parent 3d58613 commit 52a3112
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions NFe.AppTeste/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,8 @@ private void BtnCupom_Click(object sender, RoutedEventArgs e)


//impr.Imprimir(salvarArquivoPdfEm: fileDialog.FileName.Replace(".pdf", "") + ".pdf");
impr.GerarJPEG(fileDialog.FileName.Replace(".jpeg", "") + ".jpeg");

var bytes = impr.GerarImagem();
var base64 = Convert.ToBase64String(bytes);
}
catch (Exception ex)
{
Expand Down
28 changes: 28 additions & 0 deletions NFe.Danfe.Nativo/NFCe/DanfeNativoNfce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ public void GerarImagem(string filename, ImageFormat format)
}
}

public byte[] GerarImagem()
{
// Feito esse de cima para poder pegar o tamanho real da mesma desenhando
using (Bitmap bmp = new Bitmap(300, 70000))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.White);
GerarNfCe(g);
}

// Obtive o tamanho real na posição y agora vou fazer um com tamanho exato
using (Bitmap bmpFinal = new Bitmap(300, _y))
using (var streamer = new MemoryStream())
{
using (Graphics g = Graphics.FromImage(bmpFinal))
{
g.Clear(Color.White);
g.DrawImage(bmp, 0, 0);

bmpFinal.Save(streamer, ImageFormat.Jpeg);
}

return streamer.ToArray();
}
}
}

public void GerarJPEG(string filename)
{
GerarImagem(filename, ImageFormat.Jpeg);
Expand Down

0 comments on commit 52a3112

Please sign in to comment.