PDA

View Full Version : سوال: کمک در مورد webBrowser



0935880
شنبه 30 آبان 1394, 21:17 عصر
سلام دوستان خسته نباشید
من یه تصویره داخل webBrowser لودش میکنم میخوام اون تصویر سایزش متناسب با webBrowser تنظیم بشه و فیت بشه باید چیکار کنم ؟؟؟؟
اینم بگم اصلا نمیتونم اینکار را با pictureBox انجام بدن
لطفا کسایی که فقط راه دارن جواب بدن
با تشکر

0935880
شنبه 30 آبان 1394, 23:51 عصر
منتظر جواب های با ارزش شما هستم همچنان

0935880
یک شنبه 01 آذر 1394, 09:04 صبح
کسی نبود راهنماییی کنه ؟

0935880
یک شنبه 01 آذر 1394, 11:03 صبح
این را هم بگم تصویری که داخل webBrowser لود شده پسوند ان png هست و فقط همین تصویر هست که داخل ان لود میکنم
ایا باز با این امکان حالتی وجود داره که بگی تصویر لود شده در webBrowser با پسوند png را بتوان داخل pictureBox لود کرد ؟؟؟
قصد من این هست که بتوانم با اینکارسایز تصویر را داخل پروژه کنترول کنم با استفاده از قابلیت های pictureBox
اما خوب اگر میشه همین کارا را با webBrowser انجام داد (سایز تصویر نمایش داده شده را تغیر داد ) در این صورت هم مشکل حل شدنیه
ممنون همچنان منتظر جواب دوستان هستم
کدی که من استفاده میکنم
{ for (int i = 0; i < webBrowser1.Document.All.Count; i++)
{
if (webBrowser1.Document.All[i].GetAttribute("src").Contains("?wicket"))
{

String myUrl = webBrowser1.Document.All[i].GetAttribute("src");

webBrowser2.Navigate(myUrl);



}
}
}

tefos666
یک شنبه 01 آذر 1394, 15:59 عصر
سلام ، تاپیک های قبلیتون رو دیدم اگر منظورت هنوز همون مشکل captcha هست ، این چه کاری هست بخاطر یک resize میخوای اینقدر خودتو اذیت کنی از کلاس زیر استفاده کن خودت size هم میتونی بدی
من خودم استفاده کردم راضی هم هستم

CaptchaImage.cs

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;


