Showing posts with label retrieving. Show all posts
Showing posts with label retrieving. Show all posts

Monday, March 26, 2012

images

can someone please point me in the direction to storing and retrieving
images in sql server 2000Mark wrote:
> can someone please point me in the direction to storing and retrieving
> images in sql server 2000
The language is important here. For an ADO example, see:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q258038
From .Net:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconconservingresourceswhenwritingblobvaluestosqlserver.asp
David Gugick
Quest Software
www.imceda.com
www.quest.com

Friday, March 23, 2012

Image Retrieving from database

hi,

I have a SQL database that has Images stored. I am able to read the image from the database and display it. But i am not able to control the size and the position where it is displayed. I want to develop something like a photo album. the images should be displayed in a smaller size. but when the user clicks on the image, it should blow up to its original size.
I am struggling with this for some time. Any suggestions as how to develop it??.
Any help in this regard would be highly appreciated.

thanks,
-sriramCreate thumbnails of the images when they're uploaded.|||Or when they are retrieved.|||You could try streaming the file and resizing it on the fly with GDI+

or using HTTP Handlers:

a good article is at
http://www.c-sharpcorner.com/Code/2003/June/HTTPHandlersForImages.asp

alternatively:

the following code allows an .aspx file to receive parameters (file name and width of picture) and return a .jpg so that in you HTML code you can use access an image like this:

src="SmartPicture.aspx?f=yourpic.jpg&w=50"

and the file yourpic.jpg will be displayed with a width of 50 pixels and a calculated proportional height. The file size will also be reduced - ie: if your original picture was 4Mb, it would be scaled down to around 15kb.

code as follows:

save it as SmartPicture.aspx


<%@. Page Language="C#" %>
<%@. Import Namespace="System.Drawing" %>
<%@. Import Namespace="System.Drawing.Imaging" %>
<script runat="server"
void Page_Load(Object s, EventArgs e) {

double photoWidth,photoHeight;
double percentageDifference = 0;
bool heHasAccess = false;
System.Drawing.Image inputImage;

//get information being sent
heHasAccess = true;

//get file name
string pictureFileName = Request.QueryString["f"];
if(pictureFileName == null || pictureFileName == "") {
heHasAccess = false;
}

//get width
try {
if (Request.QueryString["w"] == null) {
photoWidth = 0;
} else {
photoWidth = Int32.Parse(Request.QueryString["w"]);
}
}
catch {
photoWidth = 0;
}

//if anything went wrong, show error picture
if(!heHasAccess) {
inputImage = System.Drawing.Image.FromFile(Server.MapPath("images/pictureNoAccess.jpg"));
} else {
inputImage = System.Drawing.Image.FromFile(Server.MapPath("images/" + pictureFileName));
}

//if no width was given, assume the default now
if(photoWidth==0) {
if(!heHasAccess) {
photoWidth = 100;
} else {
photoWidth = inputImage.Width;
}
}

//define size for new image
percentageDifference = inputImage.Width / photoWidth;
photoHeight = inputImage.Height / percentageDifference;

//output new image with different size
Bitmap outputBitMap = new Bitmap(inputImage,Convert.ToInt32(photoWidth),Convert.ToInt32(photoHeight));
Response.ContentType = "image/jpeg";
outputBitMap.Save(Response.OutputStream, ImageFormat.Jpeg);

}
</script>

|||This works fine.

But i have the image in a SQL database. I have image in a binary format.

So i am using the Response.BinaryWrite method.

But i have some other infromation also to be dispalyed with the image. For example some descrption and other deatils. But the image gets displayed at the top left corner hiding all other literals and labeles.

Any suggestions please.

thanks,
-sriram|||Could you post the code you are using?|||On button click: I am retreiving an image name :Test1 from my Sql Server database.
I am posting the code:

Dim imgid As String = Request.QueryString("Test1")
Dim conn As String = "data source=ERB112SERV;initial catalog=TEST;persist security info=False;user id=artak;password=po4d8dor1ju;workstation id=ERB112SERV;packet size=4096"

Dim myConnection As New SqlConnection("data source=ERB112SERV;initial catalog=TEST;persist security info=False;user id=artak;password=po4d8dor1ju;workstation id=ERB112SERV;packet size=4096")

