Frankidoze

Hi All,

Context: .Net 2.0

I have a web page with an Ink control ( InkOverLay - Windows controls embedded in object tags), no problem so far. I ink, save it in an xml (xml saved in SQL 2K in an Image column type) and load it back, update it so on and so forth.

Ink is saved with ISF - Ink Serialized Format.



Problem:
I need to print that xml using Crystal report. And unfortunately, CR does not support gif file. So I am stuck here with a Byte[] containing the Ink (ISF) and I don't know how to convert that array into a Byte[] readable by CR.

Any idea


PS: I had posted this under Visual c# general but the post went Off-Topic. As I don't know where to correctly post this, please tell me if I'm again in the wrong forum. and where should I post it.

I came here as it looks like "Ink" is a subject found a lot in here.

Thanks




Re: Notebook, Tablet PC, and UMPC Development How to transform a Byte[] object containing ink (ISF) to a Byte[] readable by Crystal Report with .NET 2.0?

Stefan Wick - MSFT

Hi Frankidoze,

You could convert the byte array to a base64-encoded string. Would that solve your problem

Convert to base64-string:

string stringToStore = Convert.ToBase64String(myIsfByteArray);

Convert back to byte array:

byte[] newIsfByteArray = Convert.FromBase64String(stringToStore);

Thanks,

Stefan Wick

Microsoft - Windows Experience






Re: Notebook, Tablet PC, and UMPC Development How to transform a Byte[] object containing ink (ISF) to a Byte[] readable by Crystal Report with .NET 2.0?

Frankidoze

Well, Crystal report requires a datafield typed as Byte[] to report an image.


I do use those Convert methods to pass back and forth the ink from the client to the server thru a hidden control. Everything works ok on that part.


I am using crystal report to generate a printable version of the data collected on the web page. And that's when I have the problem.


To generate the report I do this:
I get the ink from a hidden control and write it as a string to an xml (xml contains other data - booleans and strings) that I pass to a web service to store into a blob field (image type) in the database.

I retrieve the xml from another web service as a XmlNode and load it to a typed dataset (the ink is loaded in a System.Byte[] dataset column type). I use this typed dataset to build the report.

At that point I can set the array back to an InkOverLay object to format it as a gif and write it to the disk. I can view the image even under paint.
But crystal report does not support gif files neither.

Do you want me to provide you all the pieces of code I am using

Thank you for your help.
Franki.




Re: Notebook, Tablet PC, and UMPC Development How to transform a Byte[] object containing ink (ISF) to a Byte[] readable by Crystal Report with .NET 2.0?

Stefan Wick - MSFT

So it seems like your goal to have an image of your ink that will show up on the reports. Is that correct

You can render the ink to a bitmap in memory and save that to byte array representing the desired image format (jpg, png, etc.). You could store this alongside with the byte array for ISF (which you will still need for roundtrip purposes).

Here is a code snippet that shows how to render ink to a bitmap and persist that as a byte array in jpg format.

Code Snippet

Bitmap inkBitmap;
Rectangle inkrect = _inkOverlay.Ink.GetBoundingBox();
Point bottomRight = new Point(inkrect.Right, inkrect.Bottom);
using (Graphics g = this.CreateGraphics())
{
_inkOverlay.Renderer.InkSpaceToPixel(g, ref bottomRight);
inkBitmap = new Bitmap(bottomRight.X, bottomRight.Y, g);
}

using (Graphics g = Graphics.FromImage(inkBitmap))
{
g.Clear(this.BackColor);
_inkOverlay.Renderer.Draw(g, _inkOverlay.Ink.Strokes);
}

MemoryStream bitmapStream = new MemoryStream(); ;
inkBitmap.Save(bitmapStream, ImageFormat.Jpeg);
byte[] imageByteArrayToSave = bitmapStream.ToArray();

Side note: If you are running on Vista, you can also use the new overload of the Renderer.Draw() method that takes a bitmap reference directly. This will result in a higher quality bitmap. In that case the second 'using()' block would be replaced with a single line '_inkOverlay.Renderer.Draw(inkBitmap, _inkOverlay.Ink.Strokes);'.

Thanks,

Stefan Wick

Microsoft - Windows Experience






Re: Notebook, Tablet PC, and UMPC Development How to transform a Byte[] object containing ink (ISF) to a Byte[] readable by Crystal Report with .NET 2.0?

Frankidoze

Perfect.

It does work after adapting a bit your code as I do that in a web service.

Thank you every much for your help.


Franki