|
Hi,
I'm trying to get a base64 string from an image to place inside a WordProcessingML xml document. I need to save the image to a stream after it's generated through asp.net, that is, I'm not able to use the file system. For some reason, I seem to get a different string loading something from the file system and using file streams and binary readers, as opposed to when I use Image.Save and a memory stream. I've pasted some sample code below, it's not my actual code that I'm working with but simulates the situation. The two methods generate different strings from the same image file. If I reverse the process, and take the two generated strings and load them into an image, both work fine. No doubt there is some obvious encoding issue or something that I'm sadly unaware of so if anyone had any ideas that'd be great.
FileStream fs = File.OpenRead(@"C:\temp\chart.png");
BinaryReader br = new BinaryReader(fs);
string pngString = Convert.ToBase64String(br.ReadBytes((int)fs.Length));
MemoryStream memStream = new MemoryStream();
Image image = Image.FromFile(@"C:\temp\chart.png");
image.Save(memStream,System.Drawing.Imaging.ImageFormat.Png);
string memString = Convert.ToBase64String(memStream.GetBuffer());
Thanks,
Matt
|
|
|
|
|
if you do an image.Save to a binaryWriter do you get the same files? There is a form of image.Save which takes encoding parameters. You probably have to set these to match the original file.
|
|
|
|
|
|
Hi Andy,
I didn't actually even save the image programatically, as I mentioned the snippet I've pasted in isn't the actual code I'm working with it's just a test that I wrote up to see what the problem was in my actual code. The image on disk has just been saved straight from a browser so I could use it in the test. Don't know if this makes any difference to you?
Thanks,
Matt
|
|
|
|
|
I don't think the image object makes any promises about Load() and Save() generating the exact same bits. I just suggested a test to verify that.
Unless you have to use the image object to manipulate the image in some way I would just deal with it as a stream. That's how I've always dealt with them in WordprocessingML documents.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
|
Yeah my actual code does deal with it as a stream but it generates the same string as the Image.Save(memoryStream) method. Basically I'm using a third party charting component which has a save method which is able to save to a stream, I assume it uses the same method as the Image.Save does as it generates the same base64 string. I was hoping if i could get to the bottom of the reason I am getting two different strings I could take that solution to my actual code.
I can see now that the string is exactly the same, except the file IO method has more bytes on the end that are missing from the other method.
|
|
|
|
|
Hi
I have two forms, main form and login form, I need both forms to load at the start of my application (login form in front of main). The user shouild not be able to switch focus to the main form intil a successful login is accomplished. I'm loading both forms from a main method of another class. I played around with Application.run and ShowDialog methods without achieving wanted results. Any ideas are appriciated.
Thank you
|
|
|
|
|
Using application.run you can load your login form before the main form.
What you are describing sounds like you want to use ShowDialog in the activated or paint event to set an authentication token in the main form. That way you will have both forms on the screen at the same time.
|
|
|
|
|
What I would do is run the main form normally, and then handle the Activated event for the form, and if it's the first time, display the dialog.
bool firstTime = true;
protected override void OnActivated(EventArgs e)
{
if(firstTime)
{
firstTime = false;
LoginForm form = new LoginForm();
form.ShowDialog(this);
}
} That should work, displaying the main form and the login form on top of it.
But, my real solution would be to implement a main form with everything disabled if no user is logged in. This way a user can log in, then log out, and then another user log in without terminating your app, and only the corresponding menu items would be enabled.
And then, in the Activated event for the first time, simulate that the Log In menu item was selected. This way, if the user can't log in (invalid user or password), the application does not have to end.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
If I understood correctly, both suggestions involve controling the displaying of the login form from within the main form. Is there a way to accomplish the same thing (displaying both forms) from a 'static void Main() ' method from a third class- the class that I'll use to start the application.
Thank you in advance
|
|
|
|
|
The reason we are suggesting this is because it is the way that .net forms are implemented. The typical windows approach for this type of UI is to use a modal dialog which prevents the parent form from accepting input while the modal dialog is active.
If you don't care about disabling the main form you can just call Show() on the login form and ShowDialog on the main form, then both forms will be active. However, you need to setup some way for both forms to share state information and keep thier UIs synchronized.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
The thing is that Application.Run blocks until your form is closed, so you can't do anything from your Main while your form is displayed. You either have to display the login form and act on it before displaying your main form, or display your login form from within your main form.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
I think it should be possible to handle the Activated event from somewhere instead of overriding OnActivated in the form itself. The code within the handler should be the same as now.
|
|
|
|
|
Hi, guys, I am now developing a drawing program in C#. Everytime when adding new lines, ellipse or other shapes, I have to use "this.Invalidate(); this.Update();" to refresh the drawing area then new
shapes will appear. However, it has to paint all the shapes I drew before, or the shapes I drew before may be erased!
But everytime redrawing every shape causes terribly flicking! How to avoid this? Can it only draw newly-drawn shape?
ps: I use ControlStyles.DoubleBuffer and ControlStyles.UserPaint. The effect is not obvious.
Many thanks!
Radic
Beijing, China
-- modified at 21:25 Sunday 28th August, 2005
|
|
|
|
|
You need to look into double buffering. You can actually set up C# to do this for you, just google double buffer C# and you're sure to find plenty of info.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks, Christian! Absolutely you are the most warm-hearted!
|
|
|
|
|
Don't know where the value was taken of this line...
public const int OF_SHARE_DENY_WRITE = 32;
This is regarding the avifil32.dll... Where did the programmer get the value "32"? Where can you get a reference of this kinds of values that would be passed into parameters... Thanks for the help...
-- modified at 21:12 Sunday 28th August, 2005
|
|
|
|
|
boggs wrote:
Where did the programmer get the value "32"?
Probably from the C++ header file that defines it.
boggs wrote:
can you get a reference of this kinds of values that would be passed into parameters...
In the C++ header files where they are defined, or just create a C++ project, type the names in and hover the mouse, you'll generally see the value in the status bar.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Oh... Thanks... I think I'll try that...
|
|
|
|
|
is consuming in c#?
I.E. is there a general purpose method of determining how much memory a HashTable or string or any other object is using?
"A preoccupation with the next world pretty clearly signals an inability to cope credibly with this one."
|
|
|
|
|
Have a look at the SizeOf method of the System.Runtime.InteropServices.Marshal class.
---
b { font-weight: normal; }
|
|
|
|
|
The marshaling call will work, you can also load up winDbg and use SOS to look at all the .net memory allocations.
|
|
|
|
|
It's only for structs, not for classes.
The only way of getting a rough estimate of the size of a managed object is by serializing it. The serialized size is actually bigger than the size in memory, but it can help you to spot who's taking memory.
I see dead pixels
Yes, even I am blogging now!
|
|
|
|
|
Hi All,
Can anybody help me how to convert Copybook data into Excel SpreadSheet using C# .I am new to Copy book.The copybook structure as follows.
*****Copybook1*****
05 IC-Record-ID PIC X(02)
value'IC'
05 IC-TPA-ID PIC x(06)
05 IC-Employer-ID PIC X(09)
05 IC-Plan-ID PIC x(09)
05 IC-Employee-ID PIC X(30)
05 IC-Account-Type-Code PIC X(04)
05 IC-Plan-Start-Date PIC x(08)
05 IC-Plan-End-Date PIC x(08)
05 IC-Account-Status PIC 9(01)
88 IC-Acct-New value 1.
88.IC-Acct-Active value 2.
88,IC-Acct-Temp-Inactive value 3.
88.IC-Acct-Perm-InActive value 4.
05 IC-Auto-Deposit-Last-Alloc-Dt Pic x(08)
05 IC-Flex-Account-Options Pic x(02)
88 IC-Recurr-Expense value '01'
88 IC-Copay-Rollover value '02'
05 IC-Request_Legnth Pic s9(04)COMP.
05 IC-Subscriber-Person-ID-R REDEFINES
IC-Subscriber-Person-ID Pic x(15)
10 IC-Plan-ID pic x(10)
10 IC-Plan-Status Pic x(01)
88 IC-Plan-New value '1'
88 IC-Plan-Active value '2'
*****Copybook2*****
05 RB-RB-Record-D PIC X(02)
Value'RB'.
05 RB-Employer-ID PIC X(09)
05 RB-Employee-ID PIC X(30)
05 RB-Details-Response-Code PIC X(09).
****Copybook3*****
Employee-Account-Record
05 RC-Employee-ID PIC X(02)
value'RC'
05 RC-Employer-ID PIC X(09)
05 RC-Employee-ID PIC X(30)
05 RC-Account-Type-Code PIC X(04)
05 RC-Plan-Start-Date PIC X(08)
05 RC-Plan-End-Date PIC X(08)
05 RC-Detail-Response-Code PIC(06)
Once defined above structure . I have to give input file as sequential data file and expected output as spreadsheet.
Thanks & Regards
Rao
-- modified at 18:57 Sunday 28th August, 2005
|
|
|
|