question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about PixelDensity

See original GitHub issue

thanks for this library, its cool.

I ran into something - if I set pixelDensity(displayDensity()); in my sketch to work in HiDPI , seems that the imageprocessing library might not be compatible, it throws a lot of exceptions with TiltShift , Threshold, etc.

Do I need to set something in the constructor?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Milchreiscommented, Apr 9, 2020

Thank you for your reply.

I took over the MacBook of my lovly wife ❤️ and do some tests. The main problem is, that createGraphics sets the pixelWidth and pixelHeight values for PGraphics depending on the pixelDensity-value. Instead PImage has pixelWidth and pixelHeight regular.

In the end the line sharp.mask() fails, because the two images have different dimensions.

With f2f1a4dfc670b5f7315fdd7891de2765f9ca932b I commited a workarround to avoid that error. Instead of image.copy() I wrote a method to copy an image by redrawing it on PGraphics. In that way the result has the same width and height attributes.

For Classes that using PGraphics I could not reproduce this error.

0reactions
cristianvogelcommented, Apr 7, 2020

delving deeper into some debugging… this issue affects TiltShift ( this one I use its very cool ) and Blend and the others that create off screen PGraphics

public class TiltShift {

	public static PImage createMask(PImage image, int blurIntensity, boolean horizontal, int position, int width) {
		
		PGraphics mask = image.parent.createGraphics(image.width, image.height);
		PApplet main = image.parent;
		
		int c1 = 255;
		int c2 = 0;
		
		mask.beginDraw();
		mask.background(0);
		
		for (int i = 0; i <= width; i++) {
			float inter = PApplet.map(i, 0, width, 0, 1);
			int c = main.lerpColor(c1, c2, inter);
			mask.stroke(c);

			if (horizontal) { 
				// Top to bottom gradient
				mask.line(0, position + i, image.width, position + i);
				mask.line(0, position - i, image.width, position - i);
				
			} else { 
				// Left to right gradient
				mask.line(position + i, 0, position + i, image.height);
				mask.line(position - i, 0, position - i, image.height);
			}
		}
		
		mask.endDraw();
		
		return mask.get();

when TiltShift is applied and PixelDensity is 2, then that PGraphics mask = image.parent.createGraphics(image.width, image.height); seems to fail…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pixel Density, Demystified - Medium
Pixel density refers to how many pixels have been… ... and consider this question: should a button always be the same physical size...
Read more >
Question about pixel density : r/buildapc - Reddit
This leads me to my question.Would a 1080p 32 inch screen look good or would the 1080 pixels be too stretched out across...
Read more >
[Solved] What is Pixel density? - Testbook.com
This question was previously asked in. UGC NET Paper 1: Held on 4th Jan 2022 Shift 2 ... Pixel density is commonly measured...
Read more >
View question - pixel density
What is the pixel density (in PPI) for a mobile device which has a screen size of 4 inches on the diagonal and...
Read more >
Solved Question 4 What will be the pixel density (PPI) for
Transcribed image text: Question 4 What will be the pixel density (PPI) for the screen whose resolution is 300 x 400 and screen...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found