Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 5th, 2005, 08:46 PM
sqlnewbie sqlnewbie is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: USA
Posts: 1 sqlnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 15 sec
Reputation Power: 0
Question displaying image fields in reporting services

I have an image field that contains ole objects inserted from an
Access Data Project that may contain bmp images, jpg images or
even AutoCAD dwgs. They display fine in Access forms or reports
using bound object frames, but not with reporting services image
controls. I have tried to set the value property to
=System.Convert.FromBase64String(Mid(System.Conver t.ToBase64String(Fields.FieldName.Value),105))
as suggested several places on the web. That did not display the picture properly.

Please help!!

sqlnewbie

Reply With Quote
  #2  
Old April 9th, 2005, 07:19 PM
Dallas1579 Dallas1579 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 Dallas1579 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 34 sec
Reputation Power: 0
displaying images in SQL RS

Hello mate, I have the same issue is there a fix around out there I can not view the
images in the report

Reply With Quote
  #3  
Old May 17th, 2005, 12:51 PM
dlightman dlightman is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 1 dlightman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 30 sec
Reputation Power: 0
Thumbs up Database driven images not showing in non-english systems

I'd like to share with the community the results of 3 days of testings and
headaches. I finally found the reason for the problem and a way to solve it:

As stated in
http://www.microsoft.com/technet/prodtechnol/sql/2000/deploy/migratereports.mspx
dealing with 'How to Migrate Access Reports to Reporting Services', when
talking about database-stored images, the writer (Adam Cogan) says:
[...]
3. Replace the default value in the image Value field with the following
expression as shown in Figure 16:
=System.Convert.FromBase64String(Mid(System.Conver t.ToBase64String(Fields!Picture.Value),105))
[...]

However this piece of code does not work under certain conditions. I have
seen several forum pages of people posting they are having the same problem
(see
http://forums.devarticles.com/archive/t-11844/displaying-image-fields-in-reporting-services )
. The former code takes the assumption that the images stored in the
database were saved by a English/American localised application. If you are
using an English version of MS Access, do copy a bitmap file and paste it
into an image field of SQL table (using ADP Access project), MS Access adds
an OLE header and trailer to the image you are storing. In the English case,
the header is 78 bytes and trailer 38 bytes. However, this header is not of
that size if you are using another language. In my case, we use spanish
applications and the OLE header for bitmap files is 88 bytes instead of 78
(the trailer is also 38 bytes but you can forget about it).

If you use the former piece of code in your reports and you are not using an
English OS and applications you will see red crosses on your reports (this
is an assumption of my own because at least in the Spanish case the header
size differs from English; I suppose the same might happen in German,
French, etc.).

The reason of this behaviour is because when converting those 78 bytes of
english header into a Base64 string, it turns to be exactly 104 Base64
chars:
78 bytes * 8 bits each = 624 bits
If you convert that stream of 624 bits using Base64 (6 bits each char):
624 bits / 6 bits = 104 Base64 chars

So the next Base64 char (105) belongs completely to the bitmap file data and
you don't experience any problem if you use the Mid function to cut the
string by 105th char and then FromBase64String to convert the Base64 string
back to a byte() (byte array).

However if you use Spanish applications, the OLE header is 88 bytes (704
bits). If you try to convert that stream of bits into a Base64 string:
740 bits / 6 bits each Base64 char = 123,333... chars

What does it mean? It means that it will use 123 chars and 2 bits of the
next char. The other 4 bits of the 124th Base64 char will have data
belonging to the bitmap file. And here is the tricky part: You CANNOT remove
the OLE header without turning the whole string into rubbish because of
this. Thats why you always see red crosses on your reports no matter the
number you use to remove the OLE header from the Base64 string. No matter if
you use 105, 104, 103, or 123, 124, etc. It will always break the Base64
string and when you convert it back to get the image you will get just
rubish.


THE SOLUTION:

Instead of using Base64 strings to cut the OLE header and try to rebuild the
image, you should use this piece of code in your Image RS components:

=System.Text.Encoding.Default.GetBytes(Mid(System. Text.Encoding.Default.GetString(Fields!Picture.Val ue),XXX))

Where XXX is the size of the localised OLE header + 1.
For Spanish use XXX = 89
For English use XXX = 79
For other languages you will have to guess (you can do some trial/error
until you find out).

Why is there this difference of sizes in the OLE header? The header contains
the type description of the file (the type column when you see the file
using explorer) using your local language. In Spanish, the default value for
a bitmap file is 'Imagen de mapa de bits' (22 bytes). However in English the
type description for that kind of files (I suppose) is 'Bitmap image' (12
bytes). Hence:
22 - 12 = 10
The OLE header is 10 bytes larger for spanish applications (in the case of
.bmp files). For other type of files the size probably differs (I have not
tested it).

Instead of trial/error to find the XXX value for your local languae you can
try to do this little calculation:
78 + ( length(bitmap type description for your language) - 12) + 1

That's all. Just use:
=System.Text.Encoding.Default.GetBytes(Mid(System. Text.Encoding.Default.GetString(Fields!Picture.Val ue),XXX))
being XXX the value you have just calculated and forget about the original
Adam's code.

I hope this could help to people experiencing this problem and save their
valuable time. I also hope that Adam Cogan revises his article to replace
his version of the code and explains the restrictions of this alternative
also. People tend to consider documentation under microsoft.com domain to be
fully trustable, but in this case the information was totally wrong for
users that are not using English localised applications.

Regards.

Reply With Quote
  #4  
Old November 4th, 2005, 10:09 AM
RoerGarcia RoerGarcia is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 1 RoerGarcia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 29 sec
Reputation Power: 0
The same thing with another flavour

Hi. you wrote this:
Quote:
Originally Posted by dlightman

THE SOLUTION:

Instead of using Base64 strings to cut the OLE header and try to rebuild the image, you should use this piece of code in your Image RS components:

=System.Text.Encoding.Default.GetBytes(Mid(System. Text.Encoding.Default.GetString(Fields!Picture.Val ue),XXX))

Where XXX is the size of the localised OLE header + 1.
For Spanish use XXX = 89
For English use XXX = 79
For other languages you will have to guess (you can do some trial/error until you find out).

Regards.


and my question about it is... if i have not vb.net but php what is the "system text encoding default get bytes thing" do? how can i do the same function in other languages, ie PHP?

im not an english speaker, sorry for my 'english'

Thanks in advance.
roer

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > displaying image fields in reporting services


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT