导航:首页 > 源码编译 > gif信息c源码

gif信息c源码

发布时间:2023-04-13 06:14:35

1. 怎么用C语言读取gif图片内容文件

分类: 电脑/网络 >> 程序设计 >> 其他编程语言
问题描述:

怎么用C语言读取贺拆备gif图片内容文件 假如文件中有6个gif图片,只读取第一个图片;读完后写入一个空文件中

解析:

用二进制文件方法打开。

(1)读gif_id,输出gif_id, 6 bytes

(2)读logical_screen_descriptor(结构),并输出

(3)如果 ScrHd.flag_GC_table == 1,

则有全局色表,则读全局色表,并输出

(4)循环,

检查gif块的类御卖型,按块的类型读块,并输出

若:

case: 0x2c -- 它是,Image Descriptor(结构),读块并输出

判断有无色表,有则读块并输出,

下面 1 byte 表示 lZW min Code Size,读并输出

子块 (include size, bytes*size data) 读块并输出

子块 (include size, bytes*size data) 读块并输出

可能有很多子块,读块并输出

直到 0x00 读块并输出,

break;

若case: 0x21 0xf9 -- 控制块,读到 0x00, 并输出

break;

若case: 0x21 0xFe -- 注解块,读到 0x00,并输出

break;

若case: 0x21 0x01 -- 普通禅毁文本块,读到 0x00,并输出

break;

若case: 0x21 0xff -- 应用程序块,读到 0x00,并输出

break;

若case: 0x3B -- END 第一个图片完毕的标识,并输出

break;

default: 打印“文件错误”break;

(5)关闭文件。

2. 请教:怎么样能把C语言代码运行后的流星雨效果图保存下来,保存为GIF。

搞定。 我用悔肆的拍前坦C++Builder XE2编译器。 增中代码: #include <vcl.h> #include <GIFimg.hpp> TGIFImage *image; 在wmain函数后部分: image = new TGIFImage(); srand((int) GetCurrentTime()); // 初始化随机数发生器 image->Width = Screen->Width; image->Height = Screen->Height; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } ShowCursor(TRUE); // 显示鼠标光标 image->SaveToFile("流星雨袭桐.gif"); delete image; 在WndProc函数处理WM_TIMER消息后面增加: BitBlt(hdc, 0, 0, cxScreen, cyScreen, hdcMem, 0, 0, SRCCOPY); { Graphics::TBitmap *bmp = new Graphics::TBitmap; bmp->Width=Screen->Width; bmp->Height=Screen->Height; BitBlt(HDC(bmp->Canvas->Handle), 0, 0, cxScreen, cyScreen, hdcMem, 0, 0, SRCCOPY); image->Add(bmp); delete bmp; } ReleaseDC(hwnd, hdc); 编译后成功。 保存的GIF文件很大,最好用Ulead GIF Animator优化一下。 需要编译后的文件QQ我:1848447992

记得采纳啊

3. 求GIF格式图片解析显示的C语言源码

// File name : l2_gl_gif.h
#ifndef _GIF_H
#define _GIF_H

#define COMPRESSED_BUFFER_SIZE (25*1024) // maximal size of single compressed image data
#define GIF_DEFAULT_BKCOLOR (0xffff)
#define CODE_UPPER_BOUND 4096 // decided by algorithem itselt, maximal size of string table

typedef unsigned short COLORREF;

typedef struct tagCodeTableItem
{
unsigned short ushPrevIndex; // Previous code index
unsigned char uchCharacter; // character added this time
unsigned char uchFirstChar; // first character of the string this code corresponding to
unsigned char* pUchStringAddr; //
unsigned short ushStringLength;
} CODE_TABLE;

typedef struct tagImageInfoParameter
{
unsigned short ushImageLeftPosition;
unsigned short ushImageTopPosition;
unsigned short ushImageWidth;
unsigned short ushImageHeight;
unsigned short ushDelay;
bool blLocalColorTableFlag;// whether this image use private color table
unsigned short ushSizeofLocalColorTable;
bool blTransparentColorFlag;// whether this image use transparent index data
unsigned char uchTransparentColorIndex;
bool blInterlaceFlag; // whether this image is interlaced
bool blSortFlag; // not so important for our LCD device
unsigned short ushReserved;
} IMAGE_INFO_PARAMETER; //used as function parameter which could provided more information than usually used para

#define MAX_IMAGE_COUNT 20 // can process as many as MAX_IMAGE_COUNT sub-image of a gif file
//if it contains more than MAX_IMAGE_COUNT subimages

typedef struct tagImageRawInfo // used to keep raw subimage information
{
bool blGraphicControlExtension;
unsigned char uchGCE[8];
bool blImageDescriptor;
unsigned char uchImgDesp[12];
const unsigned char*pUchCodedImageData;
const unsigned char*pUchLocalColorTable;
} IMAGE_RAW_INFO;

