Exemple #1
0
		/// <summary>
		/// Converts a bitmap to ascii art.
		/// </summary>
		/// <param name="bitmap">A bitmap.</param>
		/// <returns>Ascii art.</returns>
		/// <example>
		/* 0:::::::::::::::::::::::::::::$MMMMM%:::::::::::::::::::::::::::::::::::::M
			%                            (#''` !M8                                    M
			%                    :QMMMMMMMM849640MMM@(                                M
			%                 "MMMMMMM4*' HM:  !MB#MMMMMM$                            M
			%               'MMMM3        ''$844$    `6MMMMM'                         M
			% '#MNN#H@@@@@@HMMM!          '''`           $MMM3                        M
			%1M@99889QB81!!M*M4'`                          @QM:                       M
			%1Q'"B000008MMM*`MM:`''`                       !M@3                :&$;`  M
			%0`  $`      !B  `*MM6  ''''`                 'MM(!:            $MMMMMMMMMM
			%!&  `8'     #`    ''1MM@H3'`'''`         '$MMMH   %          4M$''!@BMMM4M
			% ;0   46   (3       `''''1#@HBH#&$&$448MMMM0'     :'       (M& ':@BQ@"   M
			%  !B(16BMQ`B                       :894:          `*     'MH   B8Q0`     M
			%    &MM` *M&                      !4               ;:"Q#M#'  !@3Q`       M
			%      4MM;&`                      "                (01'`'''`"Q0"         M
			%        :MN                      `(                `'''`  '84B'          M
			%                                 &                 `` `''QB09`           M
			%          !                     :(                 '389088@;             M
			%          1:                   '9                  !"6QQQ!               M
			%          `#                  :B                  `84'                   M
			%           (#                04                   &'                     M
			%            1M6           `9B!                   $:                      M
			%             !M#006(:'"6490`                   `Q:                       M
			%               4B! :(1!                      `48`                        M
			%                 4@9'                      ;@B!                          M
			%                   '9QB0!              ;8QB3                             M
			%                       `&88909444099898%                                 M
			0:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::M 
		*/
		/// </example>
		public string ToAscii()
		{
			Graphic edgeMap=DetectEdges(this);

			string output="";

			for(int y=0; y<edgeMap.Height; y+=13)
			{
				for(int x=0; x<edgeMap.Width; x+=8)
				{
					int minDistance=999999999;
					char minChar=' ';

					for(int i=32; i<127; i++)
					{
						char c=(char)i;
						string str=""+c;

						Graphic characterMap=new Graphic(8, 13, Format.RGB);
						//System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(characterMap);
						characterMap.Fill(System.Drawing.Color.White);

						//characterMap.Rendertex
						Graphic mytext=Graphic.RenderText(new System.Drawing.Font("Courier New", 10), str, System.Drawing.Color.Blue);
						characterMap.Draw(-2, -2, mytext);

						int tmp=ComputeDistance(characterMap,
							new System.Drawing.Rectangle(0, 0, (int)characterMap.Width, (int)characterMap.Height),
							edgeMap,
							new System.Drawing.Rectangle(x, y, (int)characterMap.Width, (int)characterMap.Height));

						if(tmp<minDistance)
						{
							minDistance=tmp;
							minChar=c;
						}
					}

					output+=minChar;
				}

				output+="\r\n";
			}

			return output;
		}
Exemple #2
0
		public Graphic GetSubImage(uint x, uint y, uint w, uint h)
		{
			if(x>=width||y>=height) throw new ArgumentOutOfRangeException("x or y", "Out of image.");

			Graphic ret=new Graphic(w, h, channelFormat);

			ret.Draw(-(int)x, -(int)y, this);

			return ret;
		}
Exemple #3
0
		/// <summary>
		/// Erzeugt ein Thumbnail 
		/// EXPERIMENTEL Muss getestet werdne
		/// Quadrates Thumbnail unter beibehaltung der Seitenverhälntisse
		/// </summary>
		/// <param name="size"></param>
		/// <returns></returns>
		public Graphic ToThumbnail(uint size)
		{
			Graphic bmp=null;
			Graphic crapped=null;
			uint x=0, y=0;
			double prop=0;

			if (width>size)
			{
				// compute proportation
				prop=(double)width/(double)height;

				if (width>height)
				{
                    x=(uint)System.Math.Round(size*prop, 0);
					y=size;
				}
				else
				{
					x=size;
                    y=(uint)System.Math.Round(size/prop, 0);
				}

				//TESTEN

				bmp=new Graphic(x, y);
				//bmp=new System.Drawing.Bitmap((Image)image, new Size(x, y));

				crapped=new Graphic(size, size, channelFormat);
				crapped.Draw(0, 0, bmp);

				//crapped=new System.Drawing.Bitmap(75, 75);
				//Graphics g=Graphics.FromImage(crapped);
				//g.DrawImage(bmp,
				//    new Rectangle(0, 0, 75, 75),
				//    new Rectangle(0, 0, 75, 75),
				//    GraphicsUnit.Pixel);

				bmp=crapped;
			}
			else
			{
				crapped=this;
			}

			return bmp;
		}
Exemple #4
0
        private Graphic Render(int width, int height, string onlyLayer)
        {
            Graphic ret=new Graphic((uint)width, (uint)height, Format.RGBA);
            ret=ret.InvertAlpha();

            foreach(LayerData i in Layers)
            {
                if(onlyLayer=="")
                {
                    if(i.name=="Collision")
                        continue; //Collision Layer überspringen
                }
                else
                {
                    if(i.name!=onlyLayer)
                        continue;
                }

                //Für jedes Tile in X bzw Y Richtung
                for(int y=0;y<i.height;y++)
                {
                    for(int x=0;x<i.width;x++)
                    {
                        int number=i.data[x, y];
                        if(number<=0)
                            continue; //Kein Tile zugewiesen //TODO was genau meint eine Zahl kleiner 0 genau
                        Graphic Tile=GetTile(number);

                        //Korrekturfaktor für Tiles welche breiter bzw. 
                        //höher sind als normal
                        int CorFactorX=0; //Korrekturfaktor für x wird nicht benötigt (denke ich)
                        //int CorFactorX=(int)(Tile.Width-TileWidth);
                        int CorFactorY=(int)(Tile.Height-TileHeight);

                        ret.Draw(x*TileWidth-CorFactorX, y*TileHeight-CorFactorY, Tile, true);
                    }
                }
			
            }

            return ret;
        }