I have an ASP.NET web application that display some images. For thumbnail display, I have to resize them. Here is my code:
var newImage = new Bitmap(sourceImage, width, height);
var g = Graphics.FromImage(newImage);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height);
newImage.Save(path,GetEncoder(ImageFormat.Jpeg), myEncoderParameters);
Everything looks ok if I run in LOCALHOST. However, when I publish on server, the image quality is very poor and broken.
As Microsoft documentation (http://msdn.microsoft.com/en-us/library/system.drawing.graphics.smoothingmode%28v=vs.110%29.aspx), the System.Drawing namespace is not support for some platform, but seems like that's not my case (I'm not very sure). This is my server system specification: http://i.stack.imgur.com/ByVZ1.jpg (Please follow the link, I do not have enough reputation to post image).
Can anyone please help me with this. Thanks very much.
Add the following to your Graphics settings.
g.CompositingQuality = CompositingQuality.HighQuality;
I'm thinking CompositingQuality.Default may be different between your two machines.
Graphics.CompositingQuality Documentation
I got an answer by myself. The problem is when I call
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height);
It will draw an resized image into itself, that is the object:
new Bitmap(sourceImage, width, height));
so all the settings of the graphic object is not affected. The resize functioned actually at the above line of code.
The correct solution should be:
g.DrawImage(sourceImage, 0, 0, newImage.Width, newImage.Height);
And everything works now.
Related
Sample image of qr code embedded over given image
So i am working with qr codes in my project and I need to superimpose my qr code over an image. Example image is attached. I generated this from an online qr code generator. Which libraries can i use to generate such such images either in a web application or a mobile application?
You can use any GD library provided by any programming language. What you're looking for is Watermarking. Some examples are:
C#
You can follow this article using GDI for .NET.
PHP
Example directly from manual.
<?php
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
I am trying to create a PostScript file using the Apache xml-graphics library. When I run under Java, it works fine.
But when I build for .NET using IKVM, then on a call to GlyphVector.getoutline(x, y), the code never returns.
This is happening when I:
AttributedString as = new AttributedString(buf.toString());
// call as.addAttribute() setting various TextAttribute for various ranges
FontRenderContext frc = graphics.getFontRenderContext();
LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(as.getIterator(), frc);
TextLayout layout = lineMeasurer.nextLayout(Integer.MAX_VALUE);
layout.draw (graphics, left, line.getBaseline());
Any idea what can be going wrong?
thanks - dave
I am developing an applications toolbar in QT 4.8.5 (this version is mandatory for my client) on a SLED 11.
I am also in a multimonitor environment.
My purpose is to show an extended toolbar on a specified monitor and a reduced one on the others.
From the main toolbar is possibile to open different applications installed in the system. These applications can be QT based or not.
In order to make xserver to handle the toolbar as a docking window and reserve the space on the desktop (so the other windows cannot be moved on the toolbar and make the window maximization not cover the toolbar) I used some xlib call.
This is the way I reserved the space:
void ToolbarWindow::dock(int x, int y, int width, int height)
{
#ifdef Q_WS_X11 //only define on Qt 4.X
Display *display = QX11Info::display();
// Change the window type in order to make it DOCK.
Atom tmp = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DOCK", False);
XChangeProperty(display,
winId(),
XInternAtom(display, "_NET_WM_WINDOW_TYPE", False),
XA_ATOM ,
32,
PropModeReplace,
(unsigned char *)&tmp, 1);
// Reserve the space.
// [0]left, [1]right, [2]top, [3]bottom, [4]left_start_y, [5]left_end_y, [6]right_start_y, [7]right_end_y, [8]top_start_x, [9]top_end_x, [10]bottom_start_x, [11]bottom_end_x
long insets[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
insets[2] = height;
insets[8] = x;
insets[9] = x+width;
XChangeProperty(display,
winId(),
XInternAtom(display, "_NET_WM_STRUT", False),
XA_CARDINAL ,
32,
PropModeReplace,
(unsigned char *)&insets, 4);
XChangeProperty(display,
winId(),
XInternAtom(display, "_NET_WM_STRUT_PARTIAL", False),
XA_CARDINAL ,
32,
PropModeReplace,
(unsigned char *)&insets, 12);
#endif
}
Everything seems to work fine, but after some tests I had a big problem with the QT dropdown menu.
It seems that, when QT calculate the position of a dropdown it consider the max reserved height independently of the monitor the window is in.
Here there are two images showing the problem.
The first image show that the problem can be test even in QTCreator dropdown menu.
The second image show a test I made in order to see what happened on combobox dropdown on a custom QMainWindow.
The problem seems to be the same.
I can also add that moving the window beneath the height of the main toolbar on the second monitor the dropdown position is correct.
Moreover other non-QT application DO NOT have this behavior, so I think this is a QT 4.8.5 problem during the dropdown positioning.
I also found similar bugs related to Mac OS X.
I do not know if these bugs can be meaningful but I will list them anyway:
https://bugreports.qt.io/browse/QTBUG-36672
https://bugreports.qt.io/browse/QTBUG-36984
https://bugreports.qt.io/browse/QTCREATORBUG-11364
Anyone can help me found out a solution to this problem?
Thanks a lot.
This Qt bug looks very similar: QMenu size is not shown properly on dual monitor and one with lower resolution.
It includes a patch for Qt (although it may be out of date now) which may correct it.
I made a tilemap. and used it on cocos2d-js.
Just added
this._map = new cc.TMXTiledMap(res.tilemap);
this.addChild(this._map, 0, 1);
in Layer.
But When I use this image,
http://i.imgur.com/f5VG0Nr.png,
http://i.imgur.com/Ugg9GNq.png
this error occured.
[.WebGLRenderingContext]RENDER WARNING: texture bound to texture
unit 0 is not renderable. It maybe non-power-of-2 and have incompatible
texture filtering or is not 'texture complete'
But When I used other image, it works.
like
http://i.imgur.com/Grv0srJ.png,
http://i.imgur.com/v1eWdkE.png,
http://i.imgur.com/BXKRbVx.png
I changed tilemap many times with that images, but same result.
I don't know what is diffrent that images.
Please help me.
Have you tried I believe I encountered this error once:
Have you tried adding all the image files in your resources.js file?
With the following code, on my workstation (QtCreator an "manually" running) all works fine. But on an other pc with no Qt installation my application don't show the QGraphicsPixmapItem.
image = new QGraphicsPixmapItem(QPixmap(urlFile));
image->setZValue(-5000.0);
scene->setSceneRect(QRectF(0, 0, image->pixmap().width() + 200, image->pixmap().height() + 200));
scene->addItem(image);
view->setMaximumWidth(image->pixmap().width() + 200);
view->setMaximumHeight(image->pixmap().height() + 200);
qreal centerX = (scene->width() / 2.0) - (image->pixmap().width() /2.0);
qreal centerY = (scene->height() / 2.0) - (image->pixmap().height() /2.0);;
image->setOffset(QPointF(centerX, centerY));
Do you know why ?
I Know why :)
The folowing dll are needed to use jpg and gif : qgif4.dll, qjpeg4.dll.
In fact, a deployed application support by default, only the following formats : bmp, pbm, png, ppm, xbm, xpm.
The previously dll could be find in QTDIR/qt/plugins/imageformats/
To add the support of other image formats to your deployed application, create a imageformats/ directory on the same level of your executable and put your wanted dll in.