我如何使用(Memorystream Ms = New Memorystream()) [英] How Do I Use Using (Memorystream Ms = New Memorystream())
本文介绍了我如何使用(Memorystream Ms = New Memorystream())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图爬行条形码生成器,继承我的代码:
hi , im trying to creeate a barcode generator , heres my code:
using (MemoryStream ms = new MemoryStream())
{
barcode.Save(ms, ImageFormat.Png);
pictureBox1.Image = bitmap;
pictureBox1.Height = bitmap.Height;
pictureBox1.Width = bitmap.Width;
继承人我的错误
'字符串'不包含'保存'的定义并且没有扩展方法'保存'接受类型'字符串'的第一个参数可以找到(你是否错过了使用指令或汇编引用?)
我应该使用什么样的refremce?我所有的当前参考>
heres my error
'string' does not contain a definition for 'Save' and no extension method 'Save' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
what refremce should i use for this? all my current refrences>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
推荐答案
更改
change
barcode.Save(ms, ImageFormat.Png);
to
to
bitmap.Save(ms, ImageFormat.Png);
条形码
是一个字符串 - 错误信息表明 - 这意味着它不是条形码的图像,它是一个包含文章编号的字符串:5013719020011
如果你想转换它例如,对于MemoryStream,您可以将图像字节保存在数据库中,然后您需要首先从该数字创建条形码图像。框架不知道你想要Code 39或EAN128条形码只是因为你有一个字符串中的数字! :笑:
看看你的其余代码,看看你在哪里创建了图像 - 我怀疑你想要使用位图
而不是。
barcode
is a string - the error message says that - which means that it isn't an image of a barcode, it's a string containing the Article Number: "5013719020011"
If you want to convert it to a MemoryStream so you can save the image bytes in a database for example, then you need to first create a barcode image from that number. The framework doesn't know that you want a Code 39 or an EAN128 barcode just because you have a number in a string! :laugh:
Look at the rest of your code, and see where you have create the image - I'd suspect that you want to usebitmap
instead.
这篇关于我如何使用(Memorystream Ms = New Memorystream())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文