Today, I mainly changed the problem of scaling pictures on the home page of Robin piano.

Source: Internet
Author: User

Today, I think the pictures on the homepage are too slow, so I started to change the image size.

After checking the cause, the problem lies in the thumbnail of the product. Previously, the image was scaled directly using . In fact, the original image was downloaded to the local device, the size of the source image is as large as the size of the source image. the home page needs to display four images, and each source image must be 2.4 MB at kb, which is big enough.

So consider how to display the thumbnail.

At first, I wanted to generate a thumbnail when uploading the file. However, it is difficult to use asp. I have been searching for it online for a long time. I have said that only components are required, my server has no components. this cannot be achieved.

Then, consider whether you can upload the source image twice, generate a thumbnail locally, and upload it again. if you want to use Flex, the code for uploading the source image is found, which is also very simple. however, if I want to scale down and upload files locally, I won't be a beginner. It seems that I want to use ImageData, Matrix or something, and I won't be able to study it all at once.

Finally, there is no way. on the server for research, I remember it was usable. net 1.1, download an asp.net probe, the server uses windows2003 ,. net 1.1, it is easy to do, and the scaling of a server is complete.

 

The showimage. aspx code is as follows:

<%

Try
{
String input_ImgUrl = "../pic/" + Request. QueryString ["name"];

// === Create an Image object through a connection ===
System. Drawing. Image oldimage = System. Drawing. Image. FromFile (Server. MapPath (input_ImgUrl ));
Int int_Width = oldimage. Width;
Int int_Height = oldimage. Height;

// === Size of the uploaded standard image ===
Int int_Standard_Width = Convert. ToInt32 (Request. QueryString ["width"]);
Int int_Standard_Height = Convert. ToInt32 (Request. QueryString ["height"]);

Int Reduce_Width = 0; // The reduced width.
Int Reduce_Height = 0; // The reduced height.
Int level = 100; // the range of the thumbnail quality from 1

// === Get zoom out, crop size ===
Double scaleHeight = (double) int_Standard_Height/(double) int_Height );
Double scaleWidth = (double) int_Standard_Width/(double) int_Width );

If (scaleHeight <scaleWidth)
{
Performance_width = (int) (int_Width * scaleHeight );
Performance_height = int_Standard_Height;
}
Else if (scaleHeight> scaleWidth)
{
Performance_width = int_Standard_Width;
Performance_height = (int) (int_Height * scaleWidth );
}
Else
{
Performance_width = int_Standard_Width;
Performance_height = int_Standard_Height;
}

// === Zoom out image ====
System. Drawing. Image thumbnailImage = oldimage. GetThumbnailImage (performance_width, performance_height, null, IntPtr. Zero );
System. Drawing. Bitmap bm = new System. Drawing. Bitmap (thumbnailImage );

// === Functions for processing JPG quality ====
System. Drawing. Imaging. ImageCodecInfo [] codecs = System. Drawing. Imaging. ImageCodecInfo. GetImageEncoders ();
System. Drawing. Imaging. ImageCodecInfo ici = null;
Foreach (System. Drawing. Imaging. ImageCodecInfo codec in codecs)
{
If (codec. MimeType = "image/jpeg ")
Ici = codec;
}
System. Drawing. Imaging. EncoderParameters ep = new System. Drawing. Imaging. EncoderParameters ();
Ep. Param [0] = new System. Drawing. Imaging. EncoderParameter (System. Drawing. Imaging. Encoder. Quality, (long) level );

System. IO. MemoryStream MS = new System. IO. MemoryStream ();
Bm. Save (MS, ici, ep );
Response. ClearContent ();
Response. BinaryWrite (ms. ToArray ());
Response. ContentType = "image/jpeg"; // specify the output format as image

Response. Flush ();
}
Catch (Exception e)
{
Response. Write (e. ToString ());
}

%>

 

 

The Flex file upload code used in the intermediate process:

<? Xml version = "1.0" encoding = "UTF-8"?>

<Mx: Application xmlns: mx = "http://www.adobe.com/2006/mxml"
Layout = "vertical" verticalAlign = "middle" horizontalAlign = "center">

<Mx: Style>
Global {
FontSize: 14;
}
</Mx: Style>
 
<Mx: Script>
<! [CDATA [
Import mx. effects. Zoom;
Import mx. controls. Image;
// Create a FileReference first
Private var file: FileReference = new FileReference ();

// Indicates the upload status and binds it to the text box below.
[Bindable]
Private var stateText: String = "select a file to upload ";

// CreateChildren occurs earlier than the creationComplete event. The registered event listening in the province is directly written here.
Protected override function createChildren (): void {
Super. createChildren ();
File. addEventListener (Event. SELECT, file_select );
File. addEventListener (Event. COMPLETE, file_complete );
File. addEventListener (ProgressEvent. PROGRESS, file_progress );
}

// Select an event for one file
Private function file_select (e: Event): void {
StateText = "selected file" + file. name;
}

// Events after upload
Private function file_complete (e: Event): void {
StateText = "uploaded ";
}

Private function file_progress (e: ProgressEvent): void {
StateText = "uploaded" + Math. round (100 * e. bytesLoaded/e. bytesTotal) + "% ";
}
// Determine the file size before uploading. FileService. aspx is the upload address.
Private function upload (): void {
If (file. size> 0 ){
StateText = "uploading" + file. name;
Var request: URLRequest = new URLRequest ("FileService. asp ");
File. upload (request );

}
}


]>
</Mx: Script>
 
<Mx: Panel width = "250" height = "112" layout = "vertical" title = "Upload example"
VerticalAlign = "middle" horizontalAlign = "center">
<Mx: HBox>
<Mx: TextInput text = "{stateText}" width = "160" editable = "false"/>
<Mx: Button label = "browse" click = "file. browse ();"/>
</Mx: HBox>
<Mx: HBox>
<Mx: Button label = "upload" click = "upload ();"/>
</Mx: HBox>
</Mx: Panel>
</Mx: Application>
Among them, FileService. asp uses the component-free upload technology, in fact, it can also be replaced by FileService. aspx, as long as the file on a general web page can be uploaded.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.