namespace App_Code {
/// <summary>
/// Summary description for CaptchaImage.
/// </summary>
public class CaptchaImage {
// Public properties (all read-only).
public string Text {
get { return this.text; }
}


public Bitmap Image {
get { return this.image; }
}


public int Width {
get { return this.width; }
}


public int Height {
get { return this.height; }
}


// Internal properties.
private string text;
private int width;
private int height;
private string familyName;
private Bitmap image;


// For generating random numbers.
private Random random = new Random();


// ================================================== ==================
// Initializes a new instance of the CaptchaImage class using the
// specified text, width and height.
// ================================================== ==================
public CaptchaImage(string s, int width, int height) {
this.text = s;
this.SetDimensions(width, height);
this.GenerateImage();
}


// ================================================== ==================
// Initializes a new instance of the CaptchaImage class using the
// specified text, width, height and font family.
// ================================================== ==================
public CaptchaImage(string s, int width, int height, string familyName) {
this.text = s;
this.SetDimensions(width, height);
this.SetFamilyName(familyName);
this.GenerateImage();
}


// ================================================== ==================
// This member overrides Object.Finalize.
// ================================================== ==================
~CaptchaImage() {
Dispose(false);
}


// ================================================== ==================
// Releases all resources used by this object.
// ================================================== ==================
public void Dispose() {
GC.SuppressFinalize(this);
this.Dispose(true);
}


// ================================================== ==================
// Custom Dispose method to clean up unmanaged resources.
// ================================================== ==================
protected virtual void Dispose(bool disposing) {
if (disposing)
// Dispose of the bitmap.
this.image.Dispose();
}


// ================================================== ==================
// Sets the image width and height.
// ================================================== ==================
private void SetDimensions(int width, int height) {
// Check the width and height.
if (width <= 0)
throw new ArgumentOutOfRangeException("width", width,
"Argument out of range, must be greater than zero.");
if (height <= 0)
throw new ArgumentOutOfRangeException("height", height,
"Argument out of range, must be greater than zero.");
this.width = width;
this.height = height;
}


// ================================================== ==================
// Sets the font used for the image text.
// ================================================== ==================
private void SetFamilyName(string familyName) {
// If the named font is not installed, default to a system font.
try {
Font font = new Font(this.familyName, 12F);
this.familyName = familyName;
font.Dispose();
}
catch (Exception ex) {
this.familyName = System.Drawing.FontFamily.GenericSerif.Name;
}
}


// ================================================== ==================
// Creates the bitmap image.
// ================================================== ==================
private void GenerateImage() {
// Create a new 32-bit bitmap image.
Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);


// Create a graphics object for drawing.
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(0, 0, this.width, this.height);


// Fill in the background.
HatchBrush hatchBrush = new HatchBrush(HatchStyle.ZigZag, Color.LightGray, Color.White);
g.FillRectangle(hatchBrush, rect);


// Set up the text font.
SizeF size;
float fontSize = rect.Height + 1;
Font font;
// Adjust the font size until the text fits within the image.
do {
fontSize--;
font = new Font(this.familyName, fontSize, FontStyle.Bold);
size = g.MeasureString(this.text, font);
} while (size.Width > rect.Width);


// Set up the text format.
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;


// Create a path using the text and warp it randomly.
GraphicsPath path = new GraphicsPath();
path.AddString(this.text, font.FontFamily, (int) font.Style, font.Size, rect, format);
float v = 4F;
PointF[] points =
{
new PointF(this.random.Next(rect.Width)/v, this.random.Next(rect.Height)/v),
new PointF(rect.Width - this.random.Next(rect.Width)/v, this.random.Next(rect.Height)/v),
new PointF(this.random.Next(rect.Width)/v, rect.Height - this.random.Next(rect.Height)/v),
new PointF(rect.Width - this.random.Next(rect.Width)/v,
rect.Height - this.random.Next(rect.Height)/v)
};
Matrix matrix = new Matrix();
matrix.Translate(0F, 0F);
path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);


// Draw the text.
hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
g.FillPath(hatchBrush, path);


// Add some random noise.
int m = Math.Max(rect.Width, rect.Height);
for (int i = 0; i < (int) (rect.Width*rect.Height/30F); i++) {
int x = this.random.Next(rect.Width);
int y = this.random.Next(rect.Height);
int w = this.random.Next(m/50);
int h = this.random.Next(m/50);
g.FillEllipse(hatchBrush, x, y, w, h);
}


// Clean up.
font.Dispose();
hatchBrush.Dispose();
g.Dispose();


// Set the image.
this.image = bitmap;
}
}
}


JpegImage.cs


using System.Drawing.Imaging;
using App_Code;


public partial class JpegImage : System.Web.UI.Page {
protected void Page_Load(object sender, System.EventArgs e) {
// Create a CAPTCHA image using the text stored in the Session object.
CaptchaImage ci = new CaptchaImage(this.Session["CaptchaImageText"].ToString(), 200, 50, "Century Schoolbook");


// Change the response headers to output a JPEG image.
this.Response.Clear();
this.Response.ContentType = "image/jpeg";


// Write the image to the response stream in JPEG format.
ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg);


// Dispose of the CAPTCHA image object.
ci.Dispose();
}
}



JpegImage.aspx

<%@ Page language="C#‎‎" CodeFile="JpegImage.aspx.cs" AutoEventWireup="true" Inherits="JpegImage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>JpegImage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#‎‎">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>

</body>
</html>





نحوه استفاده

در فرم لود


if (!this.IsPostBack)
{
// Create a random code and store it in the Session object.
this.Session["CaptchaImageText"] = GenerateRandomCode();
}


private string GenerateRandomCode()
{
string s = "";
for (int i = 0; i < 6; i++)
s = String.Concat(s, this.random.Next(10).ToString());
return s;
}

تو جایی که میخوای استفاده کنی


<div style="z-index: 102; left: 8px; width: 100px; position: absolute; top: 5px;
height: 49px">
<img src="JpegImage.aspx" style="width: 146px; height: 62px" /></div>
</div>

0935880
یک شنبه 01 آذر 1394, 17:11 عصر
تشکر :تشویق::لبخند:
یک پ . خ نیز ارسال کردم در صورت امکان جواب بدهید