Saving a Java 2d graphics image as .png file

JPanel dPanel; … public void save() { BufferedImage bImg = new BufferedImage(dPanel.getWidth(), dPanel.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D cg = bImg.createGraphics(); dPanel.paintAll(cg); try { if (ImageIO.write(bImg, “png”, new File(“./output_image.png”))) { System.out.println(“– saved”); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

Rotate zoom drag image in android imageview

Firstly, You have to take ImageView in your .xml file. <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” > <ImageView android:id=”@+id/imageView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:src=”https://stackoverflow.com/questions/5894736/@drawable/ic_launcher” /> </LinearLayout> Then, Do intialize your Imageview in Java and set onTouchListener to your ImageView. ImageView imageView=(ImageView) findViewById(R.id.imageView1); imageView.setOnTouchListener(this); Implement onTouchListener to your Activity and add unimplemented method to Activity. Now, Finally write this … Read more

How to play or open *.mp3 or *.wav sound file in c++ program? [closed]

First of all, write the following code: #include <Mmsystem.h> #include <mciapi.h> //these two headers are already included in the <Windows.h> header #pragma comment(lib, “Winmm.lib”) To open *.mp3: mciSendString(“open \”*.mp3\” type mpegvideo alias mp3″, NULL, 0, NULL); To play *.mp3: mciSendString(“play mp3”, NULL, 0, NULL); To play and wait until the *.mp3 has finished playing: mciSendString(“play … Read more

IPhone Text Glow Effect

As of 3.2 you there is direct support for shadows in the SDK. label.layer.shadowColor = [label.textColor CGColor]; label.layer.shadowOffset = CGSizeMake(0.0, 0.0); Play with the parameters: label.layer.shadowRadius = 3.0; label.layer.shadowOpacity = 0.5; And to avoid shadow being clipped by the label bouds: label.layer.masksToBounds = NO; Don’t forget to #include <Quartzcore/Quartzcore.h> and link against the QuartzCore or … Read more

Forcing Machine to Use Dedicated Graphics Card?

The easiest way from C++ to ensure that the dedicated graphics card is used instead of chipset switchable graphics under Windows is to export the following symbols (MSVC sample code): Enable dedicated graphics for NVIDIA: extern “C” { __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; } Enable dedicated graphics for AMD Radeon: extern “C” { __declspec(dllexport) … Read more

How to capture the screen and mouse pointer using Windows APIs?

[StructLayout(LayoutKind.Sequential)] struct CURSORINFO { public Int32 cbSize; public Int32 flags; public IntPtr hCursor; public POINTAPI ptScreenPos; } [StructLayout(LayoutKind.Sequential)] struct POINTAPI { public int x; public int y; } [DllImport(“user32.dll”)] static extern bool GetCursorInfo(out CURSORINFO pci); [DllImport(“user32.dll”)] static extern bool DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon); const Int32 CURSOR_SHOWING = 0x00000001; public static Bitmap … Read more

How to draw a rounded rectangle in c#

public static GraphicsPath RoundedRect(Rectangle bounds, int radius) { int diameter = radius * 2; Size size = new Size(diameter, diameter); Rectangle arc = new Rectangle(bounds.Location, size); GraphicsPath path = new GraphicsPath(); if (radius == 0) { path.AddRectangle(bounds); return path; } // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = bounds.Right – … Read more