Posts

Showing posts with the label Image

Checking For Multiple Images Loaded

Answer : If you want to call a function when all the images are loaded, You can try following, it worked for me var imageCount = images.length; var imagesLoaded = 0; for(var i=0; i<imageCount; i++){ images[i].onload = function(){ imagesLoaded++; if(imagesLoaded == imageCount){ allLoaded(); } } } function allLoaded(){ drawImages(); } Can't you simply use a loop and assign the same function to all onloads? var myImages = ["green.png", "blue.png"]; (function() { var imageCount = myImages.length; var loadedCount = 0, errorCount = 0; var checkAllLoaded = function() { if (loadedCount + errorCount == imageCount ) { // do what you need to do. } }; var onload = function() { loadedCount++; checkAllLoaded(); }, onerror = function() { errorCount++; checkAllLoaded(); }; for (var i = 0; i < imageCount; i++) { var img = new Image(); img.onload = onload;...

Android: Combining Text & Image On A Button Or ImageButton

Answer : For users who just want to put Background, Icon-Image and Text in one Button from different files: Set on a Button background, drawableTop/Bottom/Rigth/Left and padding attributes. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/home_btn_test" android:drawableTop="@drawable/home_icon_test" android:textColor="#FFFFFF" android:id="@+id/ButtonTest" android:paddingTop="32sp" android:drawablePadding="-15sp" android:text="this is text"></Button> For more sophisticated arrangement you also can use RelativeLayout (or any other layout) and make it clickable. Tutorial: Great tutorial that covers both cases: http://izvornikod.com/Blog/tabid/82/EntryId/8/Creating-Android-button-with-image-and-text-using-relative-layout.aspx There's a mu...

Android: Picasso Load Image Failed . How To Show Error Message

Answer : Use builder: Picasso.Builder builder = new Picasso.Builder(this); builder.listener(new Picasso.Listener() { @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { exception.printStackTrace(); } }); builder.build().load(URL).into(imageView); Edit For version 2.71828 they have added the exception to the onError callback: Picasso.get() .load("yoururlhere") .into(imageView, new Callback() { @Override public void onSuccess() { } @Override public void onError(Exception e) { } }) When you use callback, the picaso will call method onSuccess and onError! File fileImage = new File(mPathImage); Picasso.with(mContext).load(fileImage) .placeholder(R.drawable.draw_detailed_view_display) .error...

Change Color Of PNG Image Via CSS?

Answer : You can use filters with -webkit-filter and filter : Filters are relatively new to browsers but supported in over 90% of browsers according to the following CanIUse table: https://caniuse.com/#feat=css-filters You can change an image to grayscale, sepia and lot more (look at the example). So you can now change the color of a PNG file with filters. body { background-color:#03030a; min-width: 800px; min-height: 400px } img { width:20%; float:left; margin:0; } /*Filter styles*/ .saturate { filter: saturate(3); } .grayscale { filter: grayscale(100%); } .contrast { filter: contrast(160%); } .brightness { filter: brightness(0.25); } .blur { filter: blur(3px); } .invert { filter: invert(100%); } .sepia { filter: sepia(100%); } .huerotate { filter: hue-rotate(180deg); } .rss.opacity { filter: opacity(50%); } <!--- img src http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/500px-M...

Alternative Segmentation Techniques Other Than Watershed For Soil Particles In Images

Image
Answer : You could try using Connected Components with Stats already implemented as cv2.connectedComponentsWithStats to perform component labeling. Using your binary image as input, here's the false-color image: The centroid of each object can be found in centroid parameter and other information such as area can be found in the status variable returned from cv2.connectedComponentsWithStats . Here's the image labeled with the area of each polygon. You could filter using a minimum threshold area to only keep larger polygons Code import cv2 import numpy as np # Load image, Gaussian blur, grayscale, Otsu's threshold image = cv2.imread('2.jpg') blur = cv2.GaussianBlur(image, (3,3), 0) gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] # Perform connected component labeling n_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(thresh, connectivity=4) # Create fal...

Android Emulator Camera Custom Image

Image
Answer : Under Tools > AVD Manager , select the "pencil" to get to "Virtual Device Configuration". Show Advanced Settings > Camera will give you the option of using emulated, or a device: Device - use host computer webcam or built-in camera If all you need is to get a still image into the camera, starting with Android Studio 3.2 you can put your static images into the virtual scene: as discussed in this entry from Android developers blog. Note that you'll need to move the camera position into the dining room to see your images (turn around and use Alt-w to move forward). Finally! Append to file ~/Android/Sdk/emulator/resources/Toren1BD.posters poster custom size 2 2 position 0 0 -1.8 rotation 0 0 0 default custom.png Place 'custom.png' in ~/Android/Sdk/emulator/resources/ Restart! emulator @Phone -no-snapshot -no-boot-anim (replace 'Phone' with the name of your avd! (see: emulator -list-avds) Profit! Now you have a...

100x100 Image With Random Pixel Colour

Image
Answer : This is simple with numpy and pylab . You can set the colormap to be whatever you like, here I use spectral. from pylab import imshow, show, get_cmap from numpy import random Z = random.random((50,50)) # Test data imshow(Z, cmap=get_cmap("Spectral"), interpolation='nearest') show() Your target image looks to have a grayscale colormap with a higher pixel density than 100x100: import pylab as plt import numpy as np Z = np.random.random((500,500)) # Test data plt.imshow(Z, cmap='gray', interpolation='nearest') plt.show() If you want to create an image file (and display it elsewhere, with or without Matplotlib), you could use NumPy and Pillow as follows: import numpy, from PIL import Image imarray = numpy.random.rand(100,100,3) * 255 im = Image.fromarray(imarray.astype('uint8')).convert('RGBA') im.save('result_image.png') The idea here is to create a numeric array, convert it to a RGB image, and sa...

Changing Image Size In Markdown

Answer : You could just use some HTML in your Markdown: <img src="drawing.jpg" alt="drawing" width="200"/> Or via style attribute ( not supported by GitHub ) <img src="drawing.jpg" alt="drawing" style="width:200px;"/> Or you could use a custom CSS file as described in this answer on Markdown and image alignment ![drawing](drawing.jpg) CSS in another file: img[alt=drawing] { width: 200px; } With certain Markdown implementations (including Mou and Marked 2 (only macOS)) you can append =WIDTHxHEIGHT after the URL of the graphic file to resize the image. Do not forget the space before the = . ![](./pic/pic1_50.png =100x20) You can skip the HEIGHT ![](./pic/pic1s.png =250x) The accepted answer here isn't working with any Markdown editor available in the apps I have used till date like Ghost, Stackedit.io or even in the StackOverflow editor. I found a workaround here in the StackEdit.io iss...

Capture Image From Camera And Display In Activity

Answer : Here's an example activity that will launch the camera app and then retrieve the image and display it. package edu.gvsu.cis.masl.camerademo; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; public class MyCameraActivity extends Activity { private static final int CAMERA_REQUEST = 1888; private ImageView imageView; private static final int MY_CAMERA_PERMISSION_CODE = 100; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.imageView = (ImageView)this.findViewById(R.id.imageView1); Button photoButton = (Button) this.findViewById(R.id.button1); photoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v...