I've been trying to select the most appropriate Pane which would fit my elements. I have tried FlowPane and GridPane, but I've had the same result.
Screenshot with the problem
What I want a result is to place the playerCards grid which is on column 1 row 1 straight under the playerInfo grid which is on column 1, row 0. This is not happening because the height of the element's height on column 0, row 0 is bigger. And all elements on the next row are positioned according to this. So basically my goal is to remove the space between the element with red background and the white background.
private Node getTop() {
GridPane container = new GridPane();
FlowPane topp = new FlowPane();
topp.setMinHeight(200);
GridPane playerInfo = new GridPane();
playerInfo.setHgap(125.0);
playerInfo.setVgap(5.0);
playerInfo.setPadding(new Insets(10.0, 10.0, 0.0, 50.0));
//most left here
GridPane legend = new GridPane();
legend.setStyle("-fx-background-color: #FFFFFF;");
legend.setVgap(2.0);
Label[] treasureTypes = new Label[7];
treasureTypes[0] = new Label(" - Diamonds 5pts");
treasureTypes[1] = new Label(" - Rubies 5pts");
treasureTypes[3] = new Label(" - Pearls 3pts");
treasureTypes[2] = new Label(" - Gold Bars 4pts");
treasureTypes[4] = new Label(" - Barrels of Rum 2pts");
treasureTypes[5] = new Label(" - Black card");
treasureTypes[6] = new Label(" - Red card");
for (int x = 0; x < treasureTypes.length; ++x) {
switch (x) {
case 0:
legend.add(new ImageView(new Image("group/project/images/diamond.png")), 0, x);
break;
case 1:
legend.add(new ImageView(new Image("group/project/images/diamond.png")), 0, x);
break;
case 2:
legend.add(new ImageView(new Image("group/project/images/pearls.jpg")), 0, x);
break;
case 3:
legend.add(new ImageView(new Image("group/project/images/gold_bar.png")), 0, x);
break;
case 4:
legend.add(new ImageView(new Image("group/project/images/diamond.png")), 0, x);
break;
case 5:
legend.add(new ImageView(new Image("group/project/images/diamond.png")), 0, x);
break;
case 6:
legend.add(new ImageView(new Image("group/project/images/diamond.png")), 0, x);
break;
}
legend.add(treasureTypes[x], 1, x);
}
legend.setPadding(new Insets(10.0, 10.0, 0.0, 50.0));
//top.getChildren().add(left);
//right buttons here
Button rules = new Button("Rules");
Button idk = new Button("Chance Card References");
VBox rightButtons = new VBox();
rightButtons.setAlignment(Pos.CENTER);
rightButtons.setMinWidth(200.0);
rightButtons.getChildren().addAll(rules, idk);
Label playerNames[] = new Label[4];
Label playerCoords[] = new Label[4];
Label playerMoveRange[] = new Label[4];
Label playerHomeTown[] = new Label[4];
Player pl;
for (int x = 0; x < 4; ++x) {
pl = gameEngine.getPlayer(x);
playerNames[x] = new Label();
playerCoords[x] = new Label();
playerMoveRange[x] = new Label();
playerHomeTown[x] = new Label();
//highlight the current player nickname
if (pl.getNickname().equals(gameEngine.getCurrentPlayer().getNickname())) {
playerNames[x].setTextFill(Color.GREEN);
} else {
//this is for reseting the color i.e the color is currently green
playerNames[x].setTextFill(Color.BLACK);
}
playerNames[x].setText("Player :" + pl.getNickname());
playerCoords[x].setText("Coordinates : ("
+ Integer.toString(pl.getShip().getCoordinates().getColumn() + 1)
+ ", " + Integer.toString(pl.getShip().getCoordinates().getRow() + 1) + ")");
playerMoveRange[x].setText("Player move range: " + pl.getMovementRange());
playerHomeTown[x].setText("Home town: " + pl.getShip().getHomeTown().getName());
playerInfo.add(playerNames[x], x, 0);
playerInfo.add(playerCoords[x], x, 1);
playerInfo.add(playerMoveRange[x], x, 2);
playerInfo.add(playerHomeTown[x], x, 3);
}
GridPane playerCards = new GridPane();
int numCards = 0;
int cardColor, cardVal;
for (Card c : gameEngine.getCurrentPlayer().getCards()) {
cardColor = (c.getColor()) ? 1 : 0;
cardVal = c.getValue();
Image cardImg = null;
switch (cardColor) {
case 0:
switch (cardVal) {
case 1:
cardImg = new Image("group/project/images/diamond.png");
break;
case 2:
cardImg = new Image("group/project/images/diamond.png");
break;
case 3:
cardImg = new Image("group/project/images/diamond.png");
break;
}
break;
case 1:
switch (cardVal) {
case 1:
cardImg = new Image("group/project/images/diamond.png");
break;
case 2:
cardImg = new Image("group/project/images/diamond.png");
break;
case 3:
cardImg = new Image("group/project/images/diamond.png");
break;
}
break;
}
playerCards.add(new ImageView(cardImg), numCards, 0);
++numCards;
}
playerCards.setPadding(new Insets(0.0, 10.0, 0.0, 75.0));
playerCards.setStyle("-fx-background-color: #FFFFFF;");
playerInfo.setStyle("-fx-background-color: red;");
playerInfo.setMaxHeight(100);
container.add(legend, 0, 0);
container.add(playerInfo, 1, 0);
container.add(rightButtons, 2, 0);
container.add(playerCards, 1, 1);
return container;
}
This is the whole function which returns a Node - GridPane and then is set as top of borderPane. i.e borderPane.setTop(getTop());
Related
I would like to know the way to span the next node in the second column after the node containing the label "Info" to the rest of the remaining columns and on 3 rows below.
Below is my present output with the associated code.
public class Test extends Application {
#Override
public void start(Stage primaryStage) {
GridPane root = new GridPane();
root.setGridLinesVisible(true);
final int numCols = 5 ;
final int numRows = 12 ;
for (int i = 0; i < numCols; i++) {
ColumnConstraints colConst = new ColumnConstraints();
colConst.setPercentWidth(100.0 / numCols);
root.getColumnConstraints().add(colConst);
}
for (int i = 0; i < numRows; i++) {
RowConstraints rowConst = new RowConstraints();
rowConst.setPercentHeight(100.0 / numRows);
root.getRowConstraints().add(rowConst);
}
Label nameLbl = new Label("Name");
Label nameFld = new Label();
Label infoLbl = new Label("Info : ");
Label infoFld = new Label();
infoFld.setStyle("-fx-background-color: lavender;-fx-font-size: 7pt;-fx-padding: 10 0 0 0;");
Button okBtn = new Button("OK");
Button cancelBtn = new Button("Cancel");
Label commentBar = new Label("Status: Ready");
commentBar.setStyle("-fx-background-color: lavender;-fx-font-size: 7pt;-fx-padding: 10 0 0 0;");
root.add(nameLbl, 0, 0, 1, 1);
root.add(nameFld, 1, 0, 1, 1);
root.add(infoLbl, 0, 1, 1, 1);
root.add(infoFld, 1, 1, 4, 4);
root.add(okBtn, 3, 9, 1, 1);
root.add(cancelBtn, 2, 9, 1, 1);
root.add(commentBar, 0, 11, GridPane.REMAINING, 1);
primaryStage.setScene(new Scene(root, 900, 500));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If you want the label to span four rows, as well as four columns, set its column span as well as its row span to 4:
// root.add(infoFld, 1, 1, 4, 1);
root.add(infoFld, 1, 1, 4, 4);
By default a label will not grow beyond its preferred size (which in this case is zero, because it has no text). Allow it to grow indefinitely:
infoFld.setMaxWidth(Double.MAX_VALUE);
infoFld.setMaxHeight(Double.MAX_VALUE);
Hope someone can help? I have read a number of SE posts on FileReader, Blobs, Base64 and EXIF and cobbled together something that is just about there. I am having problems understanding the structure of async functions and the order/delay in the process.
The script below loops through an uploaded array from a multi-part form. In the loop I have readAsDataURL to get Base64 String, and then attempting to readAsArrayBuffer to get the EXIF orientation code from the Blob before transforming a canvas.
I am clearly mixing up the async and getting a little lost.
At this stage it displays the images (and correctly orientates the first) but doesn't read the new EXIF orientation and all images are then rotated the same (presumably because the ArrayBuffer is not in sync?). If I upload more images at once there is some duplication which again must be a sync problem....
$(document).on('change', '#files', function(evt){
var files = evt.target.files;
var readerBase64;
var b64 = [];
var ab = [];
var c=0;
for (var i = 0; f = files[i]; i++) {
console.log('LOOP');
var blob = f;
var readerBase64 = new FileReader();
readerBase64.onload = function(evt){
// console.log('BASE 64 ' + evt.target.result);
b64.push(evt.target.result);
var reader = new FileReader();
reader.onloadend = (function(theFile) {
console.log(this);
console.log('READER');
return function(e) {
console.log('RETURN');
ab.push(e.target.result);
console.log(ab[c]);
var view = new DataView(ab[c]);
ori = 1;
if (view.getUint16(0, false) != 0xFFD8){ori = -2};
var length = view.byteLength,
offset = 2;
while (offset < length) {
var marker = view.getUint16(offset, false);
offset += 2;
if (marker == 0xFFE1) {
if (view.getUint32(offset += 2, false) != 0x45786966) {
ori = -1;
}
var little = view.getUint16(offset += 6, false) == 0x4949;
offset += view.getUint32(offset + 4, little);
var tags = view.getUint16(offset, little);
offset += 2;
for (var i = 0; i < tags; i++)
if (view.getUint16(offset + (i * 12), little) == 0x0112)
ori = view.getUint16(offset + (i * 12) + 8, little);
}
else if ((marker & 0xFF00) != 0xFF00) break;
else offset += view.getUint16(offset, false);
}
console.log('ori '+ori);
// console.log(b64[c]);
base64String = b64[c];
var img = document.createElement('img');
img.setAttribute('src',base64String);
//img.src = e.target.result;
img.onload = function () {
var canvas = document.createElement('canvas');
var MAX_WIDTH =1000;
var MAX_HEIGHT =800;
var width = img.width;
var height = img.height;
if (width > height) {
if (width > MAX_WIDTH) {
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
}
} else {
if (height > MAX_HEIGHT) {
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
}
}
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
// set proper canvas dimensions before transform & export
if (4 < ori && ori < 9) {
canvas.width = height;
canvas.height = width;
} else {
canvas.width = width;
canvas.height = height;
}
// transform context before drawing image
switch (ori) {
case 2: ctx.transform(-1, 0, 0, 1, width, 0); break;
case 3: ctx.transform(-1, 0, 0, -1, width, height ); break;
case 4: ctx.transform(1, 0, 0, -1, 0, height ); break;
case 5: ctx.transform(0, 1, 1, 0, 0, 0); break;
case 6: ctx.transform(0, 1, -1, 0, height , 0); break;
case 7: ctx.transform(0, -1, -1, 0, height , width); break;
case 8: ctx.transform(0, -1, 1, 0, 0, width); break;
default: break;
}
ctx.drawImage(img, 0, 0, width, height);
var dataurl = canvas.toDataURL("image/jpg");
//alert(dataurl);
// Render thumbnail.
var span = document.createElement('span');
//var ii = $('#list span').length - 2;
// if(ii > 0){
// span.setAttribute('class','hide');
// $('#list span:nth-child(3) p').text("+"+ii);
// }
span.innerHTML =
[
'<input type="image" class="thumb" name="imgs[]" value="',
dataurl,
'" src="', dataurl,
'"/>'
].join('');
document.getElementById('list').insertBefore(span, null);
c++;
}
}
})(f);
reader.readAsArrayBuffer(blob.slice(0, 64 * 1024));
}
readerBase64.readAsDataURL(f);
// console.log(f);
}
}); // Files change
I have solved it, but perhaps not very gracefully. The uploaded, resized and orientation corrected images are added to the form in an element named #list ready for posting to the server. Here is the code for anyone else:
$(document).on('change', '#files', function(evt){
var files = evt.target.files;
var f;
for (var i = 0; f = files[i]; i++) {
var blob = f;
getOrientation(f, function(ori , f) {
console.log(f);
var readerBase64 = new FileReader();
readerBase64.onload = function(evt){
console.log(ori);
console.log(evt.target.result);
base64String = evt.target.result;
var img = document.createElement('img');
img.setAttribute('src',base64String);
//img.src = e.target.result;
img.onload = function () {
var canvas = document.createElement('canvas');
var MAX_WIDTH =1000;
var MAX_HEIGHT =800;
var width = img.width;
var height = img.height;
if (width > height) {
if (width > MAX_WIDTH) {
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
}
} else {
if (height > MAX_HEIGHT) {
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
}
}
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
// set proper canvas dimensions before transform & export
if (4 < ori && ori < 9) {
canvas.width = height;
canvas.height = width;
} else {
canvas.width = width;
canvas.height = height;
}
// transform context before drawing image
switch (ori) {
case 2: ctx.transform(-1, 0, 0, 1, width, 0); break;
case 3: ctx.transform(-1, 0, 0, -1, width, height ); break;
case 4: ctx.transform(1, 0, 0, -1, 0, height ); break;
case 5: ctx.transform(0, 1, 1, 0, 0, 0); break;
case 6: ctx.transform(0, 1, -1, 0, height , 0); break;
case 7: ctx.transform(0, -1, -1, 0, height , width); break;
case 8: ctx.transform(0, -1, 1, 0, 0, width); break;
default: break;
}
ctx.drawImage(img, 0, 0, width, height);
var dataurl = canvas.toDataURL("image/jpg");
//alert(dataurl);
// Render thumbnail.
var span = document.createElement('span');
//var ii = $('#list span').length - 2;
// if(ii > 0){
// span.setAttribute('class','hide');
// $('#list span:nth-child(3) p').text("+"+ii);
// }
span.innerHTML =
[
'<input type="image" class="thumb" name="imgs[]" value="',
dataurl,
'" src="', dataurl,
'"/>'
].join('');
document.getElementById('list').insertBefore(span, null);
}
};
readerBase64.readAsDataURL(f);
});
}
});
Using the function I found on here with a minor change to send the file Blob back with the orientation in the callback:
//from http://stackoverflow.com/a/32490603
function getOrientation(file, callback) {
var reader = new FileReader();
reader.onload = function(event) {
var view = new DataView(event.target.result);
if (view.getUint16(0, false) != 0xFFD8) return callback(-2, file);
var length = view.byteLength,
offset = 2;
while (offset < length) {
var marker = view.getUint16(offset, false);
offset += 2;
if (marker == 0xFFE1) {
if (view.getUint32(offset += 2, false) != 0x45786966) {
return callback(-1 , file);
}
var little = view.getUint16(offset += 6, false) == 0x4949;
offset += view.getUint32(offset + 4, little);
var tags = view.getUint16(offset, little);
offset += 2;
for (var i = 0; i < tags; i++)
if (view.getUint16(offset + (i * 12), little) == 0x0112)
return callback(view.getUint16(offset + (i * 12) + 8, little) , file);
}
else if ((marker & 0xFF00) != 0xFF00) break;
else offset += view.getUint16(offset, false);
}
return callback(-1 , file);
};
reader.readAsArrayBuffer(file.slice(0, 64 * 1024));
};
The solution for the upload was to intercept the post and use AJAX and JQuery to build the POST data from the input[type='image']
$(document).on('submit',function(e){
e.preventDefault();
var data = $('#formFeed').serializeArray();
var msg = $('textarea').val();
data.push({name: 'msg', value: msg});
var y;
$('input[type="image"]').each(function(i, obj) {
y = $(this).attr('src');
data.push({name: 'img', value: y});
});
$.ajax({
cache: false,
type : 'POST',
url : 'http://localhost:3001/newFeed',
data: data,
contentType: "application/x-www-form-urlencoded",
success : function(data) {
console.log(data);
}
});
});
Trying to create dynamically a series of circles with Javafx. After typing the number of circles i got this:
But actually i want that my circles be in that position:
Here is my code and thanks for any hints!!
int k = 5;
for (int i = 0; i < nbNoeuds; i++) {
Noeudfx circle = new Noeudfx(k * 2, k * 2, 1, String.valueOf(i));
Label id = new Label(String.valueOf(i));
noeuds.getChildren().add(id);
id.setLayoutX(k * 2 - 20);
id.setLayoutY(k * 2 - 20);
id.setBlendMode(BlendMode.DIFFERENCE);
k += 10;
FillTransition ft1 = new FillTransition(Duration.millis(300), circle, Color.RED, Color.BLACK);
ft1.play();
noeuds.getChildren().add(circle);
ScaleTransition tr = new ScaleTransition(Duration.millis(100), circle);
tr.setByX(10f);
tr.setByY(10f);
tr.setInterpolator(Interpolator.EASE_OUT);
tr.play();
}
}
public class Noeudfx extends Circle {
Noeud noeud;
Point point;
Label distance = new Label("distance : infinite");
boolean isSelected = false;
List<Noeudfx> circles = new ArrayList<>();
public Noeudfx(double a, double b, double c, String nom) {
super(a, b, c);
noeud = new Noeud(nom, this);
point = new Point((int) a, (int) b);
circles.add(this);
}
}
Here is my solution:
int nbNoeuds = Integer.parseInt(nodeID.getText());
System.out.println("nnnnn"
+ nbNoeuds);
final Timeline animation = new Timeline(
new KeyFrame(Duration.seconds(.5), (ActionEvent actionEvent) -> {
while (noeuds.getChildren().size() <= nbNoeuds) {
// noeuds.getChildren().remove(0);
int radius =10 ;
noeuds.getChildren().add(
new Circle(
rnd.nextInt(SCENE_SIZE - radius * 2) + radius, rnd.nextInt(SCENE_SIZE - radius * 2) + radius,
radius,
Color.GRAY
)
);
}
})
);
animation.setCycleCount(Animation.INDEFINITE);
animation.play();
animation.setOnFinished((ActionEvent actionevent) -> {
animation.stop();
});
Update: i tried to add label to each circle, the problem was that the number of circles in the screen is not correct i don't know why!
Label id = new Label(String.valueOf(i));
id.setTextFill(Color.CADETBLUE);
id.setAlignment(Pos.CENTER);
Circle circle = new Circle(
rnd.nextInt(SCENE_SIZE - radius * 2) + radius, rnd.nextInt(SCENE_SIZE - radius * 2) + radius,
radius,
Color.GRAY
);
Double a = circle.getCenterX();
Double b = circle.getCenterY();
id.setLayoutX(a - 20);
id.setLayoutY(b - 20);
id.setBlendMode(BlendMode.DIFFERENCE);
noeuds.getChildren().add(id);
noeuds.getChildren().add(circle);
I'm having a dilemma with this code and have no clue what to do. I'm pretty new to processing. This is a project from this link...
http://blog.makezine.com/2012/08/10/build-a-touchless-3d-tracking-interface-with-everyday-materials/
any help is massively appreciated... Thanks in advance
import processing.serial.*;
import processing.opengl.*;
Serial serial;
int serialPort = 1;
int sen = 3; // sensors
int div = 3; // board sub divisions
Normalize n[] = new Normalize[sen];
MomentumAverage cama[] = new MomentumAverage[sen];
MomentumAverage axyz[] = new MomentumAverage[sen];
float[] nxyz = new float[sen];
int[] ixyz = new int[sen];
float w = 256; // board size
boolean[] flip = {
false, true, false};
int player = 0;
boolean moves[][][][];
PFont font;
void setup() {
size(800, 600, P3D);
frameRate(25);
font = loadFont("TrebuchetMS-Italic-20.vlw");
textFont(font);
textMode(SCREEN);
println(Serial.list());
serial = new Serial(this, Serial.list()[serialPort], 115200);
for(int i = 0; i < sen; i++) {
n[i] = new Normalize();
cama[i] = new MomentumAverage(.01);
axyz[i] = new MomentumAverage(.15);
}
reset();
}
void draw() {
updateSerial();
drawBoard();
}
void updateSerial() {
String cur = serial.readStringUntil('\n');
if(cur != null) {
String[] parts = split(cur, " ");
if(parts.length == sensors) {
float[] xyz = new float[sen];
for(int i = 0; i < sen; i++)
xyz[i] = float(parts[i]);
if(mousePressed && mouseButton == LEFT)
for(int i = 0; i < sen; i++)
n[i].note(xyz[i]);
nxyz = new float[sen];
for(int i = 0; i < sen; i++) {
float raw = n[i].choose(xyz[i]);
nxyz[i] = flip[i] ? 1 - raw : raw;
cama[i].note(nxyz[i]);
axyz[i].note(nxyz[i]);
ixyz[i] = getPosition(axyz[i].avg);
}
}
}
}
float cutoff = .2;
int getPosition(float x) {
if(div == 3) {
if(x < cutoff)
return 0;
if(x < 1 - cutoff)
return 1;
else
return 2;
}
else {
return x == 1 ? div - 1 : (int) x * div;
}
}
void drawBoard() {
background(255);
float h = w / 2;
camera(
h + (cama[0].avg - cama[2].avg) * h,
h + (cama[1].avg - 1) * height / 2,
w * 2,
h, h, h,
0, 1, 0);
pushMatrix();
noStroke();
fill(0, 40);
translate(w/2, w/2, w/2);
rotateY(-HALF_PI/2);
box(w);
popMatrix();
float sw = w / div;
translate(h, sw / 2, 0);
rotateY(-HALF_PI/2);
pushMatrix();
float sd = sw * (div - 1);
translate(
axyz[0].avg * sd,
axyz[1].avg * sd,
axyz[2].avg * sd);
fill(255, 160, 0);
noStroke();
sphere(18);
popMatrix();
for(int z = 0; z < div; z++) {
for(int y = 0; y < div; y++) {
for(int x = 0; x < div; x++) {
pushMatrix();
translate(x * sw, y * sw, z * sw);
noStroke();
if(moves[0][x][y][z])
fill(255, 0, 0, 200);
else if(moves[1][x][y][z])
fill(0, 0, 255, 200);
else if(
x == ixyz[0] &&
y == ixyz[1] &&
z == ixyz[2])
if(player == 0)
fill(255, 0, 0, 200);
else
fill(0, 0, 255, 200);
else
fill(0, 100);
box(sw / 3);
popMatrix();
}
}
}
fill(0);
if(mousePressed && mouseButton == LEFT)
msg("defining boundaries");
}
void keyPressed() {
if(key == TAB) {
moves[player][ixyz[0]][ixyz[1]][ixyz[2]] = true;
player = player == 0 ? 1 : 0;
}
}
void mousePressed() {
if(mouseButton == RIGHT)
reset();
}
void reset() {
moves = new boolean[2][div][div][div];
for(int i = 0; i < sen; i++) {
n[i].reset();
cama[i].reset();
axyz[i].reset();
}
}
void msg(String msg) {
text(msg, 10, height - 10);
}
You are missing a class, in fact, more than one. Go back to the github and download, or copy and paste, all three codes, placing each one in a new tab named same name of the class (well this is not required, but is a good practice). The TicTacToe3D.pde is the main code. To make a new tab choose "new tab" from the arrow menu in Processing IDE (just below the standard button at the right). The code should run. WIll need an Arduino though to really get it working.
in page cap.aspx
==========================================================================
string code = GetRandomText();
Bitmap bitmap = new Bitmap(160,50,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
Pen pen = new Pen(Color.LavenderBlush);
Rectangle rect = new Rectangle(0,0,160,50);
SolidBrush b = new SolidBrush(Color.LightPink);
SolidBrush blue = new SolidBrush(Color.White);
int counter = 0;
g.DrawRectangle(pen, rect);
g.FillRectangle(b, rect);
for (int i = 0; i < code.Length; i++)
{
g.DrawString(code[i].ToString(), new Font("Tahoma", 10 + rand.Next(14, 18)), blue, new PointF(10 + counter, 10));
counter += 20;
}
DrawRandomLines(g);
bitmap.Save(Response.OutputStream,ImageFormat.Gif);
g.Dispose();
b.Dispose();
blue.Dispose();
bitmap.Dispose();
===================================================================================
<div id="DIVdialog" style="display:none">
<img src="cap.aspx"/>
</div>
===================================================================================
$("#DIVdialog").dialog();
==================================================================================
show dialog but does not show image? address cap.aspx is correct!
how get cap.aspx by $.ajax and datatype:image?
I think that the key here is to add the ContentType and the BufferOutput
context.Response.ContentType = "image/gif";
context.Response.BufferOutput = false;
Eg:
public void RenderIt(HttpContext context)
{
context.Response.ContentType = "image/gif";
context.Response.BufferOutput = false;
string code = GetRandomText();
using(Bitmap bitmap = new Bitmap(160,50,System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using(Graphics g = Graphics.FromImage(bitmap))
{
using(Pen pen = new Pen(Color.LavenderBlush)
{
using(SolidBrush b = new SolidBrush(Color.LightPink))
{
using(SolidBrush blue = new SolidBrush(Color.White))
{
Rectangle rect = new Rectangle(0,0,160,50);
int counter = 0;
g.DrawRectangle(pen, rect);
g.FillRectangle(b, rect);
for (int i = 0; i < code.Length; i++)
{
g.DrawString(code[i].ToString(), new Font("Tahoma", 10 + rand.Next(14, 18)), blue, new PointF(10 + counter, 10));
counter += 20;
}
DrawRandomLines(g);
g.Dispose();
b.Dispose();
blue.Dispose();
// Return
bitmap.Save(context.Response.OutputStream, ImageFormat.Gif);
// Dispose
bitmap.Dispose();
}
}
}
}
}
context.Response.End();
}