Click here to Skip to main content
15,917,564 members
Home / Discussions / C#
   

C#

 
AnswerRe: call an opener form method Pin
dan!sh 5-Jan-11 5:19
professional dan!sh 5-Jan-11 5:19 
AnswerRe: call an opener form method Pin
fjdiewornncalwe5-Jan-11 6:19
professionalfjdiewornncalwe5-Jan-11 6:19 
GeneralRe: call an opener form method [modified] Pin
Paladin20005-Jan-11 6:33
Paladin20005-Jan-11 6:33 
AnswerRe: call an opener form method Pin
fjdiewornncalwe5-Jan-11 7:05
professionalfjdiewornncalwe5-Jan-11 7:05 
AnswerRe: call an opener form method Pin
Paladin20005-Jan-11 7:33
Paladin20005-Jan-11 7:33 
JokeRe: call an opener form method Pin
fjdiewornncalwe5-Jan-11 9:32
professionalfjdiewornncalwe5-Jan-11 9:32 
AnswerRe: call an opener form method Pin
Paladin20005-Jan-11 7:39
Paladin20005-Jan-11 7:39 
QuestionGet image from resource Pin
csrss5-Jan-11 1:38
csrss5-Jan-11 1:38 
Ok, the question is: how to load image from resource (and then do some manipulations on it)?
In a C++ app, i am simply doing:
specifying image in file myapp.rc like:

/////////////////////////////////////////////////////////////////////////////
//
// RCDATA
//
IDR_MYPIC RCDATA "Res\\bkg.jpg"

then in file resource.h:

#define IDR_MYPIC 111


then in application i can simply access it by:
HRSRC   hResInfo   = FindResourceW((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), 
			MAKEINTRESOURCEW(IDR_MYPIC), RT_RCDATA);


I am trying to do actually the same thing in C#, but after hours of searching, experimenting - i got nothing.
This code returns resources path:

System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
string[] resources = thisExe.GetManifestResourceNames();
string list = "";
foreach (string resource in resources)list += resource + "\r\n";
MessageBox.Show(list);


which are:

ComboTest.Form1.resources
ComboTest.Properties.Resources.resources

Then i am trying do apply each path like this:

System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream file = thisExe.GetManifestResourceStream("ComboTest.Form1.resources.zzz.jpg"); // <- for each path
this.pictureBox1.Image = Image.FromStream(file);


file always = null

Same thing with that:

IntPtr hModule = ResImage.LoadLibraryEx(Application.ExecutablePath, 
                IntPtr.Zero, 0x2 /* LoadLibraryAsDatafile */);
if (hModule == IntPtr.Zero) throw new Exception();
IntPtr hResource = ResImage.FindResource(hModule, "zzz.jpg", "JPEG");


hResource is always null.

My image file is "zzz.jpg" and i have imported it into a project by clicking on a main form (in a designer), clicking on BackgroundImage in Properties tab, then selecting "Project resource file" radio button and clicking "Import" button.
Image now appears in "Resources" folder in Solution Explorer tab.
So, how can i access it from code?
thanks
011011010110000101100011011010000110100101101110
0110010101110011

AnswerRe: Get image from resource Pin
RaviRanjanKr5-Jan-11 1:51
professionalRaviRanjanKr5-Jan-11 1:51 
AnswerRe: Get image from resource Pin
JF20155-Jan-11 1:54
JF20155-Jan-11 1:54 
GeneralRe: Get image from resource Pin
csrss5-Jan-11 2:31
csrss5-Jan-11 2:31 
QuestionGetting Permisions Pin
Wamuti4-Jan-11 23:13
Wamuti4-Jan-11 23:13 
AnswerRe: Getting Permisions [modified] Pin
RaviRanjanKr4-Jan-11 23:53
professionalRaviRanjanKr4-Jan-11 23:53 
AnswerRe: Getting Permisions PinPopular
Luc Pattyn5-Jan-11 2:45
sitebuilderLuc Pattyn5-Jan-11 2:45 
GeneralRe: Getting Permisions Pin
Wamuti8-Jan-11 3:21
Wamuti8-Jan-11 3:21 
GeneralRe: Getting Permisions Pin
Luc Pattyn8-Jan-11 3:29
sitebuilderLuc Pattyn8-Jan-11 3:29 
Generaltest (just ignore) Pin
Luc Pattyn13-Jan-11 9:39
sitebuilderLuc Pattyn13-Jan-11 9:39 
Generaltest (just ignore) Pin
Luc Pattyn13-Jan-11 9:39
sitebuilderLuc Pattyn13-Jan-11 9:39 
Generaltest (just ignore) [modified] Pin
Luc Pattyn13-Jan-11 9:40
sitebuilderLuc Pattyn13-Jan-11 9:40 
Generaltest (just ignore) Pin
Luc Pattyn13-Jan-11 9:56
sitebuilderLuc Pattyn13-Jan-11 9:56 
QuestionQuiz Application In c#.net Pin
varun.g4-Jan-11 23:03
varun.g4-Jan-11 23:03 
AnswerRe: Quiz Application In c#.net Pin
JF20154-Jan-11 23:16
JF20154-Jan-11 23:16 
GeneralRe: Quiz Application In c#.net Pin
varun.g4-Jan-11 23:33
varun.g4-Jan-11 23:33 
GeneralRe: Quiz Application In c#.net Pin
JF20155-Jan-11 2:05
JF20155-Jan-11 2:05 
GeneralRe: Quiz Application In c#.net Pin
varun.g5-Jan-11 16:48
varun.g5-Jan-11 16:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.