pixel

How to convert DP, PX, SP among each other, especially DP and SP?

て烟熏妆下的殇ゞ 提交于 2019-11-26 15:19:25
I have known the difference among DP , SP and PX . And after searching this topic, I found nothing satisfying me completely. Maybe this post is a duplicate, but I still want to know what is the formula of converting from DP to PX , and DP to SP , from SP to PX , from PX to SP , from SP to DP , from DP to SP ? I have known some codes to do this, but they are imperfect. DP to PX: public static int dpToPx(float dp, Context context) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); } SP to PX: public static int spToPx(float sp,

Axis coordinates to pixel coordinates? (Matlab)

一个人想着一个人 提交于 2019-11-26 14:39:37
问题 How can i convert the axis coordinates into pixel coordinates? I have a set of data which include the negative and floating values, i need to put all of the data into the image. But the pixel coordinates are all positive integer. how to solve the negative issue? 回答1: You can pass vectors of coordinates to scatter . x = [-1.2 -2.4 0.3 7]; y = [2 -1 1 -3]; scatter(x,y,'.'); If you need the image matrix, h = figure(); scatter(x,y); F = getframe(h); img = F.cdata; You can also use print to save

Make a 2D pixel plot with matplotlib

一曲冷凌霜 提交于 2019-11-26 13:03:31
问题 I got the following data from some calculations: x, y, temp where x and y are the coordinates of a point in a 2D box of dimensions 10x10. Spacing is equal to 0.1. So there are 10000 different points and the resulting file looks like: 0.0 0.0 5.6 0.1 0.0 3.2 0.2 0.0 4.1 ... 9.9 9.9 2.1 I would like to prepare kind of a 2D plot with matplotlib, with 100x100 pixels, where each pixel gets a colour (rainbow colors going from red to violet, from the minimum to the maximum values of the third column

Convert Pixels to Points

↘锁芯ラ 提交于 2019-11-26 12:05:36
I have a need to convert Pixels to Points in C#. I've seen some complicated explanations about the topic, but can't seem to locate a simple formula. Let's assume a standard 96dpi, how do I calulate this conversion? There are 72 points per inch ; if it is sufficient to assume 96 pixels per inch, the formula is rather simple: points = pixels * 72 / 96 There is a way to get the configured pixels per inch of your display in Windows using GetDeviceCaps . Microsoft has a guide called "Developing DPI-Aware Applications" , look for the section "Creating DPI-Aware Fonts". The W3C has defined the pixel

Android 图片加载图片_OOM异常解决

狂风中的少年 提交于 2019-11-26 11:42:01
http://stormzhang.github.io/android/2013/11/20/android-display-bitmaps-efficiently/ Android加载资源图片时,很容易出现OOM的错误。 因为Android系统对内存有一个限制,如果超出该限制,就会出现OOM。为了避免这个问题,需要在加载资源时尽量考虑如何节约内存,尽快释放资源等等。 Android系统版本对图片加载,回收的影响: 1,在Android 2.3以及之后,采用的是并发回收机制,避免在回收内存时的卡顿现象。 2,在Android 2.3.3(API Level 10)以及之前,Bitmap的backing pixel 数据存储在native memory, 与Bitmap本身是分开的,Bitmap本身存储在dalvik heap 中。导致其pixel数据不能判断是否还需要使用,不能及时释放,容易引起OOM错误。 从Android 3.0(API 11)开始,pixel数据与Bitmap一起存储在Dalvik heap中。 在加载图片资源时,可采用以下一些方法来避免OOM的问题: 1,在Android 2.3.3以及之前,建议使用Bitmap.recycle()方法,及时释放资源。 2,在Android 3.0开始,可设置BitmapFactory.options.inBitmap值,

Android background image size in pixel

折月煮酒 提交于 2019-11-26 11:14:30
I would like to create a background image for different resolutions in Android. So I need the values (in pixel) for ldpi, mdpi, hdpi,xhdpi and xxhdpi. It is important that the image will not be blurred. I have already read the Documentation about multiple screen support but there are sizes in dp instead of pixel. there is no full list of screen resolutions, there are no fixed values in pixels for ldpi, mdpi, hdpi,xhdpi and xxhdpi. Every android device may have different resolution. If you want to fill all resolutions you will have to create too many images. If you put them in your app, it will

Get Pixel color of UIImage

为君一笑 提交于 2019-11-26 10:15:54
How can I get the RGB value of a particular pixel in a UIImage? Jesse Naugher You can't access the raw data directly, but by getting the CGImage of this image you can access it. here is a link to another question that answers your question and others you might have regarding detailed image manipulation : CGImage Minas Petterson Try this very simple code: I used to detect a wall in my maze game (the only info that I need is the alpha channel, but I included the code to get the other colors for you): - (BOOL)isWallPixel:(UIImage *)image xCoordinate:(int)x yCoordinate:(int)y { CFDataRef pixelData

Edit raw pixel data of WriteableBitmap?

房东的猫 提交于 2019-11-26 09:52:50
问题 Is it possible to directly read/write to a WriteableBitmap\'s pixel data? I\'m currently using WriteableBitmapEx\'s SetPixel() but it\'s slow and I want to access the pixels directly without any overhead. I haven\'t used HTML5\'s canvas in a while, but if I recall correctly you could get its image data as a single array of numbers and that\'s kind of what I\'m looking for Thanks in advance 回答1: To answer your question, you can more directly access a writable bitmap's data by using the Lock ,

extracting a quadrilateral image to a rectangle

久未见 提交于 2019-11-26 09:29:11
问题 BOUNTY UPDATE Following Denis\'s link, this is how to use the threeblindmiceandamonkey code: // the destination rect is our \'in\' quad int dw = 300, dh = 250; double in[4][4] = {{0,0},{dw,0},{dw,dh},{0,dh}}; // the quad in the source image is our \'out\' double out[4][5] = {{171,72},{331,93},{333,188},{177,210}}; double homo[3][6]; const int ret = mapQuadToQuad(in,out,homo); // homo can be used for calculating the x,y of any destination point // in the source, e.g. for(int i=0; i<4; i++) {

What&#39;s the best way to set a single pixel in an HTML5 canvas?

↘锁芯ラ 提交于 2019-11-26 08:54:33
问题 The HTML5 Canvas has no method for explicitly setting a single pixel. It might be possible to set a pixel using a very short line, but then antialising and line caps might interfere. Another way might be to create a small ImageData object and using: context.putImageData(data, x, y) to put it in place. Can anyone describe an efficient and reliable way of doing this? 回答1: There are two best contenders: Create a 1×1 image data, set the color, and putImageData at the location: var id = myContext