 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 18th, 2003, 06:07 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Displaying Bitmap files from a database
Hi Guys,
I want to display BitMap files from my database and place them within a datagrip. I am at the moment using the DataAdapter and DataSet to gain my info from the data source. Is this possible??
Thanks
Adnan
__________________
Adz - Learning The J2EE Ways.
|
|

October 20th, 2003, 12:52 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You'll need to create an aspx webform that replies with binary data in the form of a image stream. You'll have to provide the necessary information on the query string so that the ASPX knows what data you want. Then in your datagrid you just create standard image tags (or web controls) and specify the URL to be the aspx page with the necessary parameters.
For example:
The datagrid HTML would include an image tag that looks like this...
<img src="getImage.aspx?imageID=123456" />
Then you have a webform (getImage.aspx) which queries the database for the right image and streams that data to the browser using BinaryWrite. You must be sure to specify the content type (jpg, gif, png, etc.) using Response.ContentType and you'd also need to do some conversion of the BMP so you stream that image type (certainly don't want to stream a raw bitmap).
Look into the System.Drawing.Image classes. There are methods to generate new images from files and streams(text) and do size conversions. You can "save" to a stream in a specific form (jpg, gif, png, etc.). Once you have a stream you can feed that to the browser.
Peter
|
|

October 20th, 2003, 03:55 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Planoie,
thanks for the explanation, but how do you create a web form that replies with binary datain the form of an image stream??
|
|

October 20th, 2003, 04:10 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
What you provide in the binary stream is up to you. You are going to provide it a bytestream that comes from the image classes. The binary stream will happen to be image data. You tell the browser what it's seeing by specifying the content type with Response.ContentType = "img/jpeg" or something like that. The browser will know how to deal with this automatically. You just need to make sure you provide a clean binary stream (you should clear the response buffer before you start Response.BinaryWrite, then flush and end the response to ensure no garbage gets into the stream). I know the way I have done it so far is not quite optimal, but it seems to work. You can erase everything in the ASPX file (apart from the @Page directive) so that you at least know that no HTML goes out to the browser. Then in page_load you can do your binary stream.
Peter
|
|

January 7th, 2005, 04:59 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Peter,
I have arrived at this point nearly 2 years later. Do you have code examples to provide the lazy and less well skilled?
Why can I not System.Drawing.Image classes to send the information to the Image control, i.e. why do I need a sparate Web Form?
Regards
Trevor Miles
|
|

January 7th, 2005, 11:10 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
All of the ASP.NET controls do nothing more than spit out HTML. I vaguely recall some method by which you could include binary image data in a page, but I have no idea how it's done and it's a HTML topic not necessarily a .NET specific issue.
|
|

January 7th, 2005, 11:50 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Peter. Still no code? :-(
|
|

February 11th, 2005, 10:15 AM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try this
Make a web form and remove all but the page directives ie.
[code]
<%@ Page Language=" vb" AutoEventWireup="false" Codebehind="GenImage.aspx. vb" Inherits="TestGFX.GenImage"%>
[/code.
Add this to the page load of your form.
Code:
'Page Load for GenImage.aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim szBanner As New Size(400, 25)
Dim intPercent As Integer = Integer.Parse("0" & Request.QueryString("P"))
Dim objBitmap As Bitmap = New Bitmap(szBanner.Width,szbanner.Height)
Dim objGraphic As Graphics = Graphics.FromImage(objBitmap)
Dim whiteBrush As New SolidBrush(Color.Red)
Dim blackPen As New Pen(Color.Black, 2)
Dim strFormater As StringFormat = New StringFormat
strFormater.LineAlignment = StringAlignment.Center
strFormater.Alignment = StringAlignment.Center
Dim fnt As New Font("Comic Sans MS", 16, FontStyle.Bold)
objGraphic.FillRectangle(Brushes.Gray, 0, 0, 400, 25)
objGraphic.DrawRectangle(Pens.DarkGray, 0, 0, 400, 25)
objGraphic.FillRectangle(Brushes.Blue, 0, 0, intPercent * 4, 25)
objGraphic.DrawRectangle(Pens.DarkBlue, 0, 0, intPercent * 4, 25)
objGraphic.DrawString(Request.QueryString("Name") & " " & intPercent, fnt, Brushes.White, 200, 13, strFormater)
Response.Clear()
Response.ContentType = "image/gif"
objBitmap.Save(Response.OutputStream, ImageFormat.Gif)
End Sub
add this line to your html or asp doc where you wish to display your image progressbar.
Code:
<IMG src="/testGFXcs/cimg.aspx?P=<%=rnd.next(0,101)%>">
I hope this helps
|
|
 |