REDIMENSIONNER UNE IMAGE - ASPIMAGE

cs_Jackboy Messages postés 757 Date d'inscription vendredi 7 septembre 2001 Statut Membre Dernière intervention 19 juin 2008 - 20 avril 2005 à 22:09
alpacino78000 Messages postés 3 Date d'inscription lundi 16 juin 2008 Statut Membre Dernière intervention 28 juillet 2008 - 19 juin 2008 à 17:29
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/30864-redimensionner-une-image-aspimage

alpacino78000 Messages postés 3 Date d'inscription lundi 16 juin 2008 Statut Membre Dernière intervention 28 juillet 2008
19 juin 2008 à 17:29
salut..
SVP j'ai un probleme..
je travaille avec VS2008, j'ai crée un programme qui permet d'exporter un raport crées avec crystal report , l'export sous forme de HTML.
j'ai un probleme avec les images, l'export essaye de telecharger les images dans un emplacement specifique sur mon disque..
comment je vai faire pour fixer une adresse URL pour ces images.
merci bien
mimo_predator Messages postés 8 Date d'inscription dimanche 4 décembre 2005 Statut Membre Dernière intervention 8 mai 2006
3 févr. 2006 à 18:24
Merci pour vous deux pour le codes. mais y aurait-il une possibilitée de le faire en C++ ou bien en VB car dans mon site je n'utilise pas C#. sauf si je dois m y mettre lol.
cs_Jackboy Messages postés 757 Date d'inscription vendredi 7 septembre 2001 Statut Membre Dernière intervention 19 juin 2008
20 avril 2005 à 22:24
en c#, utilitaire pour redimentionner sont image !


<%@ Control Language="c#" %>
<%@ import Namespace="System.Collections" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Drawing.Drawing2D" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Text" %>
<script runat="server">

protected Size ThumbNailSize = new Size(75,75);
protected string ThumbNailName = "_thumbnail";

private void Page_Load(object sender, System.EventArgs e)
{
if (RequestObject("generate") == "1")
{
GenerateThumbNailImagesForFolder(RequestObject("imgfolder"));
}
this.RW(GenerateHTMLPageForFolder(RequestObject("imgfolder")));
}



public void GenerateThumbNailImagesForFolder(string FolderName)
{
string sPhysicalPath="";
string sFileName="";
string sThumbName="";

sPhysicalPath = Server.MapPath(FolderName);

DirectoryInfo oDir = new DirectoryInfo(sPhysicalPath);

try
{

FileInfo[] oDeleteFiles = oDir.GetFiles();

foreach (FileInfo oFile in oDeleteFiles)
{
sFileName = oFile.Name.ToLower();
if (sFileName.IndexOf("thumbnail") > 0) { oFile.Delete(); }
}

FileInfo[] oFiles = oDir.GetFiles();

foreach (FileInfo oFile in oFiles)
{

sFileName = oFile.Name.ToLower();

sThumbName = sFileName.Replace(".",this.ThumbNailName + ".");

if (sFileName.IndexOf(".gif") > 0)
{
this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Gif);
}
if (sFileName.IndexOf(".jpg") > 0)
{
this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Jpeg);
}
if (sFileName.IndexOf(".bmp") > 0)
{
this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Bmp);
}

}
}
catch (Exception) { }
}

public void GenerateThumbNail(string sPhysicalPath,string sOrgFileName,string sThumbNailFileName,ImageFormat oFormat)
{

try
{

System.Drawing.Image oImg = System.Drawing.Image.FromFile(sPhysicalPath + @"" + sOrgFileName);

System.Drawing.Image oThumbNail = new Bitmap(this.ThumbNailSize.Width, this.ThumbNailSize.Height, oImg.PixelFormat);

Graphics oGraphic = Graphics.FromImage(oThumbNail);

oGraphic.CompositingQuality = CompositingQuality.HighQuality ;

oGraphic.SmoothingMode = SmoothingMode.HighQuality ;

oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic ;

Rectangle oRectangle = new Rectangle(0, 0, this.ThumbNailSize.Width, this.ThumbNailSize.Height);

oGraphic.DrawImage(oImg, oRectangle);

oThumbNail.Save(sPhysicalPath + @"" + sThumbNailFileName,oFormat);

oImg.Dispose();

}
catch (Exception) { }

}

public string GenerateHTMLPageForFolder(string FolderName)
{

string sPhysicalPath="";
string sFileName="";
int nFound=0;
int nCol=0;
int nMaxCols=7;

StringBuilder oString = new StringBuilder();

oString.Append("<html>\");

try
{

sPhysicalPath = Server.MapPath(FolderName);
DirectoryInfo oDir = new DirectoryInfo(sPhysicalPath);
FileInfo[] oFiles = oDir.GetFiles();

foreach (FileInfo oFile in oFiles)
{

sFileName = oFile.Name.ToLower();
nFound++;

if (sFileName.IndexOf(\"thumbnail\") > 0)
{

nCol++;
if (nCol == 1) { oString.Append(\"----
\"); }

if ((sFileName.IndexOf(\".gif\") > 0) || (sFileName.IndexOf(\".jpg\") > 0) || (sFileName.IndexOf(\".bmp\") > 0))
{
oString.Append(\"");
oString.Append("");
oString.Append("");
oString.Append("");
oString.Append(", \");
}
if (nCol nMaxCols) { nCol 0; oString.Append(\"\"); }

}

}

if ((nFound >0) && (nCol < nMaxCols))
{
nCol = nMaxCols - nCol;
oString.Append(\", \");
}

}
catch (Exception) { }

oString.Append("
</html>");

return oString.ToString();

}

public void RW(string sVal)
{
Response.Write(sVal +'\n');
}

public string RequestObject(string sName)
{
string sRet="";
try { sRet = Request[sName].ToString().Trim(); }
catch (Exception) { sRet = "";}
return sRet;
}

</script>
cs_Jackboy Messages postés 757 Date d'inscription vendredi 7 septembre 2001 Statut Membre Dernière intervention 19 juin 2008
20 avril 2005 à 22:12
plus un objet COM
cs_Jackboy Messages postés 757 Date d'inscription vendredi 7 septembre 2001 Statut Membre Dernière intervention 19 juin 2008
20 avril 2005 à 22:09
salut !

il doit etre relativement simple de faire un activex en vb ou en c++ qui réalise cette action. je regarde de ce cote et je ten donne des nouvelles...
Rejoignez-nous