typedef struct gif_context
{
IMAGE_RAW_INFO g_ImageRawInfo[MAX_IMAGE_COUNT];
CODE_TABLE g_CodeTable[CODE_UPPER_BOUND];
unsigned char g_uchLZWCodeSize; // 初始的压缩code size
unsigned char g_uchOffset; // 取code时基于位的偏移
const unsigned char*g_pUchCompressedData; // 指向压缩数据的首指针
unsigned char* g_pImageIndexData; // 指向解压缩后数据的首指针
unsigned char* g_pUchImageIndexPos;
unsigned short gifThisWidth;
unsigned short gifThisHeight;
unsigned short g_ushImageCount;
COLORREF g_bkColor;
////////////////2004/06/22
unsigned char DisposalMethod;
gdc_t *FirstFrameSd;// 当Disposal Method 为1,
//且存在尺度变换,需要保留第一帧数据备用
unsigned long length; // add for techfaith porting,08/01/2007
} GIF_CONTEXT, LPGIF_CONTEXT;

bool _GetGifFileInfor(GIF_CONTEXT* pGif_Context,const unsigned char* pGifFileStream);
bool pt_gif_draw_one_frame(gdc_t* sd, short x, short y,
const unsigned char* pGifData,int iFrameNum);

/************************************************************
*
* gif playing using task, currently support up to
* MAX_CONCURRENCE_NUMBER gif playing concurrently
*
*************************************************************/

//#define MAX_CONCURRENCE_NUMBER 8
//#define PV_GIF_PLAYING_INTERVER 1000
//#define GIFPLAY_FREE 0
//#define GIFPLAY_BUSY 1

typedef struct
{
GIF_CONTEXT gif_Context;
COLORREF Palette[384];
//unsigned long taskEntry;
//void* Form;
unsigned short playIndex;
unsigned short frameNumber;
unsigned short playTimes;
//unsigned char timerNo;
const unsigned char*pGifFileStream;
unsigned char* pDecodedBuf;
unsigned short width, height;
short x, y;
bool UseShrink;
unsigned short DispWidth, DispHeight;
gdc_t *gdc;
} gif_handle_t,*GIFPLAY_HANDLE;

#endif // _GIF_H

4. 用vc如何播放gif

使用MMAPI播放辩档宏gif动画MMAPI是在JSR 135中提出的,增强了java ME平台对多媒体编程的支持。例如播放音频和视频文件,捕获声音和图像等。目前大多数支持JTWI 1.0的手机都支持了MMAPI。本文介绍如何使用MMAPI播放gif格式的动画。

其实制作动画效果可以有很多办法,例如准备一个图片数组,在程序中不断的切换显示不同的图片,只要时间的间隔设置合理即可出现动画的效果。携册如果使用MMAPI则可以直接播放gif的动画。其实这蠢丛和播放视频文件的方法和流程是类似的。

首先我们应该准备一个gif文件,放在能够访问到的位置,且确保这个文件会被打包进jar内。在创建播放器之前应该先确认手机上的MMAPI实现是否支持image/gif格式的播放,如果支持则创建Player,如下。

private void createPlayer(InputStream is){
String[] contents = Manager.getSupportedContentTypes(null);
for(int i = 0;i<contents.length;i++){
if(contents[i].toLowerCase().indexOf("image/gif") != -1){
try {
player = Manager.createPlayer(is,"image/gif");
player.realize();
} catch (IOException ex) {
ex.printStackTrace();
} catch (MediaException ex) {
ex.printStackTrace();
}

}

}
}

Player创建后,我们需要获得VideoControl,然后将内容渲染到屏幕上,VideoControl提供了两种模式,这里我们使用USE_GUI_PRIMITIVE方式,将返回的Item追加到一个Form中显示。最后调用Player.start()即可播放。注意在退出之前一定要释放Player资源,关闭Player并设置为null。GifPlayer的源码如下:

源程序如下

/*
* GifPlayer.java
*
* Created on 2006年6月21日, 下午7:28
*/

package com.j2medev.gif;

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lci.Display;
import javax.microedition.lci.Form;
import javax.microedition.lci.Item;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.*;

