For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > April 2006 > VB (5or6) does something wierd with image data









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author VB (5or6) does something wierd with image data
geronimi

2006-04-27, 6:56 pm

Vb stores an image (bitmap/jpg) in a SQL2000 image field. For some
reason it doubles the size by adding 00 for each byte. But sometimes it
doesn't add 00 (0000.0000) but 01 or 20 or ?? and also the byte that
should be transferd is changed...
So SQLImageData = Imagebyte + 00
and sometimes
SQLImageData = CHANGEDImagebyte + xx.

Some example data: (hex notation):

A1 => A1 00
03 => 03 00
-----------
91 => 18 20
83 => 92 01
8C => 52 01

Could anybody give me an explanation, because I need to know what is
happening, so I can remove te extra bytes added......

I have already a image when I remove the extra bytes, but with some
wrong data (on the place where things like 8C => 52 01 happen)....

Thx,
Geronimo

Jim Mack

2006-04-27, 6:56 pm

geronimi wrote:
> Vb stores an image (bitmap/jpg) in a SQL2000 image field. For some
> reason it doubles the size by adding 00 for each byte. But sometimes
> it doesn't add 00 (0000.0000) but 01 or 20 or ?? and also the byte
> that should be transferd is changed...
> So SQLImageData =3D Imagebyte + 00
> and sometimes
> SQLImageData =3D CHANGEDImagebyte + xx.
>=20
> Some example data: (hex notation):
>=20
> A1 =3D> A1 00
> 03 =3D> 03 00
> -----------
> 91 =3D> 18 20
> 83 =3D> 92 01
> 8C =3D> 52 01
>=20
> Could anybody give me an explanation, because I need to know what is
> happening, so I can remove te extra bytes added......
>=20
> I have already a image when I remove the extra bytes, but with some
> wrong data (on the place where things like 8C =3D> 52 01 happen)....



I have no idea what a SQL2000 image field is, but it's clear that what =
you're storing there is a Unicode string, which is a very bad idea.=20

I would need to see the declarations, definitions and code surrounding =
this to offer specific advice, but there may be others here who have =
already figured this out.

--=20
Jim Mack
MicroDexterity Inc
www.microdexterity.com

Bob Butler

2006-04-27, 6:56 pm

"geronimi" <webjc007@hotmail.com> wrote in message
news:1146147318.765953.17220@v46g2000cwv.googlegroups.com
> Vb stores an image (bitmap/jpg) in a SQL2000 image field. For some
> reason it doubles the size by adding 00 for each byte. But sometimes
> it doesn't add 00 (0000.0000) but 01 or 20 or ?? and also the byte
> that should be transferd is changed...


Sounds like you are getting a Unicode conversion in there. Are you storing
the image data in a String? If so, you want to use byte arrays instead.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

geronimi

2006-04-28, 3:56 am

Hi,

I get the image form db and put it in a field of a dataset, an image
field (byte[])
Then I do this code to get the data:

MemoryStream ImageDataStream = new MemoryStream();
ImageDataStream.Write(ImageData,0,ImageData.Length); // byte[]
ImageData, filled by the dataset
ImageDataStream.Position=0;

The data in the sql2000 db is already with the fault data, so I think
the former vb5-6 application did a wrong save.......... So I need some
recoding of the data in sql........

How can I convert the data? And are there docs or info about Unicode
conversion and so?

thx

J French

2006-04-28, 3:56 am

On 27 Apr 2006 07:15:18 -0700, "geronimi" <webjc007@hotmail.com>
wrote:

>Vb stores an image (bitmap/jpg) in a SQL2000 image field. For some
>reason it doubles the size by adding 00 for each byte. But sometimes it
>doesn't add 00 (0000.0000) but 01 or 20 or ?? and also the byte that
>should be transferd is changed...
>So SQLImageData = Imagebyte + 00
>and sometimes
>SQLImageData = CHANGEDImagebyte + xx.


It looks like you are reading the Image file into a String
- that converts Binary to Unicode

Unicode uses two Bytes for each Char

Normally VB converts Unicode Strings back to ANSI (one byte per char)
when it writes to disk or calls an API

You might have 'a problem of perception', alternatively you might be
storing Unicode in the SQL2000 image field
- COM will preserve Unicode unlike normal APIs and Disk writes
geronimi

2006-04-28, 3:56 am

I found a solution!

I convert the data like this:
ImageData=System.Text.UnicodeEncoding.Convert(Encoding.Unicode,Encoding.Default,ImageData);

and the picture is perfect!!
thx for the help!

J French

2006-04-28, 7:56 am

On 28 Apr 2006 00:39:54 -0700, "geronimi" <webjc007@hotmail.com>
wrote:

>Hi,
>
>I get the image form db and put it in a field of a dataset, an image
>field (byte[])
>Then I do this code to get the data:
>
>MemoryStream ImageDataStream = new MemoryStream();
>ImageDataStream.Write(ImageData,0,ImageData.Length); // byte[]
>ImageData, filled by the dataset
>ImageDataStream.Position=0;
>
>The data in the sql2000 db is already with the fault data, so I think
>the former vb5-6 application did a wrong save.......... So I need some
>recoding of the data in sql........


>How can I convert the data? And are there docs or info about Unicode
>conversion and so?


If your locale is not Far Eastern,
- then try StrConv( S$, vbFromUnicode )


J French

2006-04-28, 7:56 am

On 28 Apr 2006 01:01:48 -0700, "geronimi" <webjc007@hotmail.com>
wrote:

>I found a solution!
>
>I convert the data like this:
>ImageData=System.Text.UnicodeEncoding.Convert(Encoding.Unicode,Encoding.Default,ImageData);
>
>and the picture is perfect!!
>thx for the help!


Sunshine - you are wandering in the wrong play pen

Read below and ponder :-

Almost everybody in this newsgroup is using VB6 or lower.

While you may get a stray answer to VB.NET (including VB2003
and VB2005 which has dropped .NET from its name) questions here,
you should ask them in newsgroups devoted exclusively to
..NET programming.

You risk getting confusing and/or misleading replies.

Look for newsgroups with either the word "dotnet" or "vsnet" in
their name.

For the microsoft news server, try these newsgroups...

news://msnews.microsoft.com/microso....dotnet.general
news://msnews.microsoft.com/microso...et.languages.vb
news://msnews.microsoft.com/microso...c.vsnet.general
news://msnews.microsoft.com/microso...vstudio.general
news://msnews.microsoft.com/microso...c.vstudio.setup
news://msnews.microsoft.public.dotn...ages.vb.upgrade
news://msnews.microsoft.public.dotn...ges.vb.controls
news://msnews.microsoft.public.dotnet.languages.vb.data

There are some others, but these should get you started.


Bob Butler

2006-04-28, 7:56 am

"geronimi" <webjc007@hotmail.com> wrote in message
news:1146209994.234805.228300@i40g2000cwc.googlegroups.com
> Hi,
>
> I get the image form db and put it in a field of a dataset, an image
> field (byte[])
> Then I do this code to get the data:
>
> MemoryStream ImageDataStream = new MemoryStream();
> ImageDataStream.Write(ImageData,0,ImageData.Length); // byte[]


So you are coding in C# and posting the question in a newsgroup meant for VB
6.0 and earlier? Try asking in a group with "dotnet" in the name.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com