In this jsfiddle I have a Raphael canvas with two images. The first one is the complete image (not clipped) and the second one is the same image but clipped. For some reason the second image is not showing up. What's wrong with this code?
javascript:
var paper = Raphael(document.getElementById('canvas'));
var img = paper.image('http://designsbynickthegeek.com/wp-content/uploads/2012/01/social-header.png', 0, 0, 480, 259 );
var img2 = paper.image('http://designsbynickthegeek.com/wp-content/uploads/2012/01/social-header.png', 0, 300, 40, 40 );
img2.attr({'clip-rect': "0,0,40,40" });
You made two mistakes.
First: You scaled your image down. Change
var img2 = paper.image('http://designsbynickthegeek.com/wp-content/uploads/2012/01/social-header.png',
0, 300, 40, 40 );
to
var img2 = paper.image('http://designsbynickthegeek.com/wp-content/uploads/2012/01/social-header.png',
0, 300, 480, 259 );
Second: You used the wrong clipping coordinates. Change
img2.attr({'clip-rect': "0,0,40,40" });
to
img2.attr({'clip-rect': "0,300,40,40" });
see your edited fiddle here.
Related
I need to print a grid like the one in the photo on a PDF document
I am using CIMG to create the image in bmp, then save it as jpg and paste it in the PDF using JagPDF
The code for the graph is as follows:
int lineseparation=3;
int lineseparationbold=lineseparation*5;
CImg<unsigned char> graph1;
graph1.assign(50*lineseparationbold+1, 28*lineseparationbold+1, 1, 3, 255);
static const unsigned char black[] = { 0, 0, 0 }, white[] = { 255, 255, 255 };
static const unsigned char gray2[] = { 110, 110, 110 }, ngray[] = { 35, 35, 35 }, gray[] = { 220, 220, 220 };
static const unsigned char red[] = { 255, 200, 200 }, bred[] = { 255, 100, 100 };
graph1.draw_grid(lineseparation, lineseparation, 0, 0, false, true, red, 10.0f, 0xFFFFFFFF, 0xFFFFFFFF);
graph1.draw_grid(lineseparationbold, lineseparationbold, 0, 0, false, true, bred, 10.0f, 0xFFFFFFFF, 0xFFFFFFFF);
graph.save("plot.bmp");
Then after saving it as JPG I put it in the PDF using jagPDF this way:
pdf::Document doc(pdf::create_file("report.pdf"));
doc.page_start(pagewidth, pageheight);
pdf::Image imag2 = doc.image_load_file("plot1.jpg");
doc.page().canvas().image(imag2, 10, 50);
doc.page_end();
doc.finalize();
I need the grid to be 1mm separation between the lines (5mm the bold ones), when I put 3 pixels as separation when I print it is a little more than 1mm and if I put 2 pixels then is less than 1mm.
Putting non integers (e.g int lineseparation=2.9;) as input allow me to get bold lines closer to 5mm but the small lines are uneven. Saving the figure as BMP and resizing it is messing with the grid.
How can I make it print in the correct size?
Note: BMP and JPG have same size in pixels. I do the convertion without any resizing (although I tried that too).
I want to create one canvas widget, which allows user to draw on it. I am using canvas.bind for it. What I want is the size of canvas should be 32x32 originally, but when it is displayed, it should be like zoomed version of original widget, without resizing the original canvas. I have to use smaller size ( 32x32 ) for further processing on the drawn picture. Meaning if canvas size is 32x32 then it should be displayed as 512x512 size for drawing purpose , but 32x32 size for processing purpose. I tried with canvas.Scale but it seems that it will not be helpful for this purpose because it resizes original widget. Can someone please guide me? I use python2.7.
Thanks!
If I completely understand your problem, then I think this would be your solution:
from __future__ import division
import Tkinter
ORIGINAL_WIDTH = 32
ORIGINAL_HEIGHT = 32
WINDOW_WIDTH = 512
WINDOW_HEIGHT = 512
WIDTH_RATIO = WINDOW_WIDTH/ORIGINAL_WIDTH
HEIGHT_RATIO = WINDOW_HEIGHT/ORIGINAL_HEIGHT
class App(Tkinter.Tk):
def __init__(self, *args, **kwargs):
Tkinter.Tk.__init__(self, *args, **kwargs)
self.canvas = canvas = Tkinter.Canvas( self,
highlightthickness = 0,
width = WINDOW_WIDTH,
height = WINDOW_HEIGHT )
self.canvas.pack()
# Create a list for holding canvas objects
self.scene = []
# Draw objects and scale them
self.draw()
self.zoom()
def draw(self):
canvas = self.canvas
# Draw rectangles within the range of 0..32 x 0..32
rect1 = canvas.create_rectangle( 2, 0, 30, 2, fill='black' )
rect2 = canvas.create_rectangle( 0, 2, 2, 30, fill='black' )
rect3 = canvas.create_rectangle( 30, 2, 32, 30, fill='black' )
rect4 = canvas.create_rectangle( 2, 30, 30, 32, fill='black' )
rect5 = canvas.create_rectangle( 10, 10, 22, 22, fill='black' )
self.scene.extend( (rect1, rect2, rect3, rect4, rect5) )
def zoom(self):
canvas = self.canvas
# Scale all objects on scene
for item in self.scene:
canvas.scale( item, 0, 0, WIDTH_RATIO, HEIGHT_RATIO )
App().mainloop()
I'm newbie in cocos2d-x and I need your help.
I need to make transparent a touched portion of the layer.
How to make a portion of the layer transparent? I had thought to use ССClippingNode, but I'm not find examples or docs.
I use C++. Thanks.
In TestCpp, project that was added to all cocos2d-x version, you can find examples of CCClipingNode.
If you want to hide part of CCNode(for example "layer") using CCClipingNode, you should add your layer to CCClipingNode.
This is the example that you can paste in the HelloWorld init:
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
addChild(CCLayerColor::create(ccc4(122, 144, 0, 255), visibleSize.width, visibleSize.height));
//this is the layer that we want to "cut"
CCLayer *layer = CCLayer::create();
CCSprite* pSprite = CCSprite::create("HelloWorld.png");
pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
layer->addChild(pSprite, 0);
//we need to create a ccnode, which will be a stencil for ccclipingnode, draw node is a good choice for that
CCDrawNode * stecil = CCDrawNode::create();
stecil->drawDot(ccp(visibleSize.width/2 + origin.x - 100, visibleSize.height/2 + origin.y), 30, ccc4f(0, 0, 0, 255));
stecil->drawSegment(ccp(0, 0), ccp(visibleSize.width, visibleSize.height), 20, ccc4f(0, 0, 0, 255));
//CCClipingNode show the intersection of stencil and theirs children
CCClippingNode *cliper = CCClippingNode::create(stecil);
//you want to hide intersection so we setInverted to true
cliper->setInverted(true);
cliper->addChild(layer);
addChild(cliper);
return true;
}
I have to draw a String on a transparent bitmap at first, then draw A to destination canvas.
However on certain case, there is black border around the characters.
Bitmap* tempImg = new Bitmap(1000, 1000, PixelFormat32bppARGB);
Graphics tempGr(tempImg);
tempGr.Clear(Color(0, 255,255,255));
Gdiplus::SolidBrush* brush = new SolidBrush(Color(255, 255, 0, 0 ));
Gdiplus::FontFamily fontFamily(L"Times New Roman");
Gdiplus::Font* font = new Gdiplus::Font(&fontFamily, 19, FontStyleRegular, UnitPixel);
RectF rec(400, 400, 1000, 10000);
tempGr.DrawString(
L"Merry Chrismas",
-1,
font,
rec,
NULL,
brush
);
Graphics desGr(hdc);
desGr.Clear(Color::Gray);
desGr.DrawImage(tempImg , 0,0, 1000, 1000);
The character draw on desGr have black board for some fontsize.
How can I avoid this problem?
Many thanks!
I think the problem here is that you are drawing the text onto a transparent background.
You could try adding this line after the call to tempGr.Clear...
tempGr.TextRenderingHint = TextRenderingHint.AntiAlias;
ps - sorry not sure the exact syntax in C++ ;)
I just solved this problem in XNA:
Clear background to the same as the foreground color. The only difference is that the background should have Alpha=0, and the foreground with Alpha >> 0
The black border comes from blending of your background and foreground of different colors. Try to clear the background to some contrasting color to fully appreciate the phenomenon.
I have a rounded rectangle that I make like so
dc.RoundRect(textBorder, CPoint(20, 20));
Later on I draw a line through it about 1/3 of the way down.
dc.LineTo(textBorder.right, textBorder.top + 15);
Now I would like to fill just the part above the line with a solid color. In other words I need to fill a partially rounded rectangle, because the top of the rectangle is rounded, but the bottom of it is truncated by the line. Is there an easy way to do this?
Have you tried using a combination of CreateRoundRectRegion and then FillRgn to fill the non-rectangular area?
This the example given in the docs for CreateRoundRectRegion:
CRgn rgnA, rgnB, rgnC;
VERIFY(rgnA.CreateRoundRectRgn( 50, 50, 150, 150, 30, 30 ));
VERIFY(rgnB.CreateRoundRectRgn( 200, 75, 250, 125, 50, 50 ));
VERIFY(rgnC.CreateRectRgn( 0, 0, 50, 50 ));
int nCombineResult = rgnC.CombineRgn( &rgnA, &rgnB, RGN_OR );
ASSERT( nCombineResult != ERROR && nCombineResult != NULLREGION );
CBrush brA, brB, brC;
VERIFY(brA.CreateSolidBrush( RGB(255, 0, 0) ));
VERIFY(pDC->FillRgn( &rgnA, &brA)); // rgnA Red Filled
VERIFY(brB.CreateSolidBrush( RGB(0, 255, 0) ));
VERIFY(pDC->FillRgn( &rgnB, &brB)); // rgnB Green Filled
VERIFY(brC.CreateSolidBrush( RGB(0, 0, 255) )); // rgnC Blue
VERIFY(pDC->FrameRgn( &rgnC, &brC, 2, 2 ));
In general, when you want to do something with non-rectangular areas you have to start looking into regions.