/**
*
* @author ming
* @version
*/
public class GifPlayer extends MIDlet {

private Display display = null;
private Player player = null;

public void startApp() {
if(display == null)
display = Display.getDisplay(this);
Form form = new Form("gif player");
InputStream is = getClass().getResourceAsStream("/a.gif");
createPlayer(is);
if(player == null){
form.append("can not play image/gif");
}else{
VideoControl vc = (VideoControl)player.getControl("VideoControl");
if(vc != null){
form.append((Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,null));
}
}
display.setCurrent(form);
try {
player.start();
} catch (MediaException ex) {
ex.printStackTrace();
}
}

private void createPlayer(InputStream is){
String[] contents = Manager.getSupportedContentTypes(null);
for(int i = 0;i<contents.length;i++){
if(contents[i].toLowerCase().indexOf("image/gif") != -1){
try {
player = Manager.createPlayer(is,"image/gif");
player.realize();
} catch (IOException ex) {
ex.printStackTrace();
} catch (MediaException ex) {
ex.printStackTrace();
}

}

}
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
if(player != null){
player.close();
player = null;

5. 如何用c#读取gif和jpg的图象象素信息

给你一段袭橡我编的代码,功卖简能是变图片的分辨率,一看拍配旁就明白了
Color c = new Color();
Bitmap box1 = new Bitmap(pictureBox1.Image);
Bitmap box2 = new Bitmap(pictureBox2.Image);
int r, g, b, i, j, size, k1, k2, xres, yres;
xres = pictureBox1.Image.Width;
yres = pictureBox1.Image.Height;
size = 2;
for (i = 0; i < (xres - 1);i+=size)
{
for (j = 0; j <( yres - 1); j += size)
{
c = box1.GetPixel(i,j);//取像素点
r = c.R;
g = c.G;
b = c.B;

Color cc = Color.FromArgb(r,g,b);
for (k1 = 0; k1 <= (size - 1);k1++)
{
for (k2 = 0; k2 <= (size - 1); k2++)
{
box2.SetPixel(i+k1,j+k2,cc);//写入像素
}
}

}
}

6. 有人知道如何用C/C++/C#将.GIF格式的图片读取并且显示出来

c#picture可以直接显示gif

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace WindowsApplication1
{
/// <summary>
/// Form8 的摘要说明。
/// </summary>
public class animateImage : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
Bitmap animatedImage = new Bitmap("1.gif");
bool currentlyAnimating = false;
public animateImage()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在中差斗 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑卖磨器庆差修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// Form8
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(536, 438);
this.Name = "Form8";
this.Text = "Form8";
this.Load += new System.EventHandler(this.Form8_Load);

}
#endregion
// [STAThread]
// static void Main()
// {
// Application.Run(new Form2());
// }

private void Form8_Load(object sender, System.EventArgs e)
{

//This method begins the animation.

}
public void AnimateImage()
{
if (!currentlyAnimating)
{
//Begin the animation only once.
ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
currentlyAnimating = true;

}
}
private void OnFrameChanged(object o, EventArgs e)
{
//Force a call to the Paint event handler.
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
this.SetStyle(ControlStyles.DoubleBuffer,true);
//Begin the animation.
AnimateImage();
//Get the next frame ready for rendering.
ImageAnimator.UpdateFrames();
//Draw the next frame in the animation.
e.Graphics.DrawImage(this.animatedImage, new Point(0, 0));
e.Graphics.DrawString("哈哈",new Font("Tahoma",12),new SolidBrush(Color.Red),10,10);
}
// public static void Main()
// {
// Application.Run(new animateImage());
// }

}
}

7. 怎么将gif格式的图片转换为c语言程序

图片是不能转换成C程序的,只有通过调用,才能实现图片的模橘输出。例如,我们常见的网游,就是通过一系列的调用其旦举团本身已有的图片或动画来实现的,所以做网游的公司里,学美术的人是必不可少的。
具体方法答燃看书吧,书上都有详细的解答的。

8. 急求,linux下用c语言实现显示gif图像(静态即可),虚拟机Ubuntu环境,求代码。。。。

eog, 右启枣锋悄晌岩宏侧有c源码下载.
http://projects.gnome.org/eog/

阅读全文

与gif信息c源码相关的资料

热点内容
程序员考试教程 浏览:219
文件名修改为文件夹的名字批处理 浏览:251
拍照程序员 浏览:827
wps怎么把pdf转jpg 浏览:217
自拍用什么app做的艺术照 浏览:169
h3c无线配置命令 浏览:515
linux代码阅读工具 浏览:160
能够画出对称图形的是什么app 浏览:424
单片机投票器 浏览:467
程序员那么可爱唱吗 浏览:830
手机误删的app怎么恢复 浏览:700
java第三方加密库 浏览:660
编译代码软件哪个好 浏览:997
编译器软件图片 浏览:880
美团专送app怎么不接受远单 浏览:833
服务器mgmt口如何连接电脑 浏览:798
做程序员至少要精通几种 浏览:673
个人用云服务器价格对比 浏览:257
如何远程删除服务器文件夹 浏览:779
a9账号如何移植到安卓 浏览:340