c# - How can I include an image as a Resource in my project? -
i want add image resource in project can reference programmatically inserting range in spreadsheet.
i added image right-clicking project , selecting add > existing item...
i hoped image (.png file) available using code:
var logorange = _xlsheet.range[ _xlsheet.cells[1, logo_first_column], _xlsheet.cells[5, logo_last_column]]; //system.drawing.bitmap logo = //reportrunner.properties.resources.pa_logo_notap.png; system.drawing.image logo = reportrunner.properties.resources.pa_logo_notap.png; _xlsheet.paste(logorange, logo);
...but using either bitmap or image, get, "'reportrunner.properties.resources' not contain definition 'pa_logo_notap'"
this seemed sensible code based on read here, seems image has explicitly marked resource work. how accomplish that?
update
i tried this:
system.drawing.image logo = (system.drawing.image)reportrunner.properties.resources.resourcemanager.getobject("pa_logo_notag.png"); _xlsheet.paste(logorange, logo);
...but not did confirmation msg item being pasted not being same size , shape place being inserted, , did want that, inserted seemingly unrelated text ("avgorderamountcell.style") instead of image.
update 2
okay, tried this:
assembly myassembly = assembly.getexecutingassembly(); system.drawing.image logo = (system.drawing.image)myassembly.getname().name + ".pa_logo_notap.png"; clipboard.setdataobject(logo, true); _xlsheet.paste(logorange, logo);
...but get, "cannot convert type 'string' 'system.drawing.image' on second line of code.
update 3
this works:
private system.drawing.image _logo; . . . _logo = logo; // logo (the image) passed in overloaded constructor . . . var logorange = _xlsheet.range[ _xlsheet.cells[1, logo_first_column], _xlsheet.cells[6, logo_last_column]]; clipboard.setdataobject(_logo, true); _xlsheet.paste(logorange, _logo);
...but i'm not crazy it, because i'm using image on form, , passing image class's constructor. passing images around seems kind of goofy when should possible store image resource , load resource. still haven't gotten methodology work, though...
update 4
i reckon i'll stick i've got (in update 3), kludgy is, because this:
assembly myassembly = assembly.getexecutingassembly(); stream mystream = myassembly.getmanifestresourcestream(myassembly.getname().name + "pa_logo_notap.png"); bitmap bmp = new bitmap(mystream); clipboard.setdataobject(bmp, true); _xlsheet.paste(logorange, bmp);
...fails with, "value of 'null' not valid 'stream'"
you have change build action of image embedded resource.
then can reference doing:
updated
assembly myassembly = assembly.getexecutingassembly(); stream mystream = myassembly.getmanifestresourcestream( myassembly.getname().name + ".images.pa_logo_notap.png"); bitmap bmp = new bitmap(mystream);
Comments
Post a Comment