private void Page_Load(object sender, System.EventArgs e)
{
// odchytime vstupni souradnice
int X = Int32.Parse(Request.QueryString.Get("x"));
int Y = Int32.Parse(Request.QueryString.Get("y"));
// do hlavicky odpovedi dosadime, ze se jedna o obrazek
Response.ContentType = "image/jpeg";
String strBitmapFile = @"D:\Cesta\k\souboru\data\praha.rgb";
// originalni velikosti obrazku
int OriginalWidth = 1600;
int OriginalHeight = 1200;
int Width = 300;
int Height = 300;
// aktualni levy horni roh vyrezu
int SeekX = X;
int SeekY = Y;
// dochytani souradnic mimo obrazek <0
if (SeekX < 0) SeekX = 0;
if (SeekY < 0) SeekY = 0;
// totez, ale > jak rozmery obrazku
if (SeekX > OriginalWidth - Width) SeekX = OriginalWidth - Width;
if (SeekY > OriginalHeight - Height) SeekY = OriginalHeight - Height;
FileStream fs =
new FileStream(strBitmapFile, FileMode.Open, FileAccess.Read);
byte[] bin = new byte[Width*Height*3];
// cyklujem celou vyskou obrazku
for (int i=0; i<Height; i++)
{
// skocime na pozici, kde skutecne zacina radek
fs.Seek((OriginalWidth*3)*(SeekY+i)+SeekX*3, SeekOrigin.Begin);
fs.Read(bin, i*Width*3, Width*3);
}
fs.Close();
// Vytvor bitmapu
System.Drawing.Bitmap Obr =
new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
// vytvor bitmapu z dat (cyklujem celou mrizkou bodu)
for(int i=0; i<Height; i++)
for(int j=0; j<Width; j++)
{
Obr.SetPixel(j, i, Color.FromArgb(bin[(i*Height+j)*3+0], bin[(i*Height+j)*3+1], bin[(i*Height+j)*3+2]));
}
// pridame blbinku / informacni textik
Graphics objGrafika = Graphics.FromImage(Obr);
objGrafika.DrawString("by Michael – Hepbeg Club 2004", new Font("Arial", 8), Brushes.Black, 5.0f, 5.0f, StringFormat.GenericDefault);
Obr.Save(Response.OutputStream, ImageFormat.Jpeg);
}