Dim sql As String = "SELECT imgdata, imgtype FROM ImageStore WHERE imgtitle = 'Test1'"
Dim command As SqlCommand = New SqlCommand(sql, myConnection)
myConnection.Open()
Dim dr As SqlDataReader = Command.ExecuteReader()
If (dr.Read()) Then

Response.ContentType = dr("imgtype").ToString()
Response.BinaryWrite(dr.Item("imgdata"))

End If
myConnection.Close()

Thanks for mailing.

-sriram|||But the image gets displayed at the top left corner hiding all other literals and labeles.

Sounds like you're mixing absolute, and relative positioning, no?

If thatis the case, then you're going to have to either specify the positioning for the image, or go to all relative positioning (flow layout) for the controls involved.|||You have to assing the image to img tag, then you could display it where ever you want!

Below example might helps you to understand it!

Live example
http://www.w3coder.com/contest/examples/showipinimage.aspx

and code for it at
http://www.w3coder.com/contest/examples/ImageIPonaspxpage.zip

Hope these helps!|||hi,

Sorry. I didnt quiet get it. I am not even able to assign the image from a database.

So i am not able to write the output from a database to an Image.

I am not able to get the idea of assigning relative positioning.

can you help me with a sample codr or so so that i can understand it well.

thanks,
-sriram|||Would you have code for saving an image to a database?|||I don't understand your question.|||

can anyone pls enlighten my on to retrieve the image file from MS Access?

what is the syntax and the way of approving and maybe a sample code.. im a noob... thanks

sql

Monday, March 19, 2012

Image Column Data and Backup

I have a table (SQL Server 2000) that stores icon files in an Image
field. I have no problem storing and retrieving the images on my system.
When I back up the database however the rows in that table do not seem
to get backed up. In other words when I restore the database on another
server there are no rows in that one table.
I have used the sp_tableoption to turn "in row text" on for the table
etc. Anyone have a clue what I might be doing wrong? This table will
eventually need to be recreated at a customer site with the data intact
and I was planning on just backing the database up and then restoring it.
Bob PorterA restored database will be exactly like the original, less uncommitted
transactions. A common cause of the problem you describe is that multiple
backups exist in the same backup file and the first (oldest) is restored by
default. You can list the backup file contents with RESTORE HEADERONLY:
RESTORE HEADERONLY
FROM DISK='C:\Backups\MyDatbase.bak'
You can then specify the desired backup with the FILE specification:
RESTORE DATABASE MyDatabase
FROM DISK='C:\Backups\MyDatbase.bak'
FILE=2
Hope this helps.
Dan Guzman
SQL Server MVP
"Robert Porter" <rhysliam@.noemail.nospam> wrote in message
news:ud2nToCbFHA.2128@.TK2MSFTNGP15.phx.gbl...
>I have a table (SQL Server 2000) that stores icon files in an Image field.
>I have no problem storing and retrieving the images on my system. When I
>back up the database however the rows in that table do not seem to get
>backed up. In other words when I restore the database on another server
>there are no rows in that one table.
> I have used the sp_tableoption to turn "in row text" on for the table etc.
> Anyone have a clue what I might be doing wrong? This table will eventually
> need to be recreated at a customer site with the data intact and I was
> planning on just backing the database up and then restoring it.
> Bob Porter|||Dan Guzman wrote:
> A restored database will be exactly like the original, less uncommitted
> transactions. A common cause of the problem you describe is that multiple
> backups exist in the same backup file and the first (oldest) is restored b
y
> default. You can list the backup file contents with RESTORE HEADERONLY:
> RESTORE HEADERONLY
> FROM DISK='C:\Backups\MyDatbase.bak'
> You can then specify the desired backup with the FILE specification:
> RESTORE DATABASE MyDatabase
> FROM DISK='C:\Backups\MyDatbase.bak'
> FILE=2
>
It did! Thanks, sorry for the newbie question I knew better... sigh...|||No problem. You're certainly not the first to run into this :-)
Hope this helps.
Dan Guzman
SQL Server MVP
"Robert Porter" <rhysliam@.noemail.nospam> wrote in message
news:%23J0MYlDbFHA.464@.TK2MSFTNGP15.phx.gbl...
> Dan Guzman wrote:
> It did! Thanks, sorry for the newbie question I knew better... sigh...