memorystream - Access File in memory stream ? c# -
i'm using code save file memory stream
using system.drawing.imaging; dictionary<string,memorystream> dict = new dictionary<string,memorystream>(); dict.add("mypicture.png",new memorystream()); bmp.save(dict["mypicture.png"], imageformat.bmp);
after have function accepts file name
result = drawmatches.draw("box.png", "mypicture.png", out matchtime,i);
am accessing file memory stream correctly? in function it's saying
invalid argument
i think i'm not accessing file in right way memory stream
this drawmatches.draw:
public static image<bgr, byte> draw(string modelimagefilename, string observedimagefilename, out long matchtime,int i) { image<gray, byte> modelimage = new image<gray, byte>(modelimagefilename); image<gray, byte> observedimage = new image<gray, byte>(observedimagefilename); }
error not in compilation, when running
it says " parameter not valid " , points observedimage
i'm not sure image<gray, byte>
class , how implemented, you're passing string
constructor - sure correct? (edit: found out part of emgu implementation). i'll show how you'd create image stream:
memorystream ms = dict["mypicture.png"]; // gives memory stream dictionary ms.seek(0, seekorigin.begin); // go origin of stream bitmap bmp = new bitmap(ms); // create image stream
now suspect want create new "emgu image" stream have using next constructor:
image<bgr, byte> img1 = new image<bgr, byte>("myimage.jpg");
which - according emgu documentation - supposed read image file. don't have file named "mypicture.png", have stream within dictionary under key "mypicture.png", totally different. uncertainty image<t1, t2>
class able read stream - @ to the lowest degree didn't see in docs.
what need phone call (using code provided above):
image<gray, byte> img1 = new image<gray, byte>(bmp);
all beingness said, code draw
method (which can't static, way) should read this:
private bitmap getbitmapfromstream(string bitmapkeyname) { memorystream ms = dict[bitmapkeyname]; ms.seek(0, seekorigin.begin); homecoming new bitmap(ms); } public image<bgr, byte> draw(string modelimagefilename, string observedimagefilename, out long matchtime,int i) { image<gray, byte> modelimage = new image<gray, byte>(getbitmapfromstream(modelimagefilename)); image<gray, byte> observedimage = new image<gray, byte>(getbitmapfromstream(observedimagefilename)); }
edit in comments below want cut down processing time saving bitmaps memory stream instead of writing disk.
i need inquire following: why do in first place? notice code posted above have bitmap
save memory stream. why don't set bitmap dictionary?
dictionary<string, bitmap> dict = new dictionary<string, bitmap>(); dict.add("mypicture.png", bmp);
then retrieve right away less time beingness wasted storing , reading image stream. draw
method read:
public image<bgr, byte> draw(string modelimagefilename, string observedimagefilename, out long matchtime,int i) { image<gray, byte> modelimage = new image<gray, byte>(dict[modelimagefilename); image<gray, byte> observedimage = new image<gray, byte>(dict[observedimagefilename]); }
c# memorystream
No comments:
Post a Comment