GithubHelp home page GithubHelp logo

Sliding over SVG? about lunasvg HOT 18 CLOSED

sammycage avatar sammycage commented on July 22, 2024
Sliding over SVG?

from lunasvg.

Comments (18)

sammycage avatar sammycage commented on July 22, 2024 2

@erentknn With the latest commit you can now do this 7a175d4

Bitmap bitmap{width, height};
Matrix matrix{1, 0, 0, 1, -x, -y};
document->render(bitmap, matrix);

Hope that this will solve this problem.

from lunasvg.

erentknn avatar erentknn commented on July 22, 2024 1

sure, svg.zip

from lunasvg.

erentknn avatar erentknn commented on July 22, 2024 1

Here it is, for explanation x and y are the original coordinates in the original image (think like I have 40k x 40k image and this is a small piece in it) and I am shifting to that coordinates so I can render the right place. It's the same as in svgImage->translate(). But I provided this in the svg file for you so probably those are, shifting coordinates, unnecessary now. I hope that has been explanatory.

	const auto svgStrPtr = new char[svgStr.length() + 1];
	svgStrPtr[svgStr.length()] = '\0';
	strcpy(svgStrPtr, svgStr.c_str());
	nsvgImage = nsvgParse(svgStrPtr, "px", 96.0f);

	auto rast = nsvgCreateRasterizer(); // Create rasterizer
	auto img = static_cast<unsigned char*>(malloc(widthCalc * heightCalc * 4)); 
	nsvgRasterize(rast, nsvgImage, -x, -y, 1, img, widthCalc, heightCalc, widthCalc * 4); 
	auto res = cv::Mat(heightCalc, widthCalc, CV_8UC4);
	res.data = img;
	cv::cvtColor(res, res, CV_RGBA2GRAY);
	res = res > 0;
	nsvgDeleteRasterizer(rast); 
	free(img);

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024 1

Thanks. I will work on it this weekend.

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

Please can you give me the SVG file

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

sure, svg.zip

The SVG renders nothing
a svg

from lunasvg.

erentknn avatar erentknn commented on July 22, 2024

oops, sorry. fixed it now: svg.zip

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

With nanosvg I could do this with no overhead.

Please can you give me the nanosvg example code so that I can fully understand what you are trying to do.

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

@erentknn if you are still having issues. Please let me know

from lunasvg.

erentknn avatar erentknn commented on July 22, 2024

Hey @sammycage, thank you for quick response. but unfortunately it's still not working. I am using the same code as above.

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

Sample code

auto document = Document::loadFromData("a.svg");
document->translate(-50, -50);

Before :

a svg

After :

after svg

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

But I provided this in the svg file for you so probably those are, shifting coordinates, unnecessary now.

Please make sure that you are not using the modified file

from lunasvg.

erentknn avatar erentknn commented on July 22, 2024

I think I explained the problem wrong. Translating works OK. What I am trying to do is sliding over the SVG Image, with nanosvg in my first output is like this:
aa

and second is this:
ab2

Second image is the tagged area (approximately):
axf

Like this, I want to loop on the whole SVG tile by tile.
BTW after your modification I can't get any output. Just blank image.

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

@erentknn Did you mean Scaling?

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

@erentknn is the height and width in lunasvg::Bitmap bitmap = svgImage->renderToBitmap(width, height) different from the one in the file.

from lunasvg.

sammycage avatar sammycage commented on July 22, 2024

However I want to process this normally big (7k x 7k) image tile by tile.

Now I understand what you are trying to do

Use Document::render instead

Example :

Bitmap bitmap{width, height};
document->translate(-x, -y);
document->render(bitmap);

from lunasvg.

erentknn avatar erentknn commented on July 22, 2024

@erentknn is the height and width in lunasvg::Bitmap bitmap = svgImage->renderToBitmap(width, height) different from the one in the file.

Yes, width and height are 1024.

Now I understand what you are trying to do

Use Document::render instead

Example :

Bitmap bitmap{width, height};
document->translate(-x, -y);
document->render(bitmap);

Now I can render the first tile correctly. But after that it's blank image again.

from lunasvg.

erentknn avatar erentknn commented on July 22, 2024

THANK YOU, It worked as expected.

from lunasvg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.